Starting GDB
In this recipe, we'll learn the basics of GDB, the GNU debugger. We'll learn how to start GDB, how to set a breakpoint, and how to step forward in a program, one step at a time. We'll also learn what debugging symbols are and how we enable them.
GDB is the most popular debugger for Linux and other Unix-like systems. It allows you to examine—and change—variables on the fly, step through instructions one at a time, view the code as the program is running, read return values, and much more.
Knowing how to use a debugger can save you many hours of frustration. Instead of guessing what the problem is with your program, you can follow the execution with GDB and spot the error. This can save you a lot of time.
Getting ready
For this recipe, you'll need the GCC compiler, the Make tool, and the GDB tool. For installation instructions for GDB, see the Technical requirements section of this chapter.
How to do it…
In this...