Debugging using xxgdb and gdb for C programs xxgdb is an X-windows interface to gdb, which is a debugger for C programs. A debugger allows you to determine the state of your code at any point in the execution of your program. It is very useful in catching runtime errors. Further documentation: Use the man utility and look up gdb and xxgdb. Step 1 ------ Are you on an X capable machine? (e.g. a Sun station, an Alpha, a PC running Linux, etc.) If the answer is yes, then you can use xxgdb. Goto step 2. If the answer is no, then you must use gdb. Goto directly to step 3. (You would answer no if you were connected over a modem.) Step 2 ------ Determine which machine you are running on. At the command line prompt, type in: finger Then look for a line that has your student login name. The "Where" field will tell you the name of your host machine. For example, my login name is haynes. So, admiral% finger Login Name TTY Idle When Where root Super-User console 23: Sat 14:25 s1014363 DANG pts/5 3:08 Sun 10:20 umslts1_12.umsl.edu s1014363 DANG pts/6 2:47 Sun 10:39 umslts1_12.umsl.edu jja JOHN ANTOGNOLI pts/2 1d Fri 16:53 persephone.cs.umsl.e s986287 WILLIAMSON pts/7 Sun 12:36 umslts1.umsl.edu s970059 DARDEN pts/24 Sun 13:15 cisco2_9.umsl.edu s993234 BROWN pts/19 7 Sun 12:21 sol12.umsl.edu s993234 BROWN pts/11 7 Sun 12:11 sol12.umsl.edu haynes HAYNES pts/23 20 Sun 13:00 agni.cs.umsl.edu s999262 PATEL pts/29 6 Sun 13:21 sol17.umsl.edu At this time, I am logged in from agni.cs.umsl.edu. Notice that user s1014363 is logged in twice. It just happens that it is from the same machine. It is possible to login from different machines, but only be working on one machine. For example, from agni, I can log into arch, and from there I can log into admiral. admiral% finger | grep haynes haynes HAYNES pts/23 7 Sun 13:00 agni.cs.umsl.edu haynes HAYNES pts/26 Sun 13:39 arch.umsl.edu You must be able to determine the host name of the machine you are working on. So if you are logged in two or more times, from different machines, log out of each account and log in once from your machine. (If you are sure of your host, you may not need to do this.) Notice that I was able to narrow down the results from finger by screening out lines with the grep command. You can substitute your name in the command above. You might want to do this if there are a bunch of people logged in. Also, you could see a page of output at a time by using the more command, e.g. finger | more. Finally, with the host name in hand, you will need to set the environment variable DISPLAY on admiral. You do this by using setenv: admiral% setenv DISPLAY "agni.cs.umsl.edu:0.0" Possible problems: Even if you do all this, you might need to enable remote machines having access to your display. You can do this by issuing the command xhost from your host machine, e.g. agni% xhost + Further documentation: Use the man utility and look up csh, finger, grep, and more, e.g. admiral% man more Exercise: You could write a shell script that set your display. Look at the utility sed. Step 3 ------ Compiling your code. You must inform gcc that you are going to use a debugger. To do this, use the -g switch. admiral% gcc -g prog1.c -o prog (The -o switch renames the output of gcc. If you do not use it, the output file name of the executable will be a.out.) Step 4 ------ Setting up the debugger. There are certain commands that you will be issuing to the debugger every time you start it up. gdb allows you to store these commands in a file and have them executed at the start. You can copy the example commands below into a file and use them for debugging your code. exec-file style symbol-file style set args echo3 dir . set print pretty on set print union on b main Both exec-file and symbol-file must point to the name of your target executable file. Using the example from Step 3: exec-file prog1 symbol-file prog1 The command set args is used to initialize your command line arguments. Finally, the command b sets a breakpoint, which is a line of code for which you want to pause the execution of your program so you can examine its state. The example command will cause the debugger to stop at the beginning of the main function. You can add as many b commands as you want. For example, if there are functions foo and bar, then I can have the lines: b main b foo b bar Step 5 ------ Executing the debugger. Assuming that you stored your startup commands in a file called prog1.gdb and you wish to debug your code. If you are using xxgdb, invoke it with the -x option to read in the startup file. admiral% xxgdb -x prog1.gdb If you are using gdb, also invoke it with the -x option to read in the startup file. admiral% gdb -x prog1.gdb Step 6 ------ RTFM: Read the man pages for further information.