Avi Drissman | e4622aa | 2022-09-08 20:36:06 | [diff] [blame] | 1 | // Copyright 2021 The Chromium Authors |
Hwanseung Lee | 56e45ca | 2021-04-16 14:16:20 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "base/debug/debugger.h" |
| 6 | |
| 7 | #include <lib/zx/process.h> |
| 8 | #include <stdlib.h> |
| 9 | #include <unistd.h> |
| 10 | #include <zircon/process.h> |
| 11 | #include <zircon/syscalls.h> |
| 12 | |
Hwanseung Lee | 56e45ca | 2021-04-16 14:16:20 | [diff] [blame] | 13 | #include "base/debug/alias.h" |
| 14 | |
Hwanseung Lee | 56e45ca | 2021-04-16 14:16:20 | [diff] [blame] | 15 | namespace base { |
| 16 | namespace debug { |
| 17 | |
| 18 | bool BeingDebugged() { |
Joshua Seaton | c0e57ccc7 | 2021-05-26 18:29:49 | [diff] [blame] | 19 | zx_info_process_t info = {}; |
Hwanseung Lee | 56e45ca | 2021-04-16 14:16:20 | [diff] [blame] | 20 | // Ignore failures. The 0-initialization above will result in "false" for |
| 21 | // error cases. |
Peter Kasting | 134ef9af | 2024-12-28 02:30:09 | [diff] [blame] | 22 | zx::process::self()->get_info(ZX_INFO_PROCESS, &info, sizeof(info), nullptr, |
| 23 | nullptr); |
Hwanseung Lee | 56e45ca | 2021-04-16 14:16:20 | [diff] [blame] | 24 | return (info.flags & ZX_INFO_PROCESS_FLAG_DEBUGGER_ATTACHED) != 0; |
| 25 | } |
| 26 | |
Benoit Lize | 33a1652 | 2021-09-13 20:15:14 | [diff] [blame] | 27 | void BreakDebuggerAsyncSafe() { |
Hwanseung Lee | 56e45ca | 2021-04-16 14:16:20 | [diff] [blame] | 28 | // NOTE: This code MUST be async-signal safe (it's used by in-process |
| 29 | // stack dumping signal handler). NO malloc or stdio is allowed here. |
| 30 | |
| 31 | // Linker's ICF feature may merge this function with other functions with the |
| 32 | // same definition (e.g. any function whose sole job is to call abort()) and |
| 33 | // it may confuse the crash report processing system. http://crbug.com/508489 |
| 34 | static int static_variable_to_make_this_function_unique = 0; |
| 35 | Alias(&static_variable_to_make_this_function_unique); |
| 36 | |
| 37 | abort(); |
| 38 | } |
| 39 | |
Hwanseung Lee | 56e45ca | 2021-04-16 14:16:20 | [diff] [blame] | 40 | void VerifyDebugger() {} |
| 41 | |
| 42 | } // namespace debug |
| 43 | } // namespace base |