[contents]
[usage]
[execution]
[stack]
[breakpoints]
[watchpoints]
[advanced]
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...?
1.1 How do I compile with debugging symbols? [top]  [toc]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. 1.2 How do I run programs with the debugger? [top]  [toc]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.
1.3 How do I restart a program running in the debugger? [top]  [toc]Use the kill command in gdb to stop execution. The you can use the run command as shown above to start it again.
1.4 How do I exit the debugger? [top]  [toc]Use the quit command.
NOTE: You may be asked if you want to kill the program. Answer yes.
1.5 How do I get help on debugger commands? [top]  [toc]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 rms@unknownroad.com |