1. How do I use gdb?When you compile your program, you must tell the compiler to produce a program that is compatible with the debugger. The debugger needs special information to run properly. To do this, you must compile your program with the debugger flag, -g. This step is critical. Without it, the debugger won't have the program symbol information. That means it won't know what your functions and variables are called, and it won't understand when you ask it about them.
How do I...?
Pass the -g flag to your compiler:
NOTE: If you have a larger program with several files, each must be compiled with the -g flag, and it must also be set when you link.
First start the debugger with your program name as the first argument.
Next use the run command in gdb to start execution. Pass your arguments to this command.
Use the kill command in gdb to stop execution. The you can use the run command as shown above to start it again.
Use the quit command.
NOTE: You may be asked if you want to kill the program. Answer yes.
Use the help command. Gdb has a description for every command it understand, and there are many, many more then this tutorial covers. The argument to help is the command you want information about. If you just type "help" with no arguments, you will get a list of help topics similar to the following:
[contents] [usage] [execution] [stack] [breakpoints] [watchpoints] [advanced]
Questions? Comments? Flames? email firstname.lastname@example.org