xref: /aosp_15_r20/external/cronet/base/debug/debugger.cc (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
1 // Copyright 2011 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 "base/clang_profiling_buildflags.h"
8 #include "base/logging.h"
9 #include "base/threading/platform_thread.h"
10 #include "build/build_config.h"
11 
12 #if BUILDFLAG(CLANG_PROFILING)
13 #include "base/test/clang_profiling.h"
14 #endif
15 
16 namespace base {
17 namespace debug {
18 
19 static bool is_debug_ui_suppressed = false;
20 
WaitForDebugger(int wait_seconds,bool silent)21 bool WaitForDebugger(int wait_seconds, bool silent) {
22 #if BUILDFLAG(IS_ANDROID)
23   // The pid from which we know which process to attach to are not output by
24   // android ddms, so we have to print it out explicitly.
25   DLOG(INFO) << "DebugUtil::WaitForDebugger(pid=" << static_cast<int>(getpid())
26              << ")";
27 #endif
28   for (int i = 0; i < wait_seconds * 10; ++i) {
29     if (BeingDebugged()) {
30       if (!silent)
31         BreakDebugger();
32       return true;
33     }
34     PlatformThread::Sleep(Milliseconds(100));
35   }
36   return false;
37 }
38 
BreakDebugger()39 void BreakDebugger() {
40 #if BUILDFLAG(CLANG_PROFILING)
41   WriteClangProfilingProfile();
42 #endif
43 
44   BreakDebuggerAsyncSafe();
45 }
46 
SetSuppressDebugUI(bool suppress)47 void SetSuppressDebugUI(bool suppress) {
48   is_debug_ui_suppressed = suppress;
49 }
50 
IsDebugUISuppressed()51 bool IsDebugUISuppressed() {
52   return is_debug_ui_suppressed;
53 }
54 
55 }  // namespace debug
56 }  // namespace base
57