xref: /aosp_15_r20/external/cronet/base/debug/debugger_fuchsia.cc (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
1 // Copyright 2021 The Chromium Authors
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 
13 #include "base/debug/alias.h"
14 
15 namespace base {
16 namespace debug {
17 
BeingDebugged()18 bool BeingDebugged() {
19   zx_info_process_t info = {};
20   // Ignore failures. The 0-initialization above will result in "false" for
21   // error cases.
22   zx::process::self()->get_info(ZX_INFO_PROCESS, &info, sizeof(info),
23                                 nullptr, nullptr);
24   return (info.flags & ZX_INFO_PROCESS_FLAG_DEBUGGER_ATTACHED) != 0;
25 }
26 
BreakDebuggerAsyncSafe()27 void BreakDebuggerAsyncSafe() {
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 
VerifyDebugger()40 void VerifyDebugger() {}
41 
42 }  // namespace debug
43 }  // namespace base
44