summaryrefslogtreecommitdiff
path: root/src/mongo/util/debugger.cpp
diff options
context:
space:
mode:
authorMathias Stearn <mathias@10gen.com>2015-03-06 15:22:24 -0500
committerMathias Stearn <mathias@10gen.com>2015-03-09 18:52:52 -0400
commitf6656c88c4beefb963798afbd6a40d59a6164952 (patch)
tree648e86c4514f2d02576ae45d059abdc71a3fe044 /src/mongo/util/debugger.cpp
parent055d827ed7c144f26441441a75ea8dd5f797f9de (diff)
downloadmongo-f6656c88c4beefb963798afbd6a40d59a6164952.tar.gz
Fix launchGDBServer() compile and make more signal safe
Diffstat (limited to 'src/mongo/util/debugger.cpp')
-rw-r--r--src/mongo/util/debugger.cpp28
1 files changed, 17 insertions, 11 deletions
diff --git a/src/mongo/util/debugger.cpp b/src/mongo/util/debugger.cpp
index 03f8dfa7c24..13be663a955 100644
--- a/src/mongo/util/debugger.cpp
+++ b/src/mongo/util/debugger.cpp
@@ -31,8 +31,6 @@
#include "mongo/util/debugger.h"
-#include <iostream>
-
#include "mongo/db/server_options.h"
#include "mongo/util/debug_util.h"
@@ -40,10 +38,6 @@
#include <signal.h>
#endif
-#if defined(USE_GDBSERVER)
-#include "mongo/db/jsobj.h"
-#endif // defined(USE_GDBSERVER)
-
namespace mongo {
void breakpoint() {
#ifdef _WIN32
@@ -77,15 +71,27 @@ namespace mongo {
// 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());
+ 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));
+
+ 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);
- 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);
+ execlp("gdbserver", "gdbserver", "--attach", hostPort, pidToDebug, NULL);
perror(NULL);
+ _exit(1);
}
else {
//parent