Chapter 12: Debugging Your Programs
No program is perfect on the first try. In this chapter, we'll learn how to debug our programs using GDB and Valgrind. With the latter tool, Valgrind, we can find memory leaks in our programs.
We'll also take a look at what memory leaks are, what they can cause, and how to prevent them. Debugging programs and looking at memory is an important step to understanding system programming fully.
In this chapter, we will cover the following recipes:
- Starting GDB
- Stepping inside functions with GDB
- Investigating memory with GDB
- Modifying variables during runtime
- Using GDB on a program that forks
- Debugging programs with multiple threads
- Finding a simple memory leak with Valgrind
- Finding buffer overflows with Valgrind