blob: 4d2232ec2fa49345d54a5b59d37fafbe1dae0bb5 [file] [log] [blame]
Avi Drissmane4622aa2022-09-08 20:36:061// Copyright 2011 The Chromium Authors
[email protected]58580352010-10-26 04:07:502// 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"
David Dorwinb1175462021-10-06 01:55:226
7#include "base/clang_profiling_buildflags.h"
[email protected]3132e35c2011-07-07 20:46:508#include "base/logging.h"
[email protected]ce072a72010-12-31 20:02:169#include "base/threading/platform_thread.h"
aviebe805c2015-12-24 08:20:2810#include "build/build_config.h"
[email protected]58580352010-10-26 04:07:5011
David Dorwinb1175462021-10-06 01:55:2212#if BUILDFLAG(CLANG_PROFILING)
13#include "base/test/clang_profiling.h"
14#endif
15
Peter Kasting811504a72025-01-09 03:18:5016namespace base::debug {
[email protected]58580352010-10-26 04:07:5017
[email protected]d0282962011-01-01 16:08:5218static bool is_debug_ui_suppressed = false;
19
[email protected]58580352010-10-26 04:07:5020bool WaitForDebugger(int wait_seconds, bool silent) {
Xiaohan Wang131aa4d2022-01-15 19:39:4121#if BUILDFLAG(IS_ANDROID)
[email protected]3132e35c2011-07-07 20:46:5022 // The pid from which we know which process to attach to are not output by
23 // android ddms, so we have to print it out explicitly.
[email protected]a42d4632011-10-26 21:48:0024 DLOG(INFO) << "DebugUtil::WaitForDebugger(pid=" << static_cast<int>(getpid())
25 << ")";
[email protected]3132e35c2011-07-07 20:46:5026#endif
[email protected]58580352010-10-26 04:07:5027 for (int i = 0; i < wait_seconds * 10; ++i) {
28 if (BeingDebugged()) {
Peter Kasting134ef9af2024-12-28 02:30:0929 if (!silent) {
[email protected]58580352010-10-26 04:07:5030 BreakDebugger();
Peter Kasting134ef9af2024-12-28 02:30:0931 }
[email protected]58580352010-10-26 04:07:5032 return true;
33 }
Peter Kasting53fd6ee2021-10-05 20:40:4834 PlatformThread::Sleep(Milliseconds(100));
[email protected]58580352010-10-26 04:07:5035 }
36 return false;
37}
38
David Dorwinb1175462021-10-06 01:55:2239void BreakDebugger() {
40#if BUILDFLAG(CLANG_PROFILING)
41 WriteClangProfilingProfile();
42#endif
43
44 BreakDebuggerAsyncSafe();
45}
46
[email protected]d0282962011-01-01 16:08:5247void SetSuppressDebugUI(bool suppress) {
48 is_debug_ui_suppressed = suppress;
49}
50
51bool IsDebugUISuppressed() {
52 return is_debug_ui_suppressed;
53}
54
Peter Kasting811504a72025-01-09 03:18:5055} // namespace base::debug