Last Modified: 14 February 2002, RDK, kennedy@fnal.gov Mini HOW-TO on Using the gdb (Command Line Interface) Debugger ============================================================== A) Setup - UPS product setup ---------------------------- % setup gdb v5_0b (See NOTE 4 at end for news) This is often not the current version on CDF platforms, so do specify the version number to be sure to get proper Kai C++ name demangling support. If you start up the preferred gdb, then you should see a start-up screen that says something about "KCC", such as: "GNU gdb 5.0 + KCC patch level 3". B) Start-up - starting up the program ------------------------------------- Casual gdb users generally start the debugger in one of three ways: % gdb % gdb % gdb The first starts gdb without loading an executable. The second loads the indicated executable into the debugger. And the third loads the executable as well as a core dump in order to perform a post mortem analysis. In any of these cases you should also setup gdb to interpret symbols according to Kai's name demangling scheme (known as "edg" for the name of the C++ front-end used) with: (gdb) set demangle-style edg One can put this into a file $USER/.gdbinit to avoid typing it each time you start gdb. If this command causes gdb to complain, then you will not have proper name demangling of C++ symbols. C) Execution - using the debugger --------------------------------- 1) (gdb) help view the gdb on-line help 2) (gdb) break set a break point at 3) (gdb) run execute programs with 4) (gdb) step proceed to next source line (into subroutines) 5) (gdb) next proceed to next source line (over subroutines) 6) (gdb) info args list arguments in current frame by name 7) (gdb) info locals list local variables by name 8) (gdb) info variables list global and static variables by name 9) (gdb) where print current stack frame listing 10)(gdb) down go down (away from main()) one stack frame 11)(gdb) up go up (towards main()) one stack frame 12)(gdb) list list source at current point 13)(gdb) print print the value of 14)(gdb) file load an exectuable file into gdb 15)(gdb) core load a corefile into gdb 16)(gdb) quit quit D) Caveats and Limitations -------------------------- 1) Core files from processes that have suffered stack corruption will often print a useless stack dump ("where") or show oddities beginning at some depth in the stack and and continuing lower in program depth (which on the screen is seen higher in the print-out). Look for the lowest stack frame that makes sense or has non-null values for arguments, and start debugging there. 2) gdb does not yet support multi-threaded programs under IRIX 6.5, regardless of the C++ compiler in use. Unfortunately, at present, CDF Offline is forced to use multi-threaded programming due to the way we link to oracle client libraries. Many programs, such as ProductionExe and AC++Dump, cannot be debugged on IRIX because of this at present. The symptom is a message that is printed at the beginning of the debugged program referring to "Signal ?", then the program spins in a loop forever never reaching main(). This has been debugged in detail (yes, you can run gdb inside of gdb), and cannot be easily corrected in the gdb software. 3) gdb v5.1.X claims to support "edg" name-demangling, but it unfortunately does not support the exact version used by Kai C++. For instance, "argc" and "argv" are left in a partially mangled state like: #17 0x0830ba73 in main (__159632_14_argc=6, __159632_26_argv=0xbfffbac4) No patches to gdb v5.1 have been made available by Kai at this time, nor has any mention of this or estimate been given by Kai. I have observed this problem with gdb 5.1.1 as well as gdb 5.1.0. 4) If you see an error message while running gdb on Linux that looks something like: "thread_id: invalid handle", then you are running an improperly built gdb executable. To avoid this problem with CDF Offline software, the maintainer of gdb must build it without the "-r dynamic" switch that the gdb distribution uses. I have a hand-built gdb executable available until this is fixed in the FNAL KITS packaging of gdb at: fcdfsgi2:~kennedy/Debuggers/gdbkcc-5.0k3a-frhlinux6.1 Feel free to copy this, rename it as you wish, and put it in your PATH before any other gdb executables. .the end.