gdb Frequently Asked Questions (FAQ)
1. What is "debugging"Debugging is the process of removing bugs from computer programs. On one end of the spectrum, debugging means staring at your source code until you see the bug. An infinitely more effective method is to use a special program called a "debugger". 2. What is a "debugger"A debugger is a program that runs other programs. A debugger lets the user (programmer) stop running the program at any time and poke around internally. You can examine and change memory contents, call functions, and look at system registers. Besides all these fun things, a debugger can be used to fix your programs. 3. Why use a debugger? Isn't printf/cout/System.out.println good enough?Using a debugger is (generally) the most efficient way to find bugs in your program. Having your program print debugging output is a valid method of finding bugs, and in some cases is the only/easiest way to go. Debuggers show their strength when it comes to common bugs like infinite loops or segmentation faults. You can spin your wheels for hours printing output, where a debugger would point out the problem instantly. 4. What about xdb? Visual Debugger? Where is my GUI?!?Visual debuggers are great. They make debugging much easier. But you won't always have a visual environment to work in. If you learn to use a command-line debugger like gdb, you can use any debugger in existence, visual or not. Furthermore, for some applications special debuggers have been built, and these debuggers are generally command-line only (eg: kdb, the kernel debugger). 5. Finding the line number in my program takes too long!Using pageup/pagedown and the arrow keys is about the least effective way to find a line a number. If you use the emacs text editor (which the author highly recommends), place the following commands in your .emacs file in your home directory.
Now when you press the key sequence (ESC,l), emacs will prompt you for a line number to jump to. Handy, no? 6. Where can I get more information about command x?The GNU infopages for gdb fully document every command. Run info gdb from the shell. Back to Table of Contents |