xref: /aosp_15_r20/external/libchrome/base/debug/debugger.cc (revision 635a864187cb8b6c713ff48b7e790a6b21769273)
1*635a8641SAndroid Build Coastguard Worker // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2*635a8641SAndroid Build Coastguard Worker // Use of this source code is governed by a BSD-style license that can be
3*635a8641SAndroid Build Coastguard Worker // found in the LICENSE file.
4*635a8641SAndroid Build Coastguard Worker 
5*635a8641SAndroid Build Coastguard Worker #include "base/debug/debugger.h"
6*635a8641SAndroid Build Coastguard Worker #include "base/logging.h"
7*635a8641SAndroid Build Coastguard Worker #include "base/threading/platform_thread.h"
8*635a8641SAndroid Build Coastguard Worker #include "build/build_config.h"
9*635a8641SAndroid Build Coastguard Worker 
10*635a8641SAndroid Build Coastguard Worker namespace base {
11*635a8641SAndroid Build Coastguard Worker namespace debug {
12*635a8641SAndroid Build Coastguard Worker 
13*635a8641SAndroid Build Coastguard Worker static bool is_debug_ui_suppressed = false;
14*635a8641SAndroid Build Coastguard Worker 
WaitForDebugger(int wait_seconds,bool silent)15*635a8641SAndroid Build Coastguard Worker bool WaitForDebugger(int wait_seconds, bool silent) {
16*635a8641SAndroid Build Coastguard Worker #if defined(OS_ANDROID)
17*635a8641SAndroid Build Coastguard Worker   // The pid from which we know which process to attach to are not output by
18*635a8641SAndroid Build Coastguard Worker   // android ddms, so we have to print it out explicitly.
19*635a8641SAndroid Build Coastguard Worker   DLOG(INFO) << "DebugUtil::WaitForDebugger(pid=" << static_cast<int>(getpid())
20*635a8641SAndroid Build Coastguard Worker              << ")";
21*635a8641SAndroid Build Coastguard Worker #endif
22*635a8641SAndroid Build Coastguard Worker   for (int i = 0; i < wait_seconds * 10; ++i) {
23*635a8641SAndroid Build Coastguard Worker     if (BeingDebugged()) {
24*635a8641SAndroid Build Coastguard Worker       if (!silent)
25*635a8641SAndroid Build Coastguard Worker         BreakDebugger();
26*635a8641SAndroid Build Coastguard Worker       return true;
27*635a8641SAndroid Build Coastguard Worker     }
28*635a8641SAndroid Build Coastguard Worker     PlatformThread::Sleep(TimeDelta::FromMilliseconds(100));
29*635a8641SAndroid Build Coastguard Worker   }
30*635a8641SAndroid Build Coastguard Worker   return false;
31*635a8641SAndroid Build Coastguard Worker }
32*635a8641SAndroid Build Coastguard Worker 
SetSuppressDebugUI(bool suppress)33*635a8641SAndroid Build Coastguard Worker void SetSuppressDebugUI(bool suppress) {
34*635a8641SAndroid Build Coastguard Worker   is_debug_ui_suppressed = suppress;
35*635a8641SAndroid Build Coastguard Worker }
36*635a8641SAndroid Build Coastguard Worker 
IsDebugUISuppressed()37*635a8641SAndroid Build Coastguard Worker bool IsDebugUISuppressed() {
38*635a8641SAndroid Build Coastguard Worker   return is_debug_ui_suppressed;
39*635a8641SAndroid Build Coastguard Worker }
40*635a8641SAndroid Build Coastguard Worker 
41*635a8641SAndroid Build Coastguard Worker }  // namespace debug
42*635a8641SAndroid Build Coastguard Worker }  // namespace base
43