- So lets see, we've invoked gdb, then typed:
(gdb break main
(gdb)run "hello, world" "goodbye, world"
- Then the debugger gave something like the following:
Starting program: /mnt/usb/home/ozdogan/cfiles/debugme "hello,world" "goodbye, world"
Breakpoint 1, main (argc=3, argv=0xbffff054) at debugme.c:16
16 if (argc < 2) { /* 2 - 1 for program name (argv[0]) and one for a param. */
(gdb)
Now we want to start running the program slowly, step by step. There are two options for that:
- "next" - causes the debugger to execute the current command, and stop again, showing the next command in the code to be executed.
- "step" - causes the debugger to execute the current command, and if it is a function call - break at the beginning of that function. This is useful for debugging nested code.
- Now is your time to experiment with these options with our debug program, and see how they work. It is also useful to read the debuggers help, using the command "help break" and "help breakpoints" to learn how to set several breakpoints, how to see what breakpoints are set, how to delete breakpoints, and how to apply conditions to breakpoints (i.e. make them stop the program only if a certain expression evaluates to ``true'' when the breakpoint is reached).
Cem Ozdogan
2011-02-14