From a2538600842780f2d50116284224e591fbde0fd0 Mon Sep 17 00:00:00 2001 From: Fons Rademakers <Fons.Rademakers@cern.ch> Date: Mon, 14 Dec 2009 14:38:14 +0000 Subject: [PATCH] allow messages in gdb-backtrace.sh script to be customized using the rootrc resource Root.StacktraceMessage. In more extreme cases the entire script can be replaced using Root.StacktraceScript. git-svn-id: http://root.cern.ch/svn/root/trunk@31878 27541ba8-7e3a-0410-8455-c3a389f83636 --- config/rootrc.in | 6 ++++ core/unix/src/TUnixSystem.cxx | 57 +++++++++++++++++++++++++++-------- etc/gdb-backtrace.sh | 47 +++++++++++++++++++---------- 3 files changed, 82 insertions(+), 28 deletions(-) diff --git a/config/rootrc.in b/config/rootrc.in index dabd772b993..4adcbc4747a 100644 --- a/config/rootrc.in +++ b/config/rootrc.in @@ -56,6 +56,12 @@ Root.MemCheckFile: memcheck.out # Global debug mode. When >0 turns on progressively more details debugging. Root.Debug: 0 Root.Stacktrace: yes +# Allow for a customized backtrace script. +#Root.StacktraceScript: $(ROOTSYS)/etc/gdb-backtrace.sh +# Allow for a customized backtrace messages (e.g. referencing your own project +# bug tracking system). Change this message rather then the entire script. +# The % characters will be replaced by newlines. +#Root.StacktraceMessage: The lines below might hint at the cause of the crash.%If they do not help you then please submit a bug report at%http://myproject/bugs. Please post the ENTIRE stack trace%from above as an attachment in addition to anything else%that might help us fixing this issue. # Ignore errors lower than the ignore level. Possible values: # Print, Info, Warning, Error, Break, SysError and Fatal. diff --git a/core/unix/src/TUnixSystem.cxx b/core/unix/src/TUnixSystem.cxx index 3f8c352359d..ae5364b3566 100644 --- a/core/unix/src/TUnixSystem.cxx +++ b/core/unix/src/TUnixSystem.cxx @@ -2036,6 +2036,27 @@ void TUnixSystem::StackTrace() if (!gEnv->GetValue("Root.Stacktrace", 1)) return; + TString gdbscript = gEnv->GetValue("Root.StacktraceScript", ""); + gdbscript = gdbscript.Strip(); + if (gdbscript != "") { + if (AccessPathName(gdbscript, kReadPermission)) { + fprintf(stderr, "Root.StacktraceScript %s does not exist\n", gdbscript.Data()); + gdbscript = ""; + } else { + gdbscript += " "; + } + } + if (gdbscript == "") { +#ifdef ROOTETCDIR + gdbscript.Form("%s/gdb-backtrace.sh ", ROOTETCDIR); +#else + gdbscript.Form("%s/etc/gdb-backtrace.sh ", gSystem->Getenv("ROOTSYS")); +#endif + } + + TString gdbmess = gEnv->GetValue("Root.StacktraceMessage", ""); + gdbmess = gdbmess.Strip(); + cout.flush(); fflush(stdout); @@ -2058,16 +2079,22 @@ void TUnixSystem::StackTrace() return; } + // write custom message file + TString gdbmessf = "gdb-message"; + if (gdbmess != "") { + FILE *f = TempFileName(gdbmessf); + fprintf(f, "%s\n", gdbmess.Data()); + fclose(f); + } + // use gdb to get stack trace - TString gdbscript; -# ifdef ROOTETCDIR - gdbscript.Form("%s/gdb-backtrace.sh ", ROOTETCDIR); -# else - gdbscript.Form("%s/etc/gdb-backtrace.sh ", gSystem->Getenv("ROOTSYS")); -# endif gdbscript += GetExePath(); gdbscript += " "; gdbscript += GetPid(); + if (gdbmess != "") { + gdbscript += " "; + gdbscript += gdbmessf; + } gdbscript += " 1>&2"; Exec(gdbscript); delete [] gdb; @@ -2143,14 +2170,20 @@ void TUnixSystem::StackTrace() // If it is, use it. If not proceed as before. char *gdb = Which(Getenv("PATH"), "gdb", kExecutePermission); if (gdb) { + // write custom message file + TString gdbmessf = "gdb-message"; + if (gdbmess != "") { + FILE *f = TempFileName(gdbmessf); + fprintf(f, "%s\n", gdbmess.Data()); + fclose(f); + } + // use gdb to get stack trace - TString gdbscript; -# ifdef ROOTETCDIR - gdbscript.Form("%s/gdb-backtrace.sh ", ROOTETCDIR); -# else - gdbscript.Form("%s/etc/gdb-backtrace.sh ", gSystem->Getenv("ROOTSYS")); -# endif gdbscript += GetPid(); + if (gdbmess != "") { + gdbscript += " "; + gdbscript += gdbmessf; + } gdbscript += " 1>&2"; Exec(gdbscript); delete [] gdb; diff --git a/etc/gdb-backtrace.sh b/etc/gdb-backtrace.sh index 26ebf6cfedb..11066c9faa0 100755 --- a/etc/gdb-backtrace.sh +++ b/etc/gdb-backtrace.sh @@ -4,6 +4,7 @@ # It is used by TUnixSystem::StackTrace() on Linux and MacOS X. tempname=`basename $0 .sh` +messfile=`dirname $0`/gdb-message.sh OUTFILE=`mktemp -q /tmp/${tempname}.XXXXXX` if test $? -ne 0; then @@ -12,10 +13,13 @@ fi if [ `uname -s` = "Darwin" ]; then - if test $# -ne 2; then - echo "Usage: ${tempname} <executable> <process-id>" 1>&2 + if test $# -lt 2; then + echo "Usage: ${tempname} <executable> <process-id> [gdb-mess-file]" 1>&2 exit 1 fi + if test $# -eq 3; then + messfile=$3 + fi if test ! -x $1; then echo "${tempname}: process $1 not found." 1>&2 @@ -45,10 +49,13 @@ if [ `uname -s` = "Darwin" ]; then else - if test $# -ne 1; then - echo "Usage: ${tempname} <process-id>" 1>&2 + if test $# -lt 1; then + echo "Usage: ${tempname} <process-id> [gdb-mess-file]" 1>&2 exit 1 fi + if test $# -eq 2; then + messfile=$2 + fi if test ! -r /proc/$1; then echo "${tempname}: process $1 not found." 1>&2 @@ -210,20 +217,28 @@ $line" if test "x$ininterp" = "xyes"; then echo "" echo "" - echo 'The crash is most likely caused by a problem in your script.' - echo 'Try to compile it (.L myscript.C+g) and fix any errors.' - echo 'If that does not help then please submit a bug report at' - echo 'http://root.cern.ch/bugs. Please post the ENTIRE stack trace' - echo 'from above as an attachment in addition to anything else' - echo 'that might help us fixing this issue.' + if test -f $messfile; then + cat $messfile | tr '%' '\n' + else + echo 'The crash is most likely caused by a problem in your script.' + echo 'Try to compile it (.L myscript.C+g) and fix any errors.' + echo 'If that does not help then please submit a bug report at' + echo 'http://root.cern.ch/bugs. Please post the ENTIRE stack trace' + echo 'from above as an attachment in addition to anything else' + echo 'that might help us fixing this issue.' + fi elif ! test "x$frames" = "x"; then echo "" echo "" - echo 'The lines below might hint at the cause of the crash.' - echo 'If they do not help you then please submit a bug report at' - echo 'http://root.cern.ch/bugs. Please post the ENTIRE stack trace' - echo 'from above as an attachment in addition to anything else' - echo 'that might help us fixing this issue.' + if test -f $messfile; then + cat $messfile | tr '%' '\n' + else + echo 'The lines below might hint at the cause of the crash.' + echo 'If they do not help you then please submit a bug report at' + echo 'http://root.cern.ch/bugs. Please post the ENTIRE stack trace' + echo 'from above as an attachment in addition to anything else' + echo 'that might help us fixing this issue.' + fi echo "===========================================================" echo "$frames" echo "===========================================================" @@ -232,5 +247,5 @@ $line" echo "" fi - rm -f $OUTFILE + rm -f $OUTFILE $messfile fi -- GitLab