Avi Drissman | e4622aa | 2022-09-08 20:36:06 | [diff] [blame] | 1 | // Copyright 2011 The Chromium Authors |
[email protected] | 5858035 | 2010-10-26 04:07:50 | [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" | ||||
David Dorwin | b117546 | 2021-10-06 01:55:22 | [diff] [blame] | 6 | |
7 | #include "base/clang_profiling_buildflags.h" | ||||
[email protected] | 3132e35c | 2011-07-07 20:46:50 | [diff] [blame] | 8 | #include "base/logging.h" |
[email protected] | ce072a7 | 2010-12-31 20:02:16 | [diff] [blame] | 9 | #include "base/threading/platform_thread.h" |
avi | ebe805c | 2015-12-24 08:20:28 | [diff] [blame] | 10 | #include "build/build_config.h" |
[email protected] | 5858035 | 2010-10-26 04:07:50 | [diff] [blame] | 11 | |
David Dorwin | b117546 | 2021-10-06 01:55:22 | [diff] [blame] | 12 | #if BUILDFLAG(CLANG_PROFILING) |
13 | #include "base/test/clang_profiling.h" | ||||
14 | #endif | ||||
15 | |||||
Peter Kasting | 811504a7 | 2025-01-09 03:18:50 | [diff] [blame] | 16 | namespace base::debug { |
[email protected] | 5858035 | 2010-10-26 04:07:50 | [diff] [blame] | 17 | |
[email protected] | d028296 | 2011-01-01 16:08:52 | [diff] [blame] | 18 | static bool is_debug_ui_suppressed = false; |
19 | |||||
[email protected] | 5858035 | 2010-10-26 04:07:50 | [diff] [blame] | 20 | bool WaitForDebugger(int wait_seconds, bool silent) { |
Xiaohan Wang | 131aa4d | 2022-01-15 19:39:41 | [diff] [blame] | 21 | #if BUILDFLAG(IS_ANDROID) |
[email protected] | 3132e35c | 2011-07-07 20:46:50 | [diff] [blame] | 22 | // 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] | a42d463 | 2011-10-26 21:48:00 | [diff] [blame] | 24 | DLOG(INFO) << "DebugUtil::WaitForDebugger(pid=" << static_cast<int>(getpid()) |
25 | << ")"; | ||||
[email protected] | 3132e35c | 2011-07-07 20:46:50 | [diff] [blame] | 26 | #endif |
[email protected] | 5858035 | 2010-10-26 04:07:50 | [diff] [blame] | 27 | for (int i = 0; i < wait_seconds * 10; ++i) { |
28 | if (BeingDebugged()) { | ||||
Peter Kasting | 134ef9af | 2024-12-28 02:30:09 | [diff] [blame] | 29 | if (!silent) { |
[email protected] | 5858035 | 2010-10-26 04:07:50 | [diff] [blame] | 30 | BreakDebugger(); |
Peter Kasting | 134ef9af | 2024-12-28 02:30:09 | [diff] [blame] | 31 | } |
[email protected] | 5858035 | 2010-10-26 04:07:50 | [diff] [blame] | 32 | return true; |
33 | } | ||||
Peter Kasting | 53fd6ee | 2021-10-05 20:40:48 | [diff] [blame] | 34 | PlatformThread::Sleep(Milliseconds(100)); |
[email protected] | 5858035 | 2010-10-26 04:07:50 | [diff] [blame] | 35 | } |
36 | return false; | ||||
37 | } | ||||
38 | |||||
David Dorwin | b117546 | 2021-10-06 01:55:22 | [diff] [blame] | 39 | void BreakDebugger() { |
40 | #if BUILDFLAG(CLANG_PROFILING) | ||||
41 | WriteClangProfilingProfile(); | ||||
42 | #endif | ||||
43 | |||||
44 | BreakDebuggerAsyncSafe(); | ||||
45 | } | ||||
46 | |||||
[email protected] | d028296 | 2011-01-01 16:08:52 | [diff] [blame] | 47 | void SetSuppressDebugUI(bool suppress) { |
48 | is_debug_ui_suppressed = suppress; | ||||
49 | } | ||||
50 | |||||
51 | bool IsDebugUISuppressed() { | ||||
52 | return is_debug_ui_suppressed; | ||||
53 | } | ||||
54 | |||||
Peter Kasting | 811504a7 | 2025-01-09 03:18:50 | [diff] [blame] | 55 | } // namespace base::debug |