How To - Debug                                                                        Kenji Hamano

Last modified : Jun27, 2005                                              Back to How To      Back to Home


A. Debugging by "gdb"
   Supposing your package name is myMiniUser and your executable is myMiniUserApp.
   And the command to run yuor job is "myMiniUserApp myJob.tcl"
   1. Compile and link in debug mode.
      This is optional, but I recommend this.
         > gmake myMiniUser.lib ROPT=-noOptimize-Debug
         > gmake myMiniUser.bin ROPT=-noOptimize-Debug
   2. Go to workdir and use gdb
         > cd workdir
         > gdb myMiniUserApp
   2. The gdb starts and give you an prompt then
         > run myJob.tcl
   3. Your program starts running and spits out logs as usual till your program crash.
   When it crash and the prompt of gdb returns
         > where
   This gives you information of the cause of the crash.

B. To print out ErrMsg(trace) messages.
   1. You can embedd messages for debugging or for checking the flow of your program using
         ErrMsg(trace) << << endmsg;
   2. To enable to print out these messages in your log, add these lines in yout tcl file
         module talk WhateverModule
            verbose set true
            production set false
         exit
   3. The advantage of ErrMsg(trace) is that you don't need to recompile your code to enable and disable these messages.
   4. If you are using AppActionErrLogger, as most BaBar Framework applications do
severityverboseproductionresult
>= warning**output
routineTFoutput
routineTToutput
routineFFoutput
routineF Tno output
<= traceTFoutput
<= traceTToutput
<= traceFFno output
<= traceFTno output

ErrMsg(XXX) -
verbose:falsefalsetrue
production:truefalse*
debugging--xjust the message
trace--xjust the message
routine-xxmessage + ModuleName
warningxxxsame as routine + File & Line
errorx xxsame as warning
fatalx xxsame as warning & aborts


C. Find memory leak by "valgrind"
   1. Run valgrind with your executable and tcl
         > valgrind --tool=memcheck --leak-check=yes --show-reachable=yes --num-callers=15 --error-limit=no ../bin/Linux24SL3_i386_gcc2953/BToDlnuMiniApp myAnalysisJob.tcl
   2. Usually it takes time, so it's better to submit this job to a batch queue
         > bsub -q kanga -o memChck.log "valgrind --tool=memcheck --leak-check=yes --show-reachable=yes --num-callers=15 --error-limit=no ../bin/Linux24SL3_i386_gcc2953/BToDlnuMiniApp myAnalysisJob.tcl"
   3. Look for "definitely lost" or "probably lost" in your log file
         > less memChck.log
         > /definitely
   Here is a reference for memory leak.
   Here is a reference for valgrind.