Debugging Fundamentals
Debugging C is an art. Let’s master the tools that make you dangerous.GDB Essentials
Starting GDB
Basic Commands
Advanced GDB
GDB Init File
Core Dumps
Enabling Core Dumps
Analyzing Core Dumps
Triggering Core Dumps
Memory Debugging
Valgrind
Understanding Valgrind Output
AddressSanitizer
Common Memory Errors
Debugging Patterns
Printf Debugging (But Better)
Assertions
Memory Debugging Wrapper
Tracing System Calls
ltrace (Library Calls)
Debugging Crashes Systematically
Reproduce Consistently
Find the minimal input/steps to trigger the crash. Randomness = harder debugging.
Find the Root Cause
The crash site is often not the bug. Trace backwards—when did state become invalid?
Exercises
GDB Mastery
Write a program with a linked list. Use GDB to traverse the list, print node values, and find a bug you intentionally introduce.
Core Dump Analysis
Write a program that crashes. Generate a core dump and analyze it to find the crash location.
Memory Bug Hunt
Write a program with at least 3 different memory bugs. Use Valgrind and AddressSanitizer to find them all.
Next Up
Pointers Deep Dive
Master the heart of C programming