Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1103)

Unified Diff: content/common/debug_util.cc

Issue 16328003: Move a bunch of child-only code from content/common to content/child (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: content/common/debug_util.cc
diff --git a/content/common/debug_util.cc b/content/common/debug_util.cc
new file mode 100644
index 0000000000000000000000000000000000000000..1364a6f9cecbdb832b3e14c85e87691af7783330
--- /dev/null
+++ b/content/common/debug_util.cc
@@ -0,0 +1,58 @@
+// Copyright 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "content/common/debug_util.h"
+
+#if defined(OS_POSIX) && !defined(OS_ANDROID)
+#include <signal.h> // For SigUSR1Handler below.
+#endif
+
+#include "base/logging.h"
+
+#if defined(OS_POSIX) && !defined(OS_ANDROID)
+static void SigUSR1Handler(int signal) { }
+#endif
+
+namespace content {
+
+void WaitForDebugger(const std::string& label) {
+#if defined(OS_WIN)
+#if defined(GOOGLE_CHROME_BUILD)
+ std::string title = "Google Chrome";
+#else // CHROMIUM_BUILD
+ std::string title = "Chromium";
+#endif // CHROMIUM_BUILD
+ title += " ";
+ title += label; // makes attaching to process easier
+ std::string message = label;
+ message += " starting with pid: ";
+ message += base::IntToString(base::GetCurrentProcId());
+ ::MessageBox(NULL, UTF8ToWide(message).c_str(), UTF8ToWide(title).c_str(),
+ MB_OK | MB_SETFOREGROUND);
+#elif defined(OS_POSIX)
+#if defined(OS_ANDROID)
+ LOG(ERROR) << label << " waiting for GDB.";
+ // Wait 24 hours for a debugger to be attached to the current process.
+ base::debug::WaitForDebugger(24 * 60 * 60, false);
+#else
+ // TODO(playmobil): In the long term, overriding this flag doesn't seem
+ // right, either use our own flag or open a dialog we can use.
+ // This is just to ease debugging in the interim.
+ LOG(ERROR) << label
+ << " ("
+ << getpid()
+ << ") paused waiting for debugger to attach. "
+ << "Send SIGUSR1 to unpause.";
+ // Install a signal handler so that pause can be woken.
+ struct sigaction sa;
+ memset(&sa, 0, sizeof(sa));
+ sa.sa_handler = SigUSR1Handler;
+ sigaction(SIGUSR1, &sa, NULL);
+
+ pause();
+#endif // defined(OS_ANDROID)
+#endif // defined(OS_POSIX)
+}
+
+} // namespace content

Powered by Google App Engine
This is Rietveld 408576698