C Mastery / Core Dumps, Debug Symbols, DWARF
Part 6 — Debugging and Optimization

Core Dumps, Debug Symbols, DWARF

This chapter explains core dumps (post-mortem debugging) and the debug information (DWARF) that makes source-level debugging possible.

Why This Matters

When a program crashes in production, you often cannot run it interactively. A core dump captures the crash state so you can debug it later. DWARF is the format that ties that state back to your source code.

Prerequisites

Core Concept

Core dumps

A core dump is a file containing a snapshot of a process's memory and registers at the moment of a crash. You load it into GDB/LLDB to inspect the crash:

ulimit -c unlimited       # enable core dumps (POSIX)
./app                     # crashes, produces "core"
gdb ./app core

Debug symbols

-g tells the compiler to emit debug info. This does not affect code generation (at -O0); it adds sections mapping addresses to source lines, variables, and types.

DWARF

DWARF is the standard debug format. It stores:

Examples

Inspecting DWARF

readelf --debug-dump=info app   # DWARF info (ELF)
dwarfdump app                   # macOS

Post-mortem debugging

(gdb) bt          # backtrace at crash
(gdb) info locals
(gdb) print x

How It Works

When a fatal signal (e.g., SIGSEGV) arrives, the OS (if core dumps are enabled) writes the process's memory and register state to a core file. GDB loads the executable and core together, using DWARF to reconstruct source context.

Variations

Minidumps (Windows)

Windows uses minidumps instead of Unix core files; the concept is the same.

Separate debug files

Debug info can be stripped into a separate file (.debug/.dSYM) to keep the shipped binary small while retaining debuggability.

Common Mistakes

size, though it can affect inlining decisions at high optimization).

Undefined Behavior

Portability

Clang on most platforms; MSVC uses PDB.

Under the Hood

DWARF is a structured, section-based format. The line table maps every instruction address to a source line. Call frame information lets the debugger unwind the stack even without frame pointers.

Practical Usage

Exercises

1. Enable core dumps, crash a program, and inspect the core with GDB. 2. Use readelf --debug-dump to find the line table and a variable's type. 3. Strip debug info into a separate file and confirm GDB still works.

Deep Challenge

Debug a crash from a core dump where the binary was optimized: reconstruct the backtrace, explain which variables are optimized out, and correlate the crash address to a source line using DWARF.

References

Verification

verified.`

Progress

Concept checkboxes

Mastery levels

ConceptCurrent level (0–8)Target level
c.debug.core06
c.debug.dwarf06