====== GDB Debugging Tutorial ====== ===== Objective(s) ===== Create a tutorial explaining the use of the GDB debugger. It's always good to have a little help and that's exactly what the GDB debugger does. With the GDB you can step through every line of code so you can see exactly what's happening in your C++ programs. Definitely helps when you've got buggy code and you're totally unsure as to why. ===== Materials/Reading/Prerequisites ===== [[http://linux.die.net/man/1/gdb|GDB Man Page]] [[http://www.csd.uoc.gr/~hy255/refcards/gdb-refcard.pdf|GDB Cheat Sheet]] [[http://en.wikipedia.org/wiki/GDB|GDB Wikipedia Page]] ===== Background ===== The GDB Debugger is an incredibly powerful tool for a C programmer. There's nothing more annoying for a programmer to have a logic error that they can't track down. GDB makes it much easier to be able to track down these logic errors by giving the programmer the ability to look at their code, step through it line by line, set stopping points in the code, the ability to print the contents of variables, and much more. ===== Procedure ===== An easy way to get started is to create a C program, a simple hello world would be fine. Anytime you want to use GDB, you'll need to compile with debugging options. To compile a program with debugging options, enter the following in the terminal lab46~:$/ gcc -g myProg.c -o myProg lab46~:$/ gdb myProg Now that gdb is running you can enter "help" into the prompt for a list of options. I would start by entering "help running". This will give some information on running a debugged program inside of gdb. "help breakpoints" is also a good place to start. This will contain some information on setting stopping points within the code. ===== References ===== [[http://gcc.gnu.org/onlinedocs/gcc-4.4.2/gnat_ugn_unw/Introduction-to-GDB-Commands.html|Starter GDB Commands]] GDB Pocket Reference - O'Reilly