summaryrefslogtreecommitdiff
path: root/src/mongo/util/debugger.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/mongo/util/debugger.cpp')
-rw-r--r--src/mongo/util/debugger.cpp81
1 files changed, 40 insertions, 41 deletions
diff --git a/src/mongo/util/debugger.cpp b/src/mongo/util/debugger.cpp
index 03f8dfa7c24..d4b722e2a0b 100644
--- a/src/mongo/util/debugger.cpp
+++ b/src/mongo/util/debugger.cpp
@@ -45,60 +45,59 @@
#endif // defined(USE_GDBSERVER)
namespace mongo {
- void breakpoint() {
+void breakpoint() {
#ifdef _WIN32
- DEV DebugBreak();
+ DEV DebugBreak();
#endif
#ifndef _WIN32
- // code to raise a breakpoint in GDB
- ONCE {
- //prevent SIGTRAP from crashing the program if default action is specified and we are not in gdb
- struct sigaction current;
- sigaction(SIGTRAP, NULL, &current);
- if (current.sa_handler == SIG_DFL) {
- signal(SIGTRAP, SIG_IGN);
- }
+ // code to raise a breakpoint in GDB
+ ONCE {
+ // prevent SIGTRAP from crashing the program if default action is specified and we are not in gdb
+ struct sigaction current;
+ sigaction(SIGTRAP, NULL, &current);
+ if (current.sa_handler == SIG_DFL) {
+ signal(SIGTRAP, SIG_IGN);
}
+ }
- raise(SIGTRAP);
+ raise(SIGTRAP);
#endif
- }
+}
#if defined(USE_GDBSERVER)
- /* Magic gdb trampoline
- * Do not call directly! call setupSIGTRAPforGDB()
- * Assumptions:
- * 1) gdbserver is on your path
- * 2) You have run "handle SIGSTOP noprint" in gdb
- * 3) serverGlobalParams.port + 2000 is free
- */
- void launchGDB(int) {
- // Don't come back here
- signal(SIGTRAP, SIG_IGN);
+/* Magic gdb trampoline
+ * Do not call directly! call setupSIGTRAPforGDB()
+ * Assumptions:
+ * 1) gdbserver is on your path
+ * 2) You have run "handle SIGSTOP noprint" in gdb
+ * 3) serverGlobalParams.port + 2000 is free
+ */
+void launchGDB(int) {
+ // Don't come back here
+ signal(SIGTRAP, SIG_IGN);
- int newPort = serverGlobalParams.port + 2000;
- string newPortStr = "localhost:" + BSONObjBuilder::numStr(newPort);
- string pidToDebug = BSONObjBuilder::numStr(getpid());
+ int newPort = serverGlobalParams.port + 2000;
+ string newPortStr = "localhost:" + BSONObjBuilder::numStr(newPort);
+ string pidToDebug = BSONObjBuilder::numStr(getpid());
- cout << "\n\n\t**** Launching gdbserver on " << newPortStr << " ****" << endl << endl;
- if (fork() == 0) {
- //child
- execlp("gdbserver", "gdbserver", "--attach", newPortStr.c_str(), pidToDebug.c_str(), NULL);
- perror(NULL);
- }
- else {
- //parent
- raise(SIGSTOP); // pause all threads until gdb connects and continues
- raise(SIGTRAP); // break inside gdbserver
- }
+ cout << "\n\n\t**** Launching gdbserver on " << newPortStr << " ****" << endl
+ << endl;
+ if (fork() == 0) {
+ // child
+ execlp("gdbserver", "gdbserver", "--attach", newPortStr.c_str(), pidToDebug.c_str(), NULL);
+ perror(NULL);
+ } else {
+ // parent
+ raise(SIGSTOP); // pause all threads until gdb connects and continues
+ raise(SIGTRAP); // break inside gdbserver
}
+}
- void setupSIGTRAPforGDB() {
- verify( signal(SIGTRAP , launchGDB ) != SIG_ERR );
- }
+void setupSIGTRAPforGDB() {
+ verify(signal(SIGTRAP, launchGDB) != SIG_ERR);
+}
#else
- void setupSIGTRAPforGDB() {
- }
+void setupSIGTRAPforGDB() {}
#endif
}