Using gdb - the GNU Debugger ============================ - compilation: $ gcc -Wall -g check.c -o check entering gdb from command shell (only textual interface): $ gdb gdb gives you a command line interface that will be noted here as '>'. - entering gdb from emacs (textual interface + an arrow to current place) Alt+x and then: gdb press enter when asked "Run gdb (like this): gdb". - entering ddd which is a graphical front-end for gdb: $ ddd & you can also use the regular textual interface. if you use the graphical interface, you can still see what are the equivalence textual command (thus you can use ddd when you want to learn how to do something in gdb) ddd also lets you visualize data structures (ddd stands for "Data Display Debugger) but I didn't find the way it is implemented very helpful. some basic commands =================== loading an executable named check (assuming it was compiled with -g): > file check running the file: >run running the file with arguments: >run arg1 stam yosi placing a breakpoint at the begging of a function named foo: >break foo removing that breakpoint: >clear foo placing a breakpoint at line#24 of the file: > break check.c:24 Note that the name of the source file was used ! advancing the execution in one single step : >s or >step advancing the execution in one function invocation: >n or >next Note that for a command like 'a++', using 'step' and 'next' is the same, but for a function call like 'foo()', using 'step' will enter foo and using 'next' - won't. printing the function calls up to the current point: >bt or >backtrace can be done also after the program exited abnormally (very useful for pointers problems) print the value of a variable named 'a' >print a or >p a print the value of an expression >p (*p)->m_data return to the calling function. 'up' on the calling stack >u or >up go to the called function. 'down' on the calling stack. >d >down quit gdb >quit when you have a segmentation fault problem, try the following: -------------------------------------------------------------- 1) compile with -g 2) invoke gdb 3) load your executable 4) >run wait for the program to crash start your post-mortal investigation: 5) >bt 6) use up, down and print.