debugger.cc 1.1 KB

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