links: |- commands -|- index -|-
home -|
internal: keyboard a session references end
There is a lot to learn about the gdb debugger, and this brief only scratches the surface ;=)) if that! First the program should be compiled using -g, to include debugging information. In Cmake usage this is achieved by adding the option -DCMAKE_BUILD_TYPE=Debug. This action imbeds all the symbols into the binary.
This GNU DDD is a graphical front-end for command-line debuggers such as GDB
Essentially all the gdb commands can be entered via menu clicks, but it also has a (gbd) console window where gdb commands can be directly entered. A source file can be opened and a break point set at a particular line number.
Like most unix programs gdb has extensive command line options, and thus can be used in a terminal window, like -
$ gdb --args program [commands] (gdb) run
Aternatively gdb can be loaded to the (gdb) prompt, the arguments set, then load the program, like -
$ gdb (gdb) set args [commands] (gdb) file program (gdb) run
All commands can be abbreviated, provided it is unambiguous, and usually an <enter> key will repeat the last command... This is only a very brief set. ALL can be viewed by typing 'help all' at the (gdb) prompt...
command | short | description |
---|---|---|
ni | step one instruction | |
step | s | step to next line of source |
si | step one instruction exactly | |
finish | fin | Continue running until just after function in the selected stack frame returns. Print return (if any). |
next | Continue running until next source in current selected stack frame. That is step over any functions calls. | |
break foo | Set a break point at beginning of function 'foo'. This can also be a module name, and line number, like say (gdb) break RenderTexture.cpp:521 | |
delete foo | Delete a break point. | |
backtrace | bt | Show the available stack frames. |
list | List specified function or line. | |
continue | Continue the program being debugged. | |
run | Start, or re-start the program being debugged. | |
start | Does the equivalent of setting a temporary breakpoint at the beginning of the main procedure and then invoking the `run' command. | |
kill | Kill the execution of the program being debugged. | |
print var | p | Print the value, contents of a program variable. |
quit | Quit the debugger. | |
help [all] | List the help commands. | |
Logging options | ||
set logging file | Set the current log file | |
set logging on | Enable logging | |
set logging redirect on|off | Set logging output mode. If redirect is off, output will go to both the screen and the log file. On will only go to the log file. |
Here is a brief session with the (free) flight simulator, FlightGear... I modified my run_fgfs.sh, adding in the debugger load, as follows... It shows the setting of a break point; 'run' to that breakpoint; setting a 2nd break point per the 'list' line numbers; continuing; viewing two program variables; then 'continue' to exit; then 'quit' gdb. back to linux prompt...
~/fg/fg7$ ./run_fgfs2.sh run_fgfs2.sh: Running in [/home/geoff/fg/fg7/install/fgfs/bin] run_fgfs2.sh: Running: gdb --args ./fgfs --fg-root=/home/geoff/fg/fg7/fgfs/data --timeofday=noon Continue with this DEBUG? Enter y to continue : y Got y ... continuing ... GNU gdb 6.8-debian Copyright (C) 2008 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html> This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. Type "show copying" and "show warranty" for details. This GDB was configured as "x86_64-linux-gnu"... (gdb) break SGSoundMgr::load Breakpoint 1 at 0x9a6130: file soundmgr_openal.cxx, line 544. (gdb) run Starting program: /home/geoff/fg/fg7/install/fgfs/bin/fgfs --fg-root=/home/geoff/fg/fg7/fgfs/data --timeofday=noon [Thread debugging using libthread_db enabled] [New Thread 0x7fb994123700 (LWP 1828)] [New Thread 0x41a54950 (LWP 1831)] [Switching to Thread 0x7fb994123700 (LWP 1828)] Breakpoint 1, SGSoundMgr::load (this=0xf01a00, samplepath=@0x7fff0a9515c0, dbuf=0x7fff0a9515b8, fmt=0x7fff0a951608, sz=0xe39e4c8, frq=0x7fff0a951604) at soundmgr_openal.cxx:544 544 size_t *sz, int *frq ) (gdb) list 539 // SGQuatd ec2body = hlOr*_orientation; 540 _absolute_pos = _base_pos; // + ec2body.backTransform( _offset_pos ); 541 } 542 543 bool SGSoundMgr::load(string &samplepath, void **dbuf, int *fmt, 544 size_t *sz, int *frq ) 545 { 546 if ( !_working ) return false; 547 548 ALenum format; (gdb) list 549 ALsizei size; 550 ALsizei freq; 551 ALvoid *data; 552 553 #if defined(ALUT_API_MAJOR_VERSION) && ALUT_API_MAJOR_VERSION >= 1 554 ALfloat freqf; 555 data = alutLoadMemoryFromFile(samplepath.c_str(), &format, &size, &freqf ); 556 freq = (ALsizei)freqf; 557 int error = alutGetError(); 558 if (data == NULL || error != ALUT_ERROR_NO_ERROR) { (gdb) break 557 Breakpoint 2 at 0x9a61f6: file soundmgr_openal.cxx, line 557. (gdb) continue Continuing. FGMultiplayMgr - No receiver port, Multiplayermode disabled KI266 dme indicator #0 initialized loading scenario 'nimitz_demo' [New Thread 0x411cf950 (LWP 1832)] [New Thread 0x42255950 (LWP 1833)] creating 3D noise texture... DONE [New Thread 0x42a56950 (LWP 1834)] Initializing Nasal Electrical System Breakpoint 1, SGSoundMgr::load (this=0xf01a00, samplepath=@0x7fff0a951920, dbuf=0x7fff0a951918, fmt=0x7fff0a951928, sz=0x7fff0a9518f8, frq=0x7fff0a95192c) at soundmgr_openal.cxx:544 544 size_t *sz, int *frq ) (gdb) list 539 // SGQuatd ec2body = hlOr*_orientation; 540 _absolute_pos = _base_pos; // + ec2body.backTransform( _offset_pos ); 541 } 542 543 bool SGSoundMgr::load(string &samplepath, void **dbuf, int *fmt, 544 size_t *sz, int *frq ) 545 { 546 if ( !_working ) return false; 547 548 ALenum format; (gdb) list 549 ALsizei size; 550 ALsizei freq; 551 ALvoid *data; 552 553 #if defined(ALUT_API_MAJOR_VERSION) && ALUT_API_MAJOR_VERSION >= 1 554 ALfloat freqf; 555 data = alutLoadMemoryFromFile(samplepath.c_str(), &format, &size, &freqf ); 556 freq = (ALsizei)freqf; 557 int error = alutGetError(); 558 if (data == NULL || error != ALUT_ERROR_NO_ERROR) { (gdb) break 557 Breakpoint 2 at 0x9a61f6: file soundmgr_openal.cxx, line 557. (gdb) continue Continuing. FGMultiplayMgr - No receiver port, Multiplayermode disabled KI266 dme indicator #0 initialized loading scenario 'nimitz_demo' [New Thread 0x411cf950 (LWP 1832)] [New Thread 0x42255950 (LWP 1833)] creating 3D noise texture... DONE [New Thread 0x42a56950 (LWP 1834)] Initializing Nasal Electrical System Breakpoint 1, SGSoundMgr::load (this=0xf01a00, samplepath=@0x7fff0a951920, dbuf=0x7fff0a951918, fmt=0x7fff0a951928, sz=0x7fff0a9518f8, frq=0x7fff0a95192c) at soundmgr_openal.cxx:544 544 size_t *sz, int *frq ) (gdb) continue Continuing. Breakpoint 2, SGSoundMgr::load (this=<value optimized out>, samplepath=@0x7fff0a951920, dbuf=0x7fff0a951918, fmt=0x7fff0a951928, sz=0x7fff0a9518f8, frq=0x7fff0a95192c) at soundmgr_openal.cxx:557 557 int error = alutGetError(); (gdb) s 558 if (data == NULL || error != ALUT_ERROR_NO_ERROR) { (gdb) print data $2 = (ALvoid *) 0x0 (gdb) print error $1 = 518 ### This show that the value for the variable 'data' is NULL, ### and the value in 'error' if NOT ALUT_ERROR_NO_ERROR, ### so execution will enter this block... (gdb) list 558 if (data == NULL || error != ALUT_ERROR_NO_ERROR) { 559 string msg = "Failed to load wav file: "; 560 msg.append(alutGetErrorString(error)); 561 throw sg_io_exception(msg.c_str(), sg_location(samplepath)); 562 return false; 563 } (gdb) continue Continuing. Fatal error: Failed to load wav file: There was already an ALC error on entry to an ALUT function at /home/geoff/fg/fg7/fgfs/data/Sounds/rumble.wav [Thread 0x41a54950 (LWP 1831) exited] [Thread 0x42a56950 (LWP 1834) exited] Program exited normally. (gdb) quit ~/fg/fg7$
For a complete list of gdb-help.htm, or download the file gdb-help.txt (unix line endings)
Some references viewed when building this page...
http://sourceware.org/gdb/current/onlinedocs/gdb_4.html#SEC14
http://www.cs.cmu.edu/~gilpin/tutorial/
http://sourceware.org/gdb/current/onlinedocs/gdb/
Search for: Yahoo! 'unix gdb reference', but none found for 'GUI unix debugger'! - Ladebug??? TotalView???
Complete list of gdb) help all