Learning GNU gdb in 5 minutes ============================= by Fabio Kon (f-kon@cs.uiuc.edu) version 0.1 March/27/1996 version 0.2 June/12/1996 1. Running gdb and loading the program to be debugged ===================================================== The best way to use gdb is inside emacs or xemacs. After running emacs, type ESC-x gdb (or M-x gdb is you are on a Sparc machine that usually has the Meta key (it looks like a diamond)). emacs will then display something like "Run gdb on file: ~/" and you should write the pathname of the executable file you wish to debug. This file must have been compiled with the -g option and preferably using GNU gcc. 2. Setting breakpoints ====================== At this point, the executable file is loaded. The first thing you should do is to set one or more breakpoints using the break command: break if is then it sets a breakpoint at --------------- ---------------------------- a function name the fist line of that function a line number that line number in the current source code file omitted the current line in the current file If you are running gdb on emacs you can easily set a breakpoint at any line in any file. Just position the cursor at the line number in which you want to set a break point and press C-x . 3. Running the program ====================== After you have set one or more breakpoints you may run the program by typing: "run " The program will start and run until the next breakpoint is reached. 4. Step, next, and continue =============================== At this time you may use three different commands to trace your program command action ------- ------ step Step program until it reaches a different source line. Argument N means do this N times (or till program stops for another reason) next Step program, proceeding through subroutine calls. Like the "step" command as long as subroutine calls do not happen; when they do, the call is treated as one instruction. continue continue running the program until a new breakpoint is reached or until its end. 5. Examining data ================= The print command prints the contents of a variable or the value of an expression once. It can be of any type, from a single char to a very complex structure. The display command performs like print but prints the value each time the program stops. undisplay stops displaying the expression Examples: -------- print a print *a display 2*a[4]+sizeof(int)+b * c->data 6. Changing data ================ You can update any program variable or memory position by using the set command in the following way. set = or for those who remember what we've learned on our compilation courses: set = The assignment symbol is '=' just because I suppose you will be using C. In Pascal, for example, it must be ':=' 7. Comments, suggestions, and corrections ========================================= Please, send you comments, suggestions, and corrections to Fabio Kon 3231 Digital Computer Lab 1304 West Springfield Ave. Urbana, IL 61801-2987 mailto:f-kon@cs.uiuc.edu http://choices.cs.uiuc.edu/f-kon