summaryrefslogtreecommitdiff
path: root/src/mongo/util/debugger.cpp
diff options
context:
space:
mode:
authorAndrew Morrow <acm@mongodb.com>2015-07-18 11:25:56 -0400
committerAndrew Morrow <acm@mongodb.com>2015-08-10 16:34:14 -0400
commit588278785b0ae4b3cdc193e2aeaa8ae42fd84114 (patch)
treec5cb7e8fae7f02000374541bc9980fd2e072175b /src/mongo/util/debugger.cpp
parenta3fb8bf72e9d57587c2da817ec536a2f29da8a6c (diff)
downloadmongo-588278785b0ae4b3cdc193e2aeaa8ae42fd84114.tar.gz
SERVER-9666 Remove dependency cycles from debugger gdbserver support
Diffstat (limited to 'src/mongo/util/debugger.cpp')
-rw-r--r--src/mongo/util/debugger.cpp36
1 files changed, 20 insertions, 16 deletions
diff --git a/src/mongo/util/debugger.cpp b/src/mongo/util/debugger.cpp
index 659c8b726f2..e473ac8f875 100644
--- a/src/mongo/util/debugger.cpp
+++ b/src/mongo/util/debugger.cpp
@@ -31,7 +31,12 @@
#include "mongo/util/debugger.h"
-#include "mongo/db/server_options.h"
+#if defined(USE_GDBSERVER)
+#include <unistd.h>
+#include <cstdio>
+#include <cstdlib>
+#endif
+
#include "mongo/util/debug_util.h"
#ifndef _WIN32
@@ -49,7 +54,7 @@ void breakpoint() {
// prevent SIGTRAP from crashing the program if default action is specified and we are not
// in gdb
struct sigaction current;
- sigaction(SIGTRAP, NULL, &current);
+ sigaction(SIGTRAP, nullptr, &current);
if (current.sa_handler == SIG_DFL) {
signal(SIGTRAP, SIG_IGN);
}
@@ -72,26 +77,24 @@ void launchGDB(int) {
// Don't come back here
signal(SIGTRAP, SIG_IGN);
- const int newPort = serverGlobalParams.port + 2000;
-
char pidToDebug[16];
int pidRet = snprintf(pidToDebug, sizeof(pidToDebug), "%d", getpid());
- invariant(pidRet >= 0 && size_t(pidRet) < sizeof(pidToDebug));
-
- char hostPort[32];
- int hostRet = snprintf(hostPort, sizeof(hostPort), "localhost:%d", newPort);
- invariant(hostRet >= 0 && size_t(hostRet) < sizeof(hostPort));
+ if (!(pidRet >= 0 && size_t(pidRet) < sizeof(pidToDebug)))
+ std::abort();
char msg[128];
- int msgRet =
- snprintf(msg, sizeof(msg), "\n\n\t**** Launching gdbserver on %s ****\n\n", hostPort);
- invariant(msgRet >= 0 && size_t(msgRet) < sizeof(msg));
- invariant(write(STDERR_FILENO, msg, msgRet) == msgRet);
+ int msgRet = snprintf(
+ msg, sizeof(msg), "\n\n\t**** Launching gdbserver (use lsof to find port) ****\n\n");
+ if (!(msgRet >= 0 && size_t(msgRet) < sizeof(msg)))
+ std::abort();
+
+ if (!(write(STDERR_FILENO, msg, msgRet) == msgRet))
+ std::abort();
if (fork() == 0) {
// child
- execlp("gdbserver", "gdbserver", "--attach", hostPort, pidToDebug, NULL);
- perror(NULL);
+ execlp("gdbserver", "gdbserver", "--attach", ":0", pidToDebug, nullptr);
+ perror(nullptr);
_exit(1);
} else {
// parent
@@ -101,7 +104,8 @@ void launchGDB(int) {
}
void setupSIGTRAPforGDB() {
- verify(signal(SIGTRAP, launchGDB) != SIG_ERR);
+ if (!(signal(SIGTRAP, launchGDB) != SIG_ERR))
+ std::abort();
}
#else
void setupSIGTRAPforGDB() {}