Skip to content

Lesson 12 of 13 · 15m

Core Dumps and Post-Mortems

ulimit, core_pattern, and coredumpctl turn a one-time segfault into a replayable debugging session — if you collected it first.

When a process dies on a signal whose default action is "Core" — SIGSEGV, SIGABRT, SIGBUS, SIGFPE, SIGILL, SIGQUIT — the kernel can write its entire address space, registers, and per-thread state to a file. That file plus the binary plus its symbols is everything a debugger needs: the faulting instruction, the stack it ran on, every thread's state at the instant it died. The crash no longer has to be reproducible. The core is the reproduction.

Where the core goes

Two knobs decide whether you get one. ulimit -c is the size cap — set unlimited (or LimitCORE=infinity in a systemd unit). kernel.core_pattern is the destination: a plain path like /var/crash/core.%e.%p writes files directly, while a leading | pipes the dump to a program — which is what systemd hosts do: |/usr/lib/systemd/systemd-coredump ... stores dumps under /var/lib/systemd/coredump/, indexed. coredumpctl list shows the collection, coredumpctl info <pid> the report, coredumpctl debug opens gdb on it. Teams "have no core" for years because nobody checked the journal.

Reading it

gdb -batch -ex 'thread apply all bt' /path/to/binary /var/lib/systemd/coredump/core.*

bt full gives locals, info registers the register file at fault, x/i $pc the instruction. gdb finds debug info via build-id when the distro -dbgsym/-dbg packages are installed — or via debuginfod, which fetches it over HTTP when DEBUGINFOD_URLS points at your distro's server (Ubuntu runs debuginfod.ubuntu.com). A core without symbols is a stack of addresses. Keep .debug files per release — objcopy --only-keep-debug plus --add-gnu-debuglink — so shipped binaries stay small while post-mortems stay possible.

For multi-threaded crashes, gdb opens on the faulting thread; thread apply all bt shows what everyone else held. A core where three threads wait on one mutex while a fourth died tells a different story than the segfault alone.

What's in one

readelf -n core dumps the ELF notes: NT_PRSTATUS per thread (registers and the killing signal — the fault address itself lives in NT_SIGINFO's si_addr, which gdb surfaces as $cr2), NT_AUXV with the auxiliary vector, NT_FILE mapping file-backed regions — which is how gdb knows which libc.so.6 the core's addresses belonged to. The mapped-file table also explains why a core can be smaller than RSS: file-backed pages resolve to the file, not the dump.

Two operational notes that bite people. Cores contain everything the process held — credentials, keys, user data — so they need 0600 permissions and a retention story, not a world-readable /tmp. And privilege-changing binaries refuse to dump by default: fs.suid_dumpable gates it, so a daemon that drops privileges can silently skip dumping unless you set it deliberately. On hosts running apport, crashes land as /var/crash/*.crash instead; apport-retrace unpacks them with symbols, and coredumpctl dump <pid> exports a stored dump for shipping to whoever owns the bug. Traditional-path setups that want per-PID files set kernel.core_uses_pid=1. Either way, test it once with kill -SEGV on a sacrificial process — the collection path that was never exercised is the one that fails during the incident.

From a live process

gcore -o /tmp/core <pid> snapshots a running process without killing it — for the hang, not the crash. eu-stack -p <pid> from elfutils prints every thread's stack in one shot with no debugger session; pstack does the same on older systems. For a wedged service the order matters: eu-stack for the instant picture, gcore for the archive, then restart. Restarting first deletes the evidence.

The practice

  • Enable cores before the crash: LimitCORE=infinity in the unit, a real core_pattern directory, disk budget for the dumps.
  • On systemd hosts, coredumpctl first — the dump is almost always already collected.
  • Keep per-release debug symbols; wire debuginfod where available.
  • For hangs: eu-stack -p, then gcore, then restart — in that order.

Was this lesson helpful?

Sign in to rate

Keep reading

Related articles from the SudoSecurity blog.