Skip to content

Commit

Permalink
add an option to leave an interactive gdb session on crash
Browse files Browse the repository at this point in the history
  • Loading branch information
Dan Riley authored and Dan Riley committed Feb 3, 2021
1 parent add3363 commit f7fc02a
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions FWCore/Services/plugins/InitRootHandlers.cc
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ namespace edm {
bool resetErrHandler_;
bool loadAllDictionaries_;
bool autoLibraryLoader_;
bool interactiveDebug_;
std::shared_ptr<const void> sigBusHandler_;
std::shared_ptr<const void> sigSegvHandler_;
std::shared_ptr<const void> sigIllHandler_;
Expand Down Expand Up @@ -750,7 +751,8 @@ namespace edm {
unloadSigHandler_(pset.getUntrackedParameter<bool>("UnloadRootSigHandler")),
resetErrHandler_(pset.getUntrackedParameter<bool>("ResetRootErrHandler")),
loadAllDictionaries_(pset.getUntrackedParameter<bool>("LoadAllDictionaries")),
autoLibraryLoader_(loadAllDictionaries_ or pset.getUntrackedParameter<bool>("AutoLibraryLoader")) {
autoLibraryLoader_(loadAllDictionaries_ or pset.getUntrackedParameter<bool>("AutoLibraryLoader")),
interactiveDebug_(pset.getUntrackedParameter<bool>("InteractiveDebug")) {
stackTracePause_ = pset.getUntrackedParameter<int>("StackTracePauseTime");

if (unloadSigHandler_) {
Expand Down Expand Up @@ -870,6 +872,8 @@ namespace edm {
->setComment(
"If True, do an abort when a signal occurs that causes a crash. If False, ROOT will do an exit which "
"attempts to do a clean shutdown.");
desc.addUntracked<bool>("InteractiveDebug", false)->setComment("If True, leave gdb attached to cmsRun after a crash; "
"if False, attach gdb, print a stack trace, and quit gdb");
desc.addUntracked<int>("DebugLevel", 0)->setComment("Sets ROOT's gDebug value.");
desc.addUntracked<int>("StackTracePauseTime", 300)
->setComment("Seconds to pause other threads during stack trace.");
Expand All @@ -889,15 +893,19 @@ namespace edm {
//In that case, we are already all setup
return;
}
if (snprintf(pidString_,
pidStringLength_ - 1,
"date; gdb -quiet -p %d 2>&1 <<EOF |\n"
std::string gdbcmd{"date; gdb -quiet -p %d"};
if (!interactiveDebug_) {
gdbcmd += " 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'",
"/bin/sed -n -e 's/^\\((gdb) \\)*//' -e '/^#/p' -e '/^Thread/p'";
}
if (snprintf(pidString_,
pidStringLength_ - 1,
gdbcmd.c_str(),
getpid()) >= pidStringLength_) {
std::ostringstream sstr;
sstr << "Unable to pre-allocate stacktrace handler information";
Expand Down

0 comments on commit f7fc02a

Please sign in to comment.