Skip to content

Commit

Permalink
Replace use of pstack with direct invocation of gdb.
Browse files Browse the repository at this point in the history
This switches from the system pstack script to using gdb directly.
Ideally, this will be more usable on non-Linux platforms.

NOTE that this will pull the gdb from the environment (i.e., probably
CMSSW's gdb instead of the system one).  CMSSW's gdb can parse the
debug symbols we ship, meaning that the backtrace will include
niceties like filenames, line numbers, and decode arguments.

The downside of this is that CMSSW's gdb requires 10 minutes
and about 1GB RAM to generate the traceback.
  • Loading branch information
bbockelm committed Jul 8, 2015
1 parent cff10d3 commit b6d0bae
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
15 changes: 11 additions & 4 deletions FWCore/Services/src/InitRootHandlers.cc
Expand Up @@ -269,14 +269,15 @@ namespace edm {
int cmssw_stacktrace(void * /*arg*/)
{
char *const *argv = edm::service::InitRootHandlers::getPstackArgv();
execv("/usr/bin/pstack", argv);
execv("/bin/sh", argv);
::abort();
return 1;
}

static char pstackName[] = "pstack";
static char pstackName[] = "(CMSSW stack trace helper)";
static char dashC[] = "-c";
char InitRootHandlers::pidString_[InitRootHandlers::pidStringLength_] = {};
char * const InitRootHandlers::pstackArgv_[3] = {pstackName, InitRootHandlers::pidString_, nullptr};
char * const InitRootHandlers::pstackArgv_[] = {pstackName, dashC, InitRootHandlers::pidString_, nullptr};

InitRootHandlers::InitRootHandlers (ParameterSet const& pset, ActivityRegistry& iReg)
: RootHandlers(),
Expand Down Expand Up @@ -416,7 +417,13 @@ namespace edm {
void
InitRootHandlers::cachePidInfo()
{
assert(snprintf(pidString_, pidStringLength_-1, "%d", getpid()) < pidStringLength_);
assert(snprintf(pidString_, pidStringLength_-1, "gdb -quiet -p %d 2>&1 <<EOF |\n"
"set width 0\n"
"set height 0\n"
"set pagination no\n"
"thread apply all bt\n"
"EOF\n"
"/bin/sed -n -e 's/^\\((gdb) \\)*//' -e '/^#/p' -e '/^Thread/p'", getpid()) < pidStringLength_);
}

} // end of namespace service
Expand Down
4 changes: 2 additions & 2 deletions FWCore/Services/src/InitRootHandlers.h
Expand Up @@ -30,9 +30,9 @@ namespace edm {
void cachePidInfoHandler(unsigned int, unsigned int) {cachePidInfo();}
void cachePidInfo();

static const int pidStringLength_ = 50;
static const int pidStringLength_ = 200;
static char pidString_[pidStringLength_];
static char * const pstackArgv_[3];
static char * const pstackArgv_[];
bool unloadSigHandler_;
bool resetErrHandler_;
bool loadAllDictionaries_;
Expand Down

0 comments on commit b6d0bae

Please sign in to comment.