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

Unified Diff: base/debug/debugger_posix.cc

Issue 2312393002: Debug exit code (Closed)
Patch Set: abort instead of int3 Created 4 years, 3 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
« no previous file with comments | « no previous file | base/debug/stack_trace_posix.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/debug/debugger_posix.cc
diff --git a/base/debug/debugger_posix.cc b/base/debug/debugger_posix.cc
index e92d5a5619a6f113ad5b7adc5fdb92af7a541b46..974759e23466d508fc4a18fe05cc46d22add2eab 100644
--- a/base/debug/debugger_posix.cc
+++ b/base/debug/debugger_posix.cc
@@ -6,6 +6,7 @@
#include <errno.h>
#include <fcntl.h>
+#include <signal.h>
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
@@ -59,6 +60,7 @@ namespace debug {
// Based on Apple's recommended method as described in
// http://developer.apple.com/qa/qa2004/qa1361.html
bool BeingDebugged() {
+ LOG(ERROR) << "In BeingDebugged()";
// NOTE: This code MUST be async-signal safe (it's used by in-process
// stack dumping signal handler). NO malloc or stdio is allowed here.
//
@@ -72,8 +74,10 @@ bool BeingDebugged() {
static bool is_set = false;
static bool being_debugged = false;
- if (is_set)
+ if (is_set) {
+ LOG(ERROR) << "is_set=true, being_debugged=" << being_debugged;
return being_debugged;
+ }
// Initialize mib, which tells sysctl what info we want. In this case,
// we're looking for information about a specific process ID.
@@ -105,6 +109,7 @@ bool BeingDebugged() {
if (sysctl_result != 0) {
is_set = true;
being_debugged = false;
+ LOG(ERROR) << "sysctl_result=" << sysctl_result << " being_debugged=" << being_debugged;
return being_debugged;
}
@@ -117,6 +122,7 @@ bool BeingDebugged() {
#else
being_debugged = (info.kp_proc.p_flag & P_TRACED) != 0;
#endif
+ LOG(ERROR) << "being_debugged=" << being_debugged;
return being_debugged;
}
@@ -184,22 +190,22 @@ bool BeingDebugged() {
// Mac: Always send SIGTRAP.
#if defined(ARCH_CPU_ARMEL)
-#define DEBUG_BREAK_ASM() asm("bkpt 0")
+#define DEBUG_BREAK_ASM() do { LOG(ERROR) << "DEBUG_BREAK_ASM brpt 0"; asm("bkpt 0"); } while (0)
#elif defined(ARCH_CPU_ARM64)
-#define DEBUG_BREAK_ASM() asm("brk 0")
+#define DEBUG_BREAK_ASM() do { LOG(ERROR) << "DEBUG_BREAK_ASM brk 0"; asm("brk 0"); } while (0)
#elif defined(ARCH_CPU_MIPS_FAMILY)
-#define DEBUG_BREAK_ASM() asm("break 2")
+#define DEBUG_BREAK_ASM() do { LOG(ERROR) << "DEBUG_BREAK_ASM break 2"; asm("break 2"); } while (0)
#elif defined(ARCH_CPU_X86_FAMILY)
-#define DEBUG_BREAK_ASM() asm("int3")
+#define DEBUG_BREAK_ASM() do { LOG(ERROR) << "DEBUG_BREAK_ASM abort"; abort(); asm("int3"); } while (0)
#endif
#if defined(NDEBUG) && !defined(OS_MACOSX) && !defined(OS_ANDROID)
-#define DEBUG_BREAK() abort()
+#define DEBUG_BREAK() do { LOG(ERROR) << "DEBUG_BREAK abort()"; abort(); } while (0)
#elif defined(OS_NACL)
// The NaCl verifier doesn't let use use int3. For now, we call abort(). We
// should ask for advice from some NaCl experts about the optimum thing here.
// http://code.google.com/p/nativeclient/issues/detail?id=645
-#define DEBUG_BREAK() abort()
+#define DEBUG_BREAK() do { LOG(ERROR) << "DEBUG_BREAK abort()"; abort(); } while (0)
#elif !defined(OS_MACOSX)
// Though Android has a "helpful" process called debuggerd to catch native
// signals on the general assumption that they are fatal errors. If no debugger
@@ -215,7 +221,9 @@ bool BeingDebugged() {
// use a debugger.
namespace {
void DebugBreak() {
+ LOG(ERROR) << "DebugBreak function";
if (!BeingDebugged()) {
+ LOG(ERROR) << "Not being debugged. abort()";
abort();
} else {
#if defined(DEBUG_BREAK_ASM)
@@ -223,6 +231,7 @@ void DebugBreak() {
#else
volatile int go = 0;
while (!go) {
+ LOG(ERROR) << "In loop waiting for debugger";
base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(100));
}
#endif
@@ -236,6 +245,13 @@ void DebugBreak() {
#error "Don't know how to debug break on this architecture/OS"
#endif
+typedef void (*handlert)(int);
+handlert oldhandlers[32];
+void newhandler(int sig) {
+ LOG(ERROR) << "handler: " << sig;
+ oldhandlers[sig](sig);
+}
+
void BreakDebugger() {
// NOTE: This code MUST be async-signal safe (it's used by in-process
// stack dumping signal handler). NO malloc or stdio is allowed here.
@@ -246,7 +262,15 @@ void BreakDebugger() {
static int static_variable_to_make_this_function_unique = 0;
base::debug::Alias(&static_variable_to_make_this_function_unique);
+ LOG(ERROR) << "DEBUG_BREAK";
+
+ //for (int i = 1; i < 32; ++i)
+ // oldhandlers[i] = signal(i, newhandler);
+
DEBUG_BREAK();
+
+ LOG(ERROR) << "After DEBUG_BREAK";
+
#if defined(OS_ANDROID) && !defined(OFFICIAL_BUILD)
// For Android development we always build release (debug builds are
// unmanageably large), so the unofficial build is used for debugging. It is
« no previous file with comments | « no previous file | base/debug/stack_trace_posix.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698