[email protected] | 3132e35c | 2011-07-07 20:46:50 | [diff] [blame] | 1 | // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
[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 | |||||
[email protected] | 5858035 | 2010-10-26 04:07:50 | [diff] [blame] | 16 | namespace base { |
17 | namespace debug { | ||||
18 | |||||
[email protected] | d028296 | 2011-01-01 16:08:52 | [diff] [blame] | 19 | static bool is_debug_ui_suppressed = false; |
20 | |||||
[email protected] | 5858035 | 2010-10-26 04:07:50 | [diff] [blame] | 21 | bool WaitForDebugger(int wait_seconds, bool silent) { |
[email protected] | 3132e35c | 2011-07-07 20:46:50 | [diff] [blame] | 22 | #if defined(OS_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. | ||||
[email protected] | a42d463 | 2011-10-26 21:48:00 | [diff] [blame] | 25 | DLOG(INFO) << "DebugUtil::WaitForDebugger(pid=" << static_cast<int>(getpid()) |
26 | << ")"; | ||||
[email protected] | 3132e35c | 2011-07-07 20:46:50 | [diff] [blame] | 27 | #endif |
[email protected] | 5858035 | 2010-10-26 04:07:50 | [diff] [blame] | 28 | for (int i = 0; i < wait_seconds * 10; ++i) { |
29 | if (BeingDebugged()) { | ||||
30 | if (!silent) | ||||
31 | BreakDebugger(); | ||||
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 | |||||
[email protected] | 5858035 | 2010-10-26 04:07:50 | [diff] [blame] | 55 | } // namespace debug |
56 | } // namespace base |