4. How do I use breakpoints?
Breakpoints are a way of telling gdb that you want it to stop your program at certain lines of code. You can also have it stop when your program makes specific function calls. Once the program is stopped, you can poke around in memory and see what the values of all your variables are, examine the stack, and step through your program's execution.
How do I ...?
The command to set a breakpoint is break. If you only have one source file, you can set a breakpoint like so:
If you have more than one file, you must give the break command a filename as well:
To set a breakpoint on a C function, pass it's name to break.
Setting a breakpoint on a C++ function is similar to setting a breakpoint on a C function. However C++ is polymorphic, so you must tell break which version of the function you want to break on (even if there is only one). To do this, you tell it the list of argument types.
Use the tbreak command instead of break. A temporary breakpoint only stops the program once, and is then removed.
Use the info breakpoints command.
Use the disable command. Pass the number of the breakpoint you wish to disable as an argument to this command. You can find the breakpoint number in the list of breakpoints, as shown above. In the example below we can see that breakpoint number 2 has been disabled (there is an 'n' under the Enb column).
To skip a breakpoint a certain number of times, we use the ignore command. The ignore command takes two arguments: the breakpoint number to skip, and the number of times to skip it.
[contents] [usage] [execution] [stack] [breakpoints] [watchpoints] [advanced]
Questions? Comments? Flames? email firstname.lastname@example.org