Core Dumps
Chapter 89: Core Dump Analysis
Section titled βChapter 89: Core Dump AnalysisβOverview
Section titled βOverviewβCore dumps are memory snapshots of crashed processes that are invaluable for debugging production issues. When a process crashes unexpectedly, a core dump captures the entire state of the process at the time of the crash, including stack traces, variable values, and memory contents. This chapter covers enabling core dumps, analyzing them with gdb and other tools, kernel core dumps, and production best practices.
Why This Matters in DevOps/SRE
Section titled βWhy This Matters in DevOps/SREβCore dumps are essential for production debugging:
- Post-Mortem Analysis: Understand why applications crash
- Debugging: Use gdb to analyze crash state
- Root Cause: Find the exact line and variables at crash time
- Support: Vendors often need core dumps to help
- Prevention: Use crash data to fix bugs proactively
Core dump analysis is a critical skill for SREs handling production incidents.
89.1 Enabling Core Dumps
Section titled β89.1 Enabling Core DumpsβCore Dump Fundamentals
Section titled βCore Dump Fundamentalsβββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ CORE DUMP BASICS ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€β ββ What is a Core Dump? ββ βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ ββ β β ββ β A core dump is a file containing: β ββ β - Complete memory image of the process β ββ β - CPU register values at time of crash β ββ β - Stack traces for all threads β ββ β - Information about loaded libraries β ββ β - Process metadata (PID, user, etc.) β ββ β β ββ β Generated when process: β ββ β - Crashes with signal (SIGSEGV, SIGABRT, etc.) β ββ β - Receives signal with core action β ββ β - Calls abort() β ββ β β ββ βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ ββ ββ Core Dump Types: ββ βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ ββ β β ββ β 1. Core Dump (traditional) β ββ β - Single file, process memory only β ββ β β ββ β 2. Kernel Core Dump (vmcore) β ββ β - Entire kernel memory + processes β ββ β - Used for kernel crashes β ββ β β ββ β 3. Core Dump with Abbrev (gcore) β ββ β - Can attach to running process β ββ β β ββ βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ ββ ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββSystem Configuration
Section titled βSystem Configurationβ# ============================================================# ENABLING CORE DUMPS - SYSTEM CONFIGURATION# ============================================================
# /etc/security/limits.conf# Set core dump size limits for all users* soft core unlimited* hard core unlimitedroot soft core unlimitedroot hard core unlimited
# /etc/sysctl.conf - Kernel settings# Core pattern (where to save, what name)kernel.core_pattern = core.%p # %p = process IDkernel.core_uses_pid = 1 # Include PID in name
# Alternative patterns:# core.%e.%p - executable name + PID# core.%t - timestamp# core.%h - hostname
# Enable compressed core dumpskernel.core_compress_press = 1
# Set core dump size limit (0 = disabled)kernel.core_limit = 0 # 0 = unlimited in modern kernels
# Apply without rebootsudo sysctl -p
# Check current settingssysctl kernel.core_patternsysctl kernel.core_uses_pid
# System-wide ulimit (systemd)# /etc/systemd/system.confDefaultLimitCORE=infinityProcess Level Configuration
Section titled βProcess Level Configurationβ# ============================================================# PROCESS-LEVEL CORE DUMP CONFIGURATION# ============================================================
# In shell - enable for current sessionulimit -c unlimited
# In shell script#!/bin/bashulimit -c unlimited./my_program
# In Pythonimport resourcesoft, hard = resource.getrlimit(resource.RLIMIT_CORE)resource.setrlimit(resource.RLIMIT_CORE, (hard, hard))
# In C/C++ program#include <sys/resource.h>
struct rlimit rlim;rlim.rlim_cur = RLIM_INFINITY;rlim.rlim_max = RLIM_INFINITY;setrlimit(RLIMIT_CORE, &rlim);
# Using prctl (Linux-specific)#include <sys/prctl.h>prctl(PR_SET_COREFILE, PR_SET_COREFILE_LARGE);
# Disable core dumps for sensitive processesprctl(PR_SET_DUMPABLE, 0);
# Check if core dumps are enabled for a processcat /proc/<PID>/limits | grep "Max core file size"Application Configuration
Section titled βApplication Configurationβ# ============================================================# APPLICATION CORE DUMP CONFIGURATION# ============================================================
# For system services (systemd)# /etc/systemd/system/myapp.service[Service]LimitCORE=infinityWorkingDirectory=/path/to/appEnvironment="MALLOC_CHECK_=3" # Debug malloc issues
# For nginx# /etc/nginx/nginx.confworker_rlimit_core 100M;working_directory /var/crash;
# For PostgreSQL# postgresql.confkernel.core_pattern = /var/lib/postgresql/%u/core.%ppostgresql.conf: kernel.core_pattern
# For Java applications# Heap dumps vs core dumps# -XX:+HeapDumpOnOutOfMemoryError# -XX:HeapDumpPath=/var/log/heapdump.hprof
# For Python# ulimit must be set before starting# Or use: faulthandler modulepython -c "import faulthandler; faulthandler.enable()"89.2 Analyzing Core Dumps
Section titled β89.2 Analyzing Core DumpsβUsing GDB
Section titled βUsing GDBβ# ============================================================# ANALYZING CORE DUMPS WITH GDB# ============================================================
# Load core dump with executablegdb ./program core.1234
# Or specify both separatelygdb -c core.1234 ./program
# Essential GDB Commands:
# Backtracebt # Quick backtracebt full # Backtrace with local variablesbt 20 # Show 20 framesthread apply all bt # All threads
# Frame navigationframe 3 # Switch to frame 3up 2 # Go up 2 framesdown 1 # Go down 1 frameinfo frame # Current frame info
# Variables and memoryprint variable_nameprint *pointerprint array[0]@10 # Print 10 elementsx/100x &buffer # Examine 100 words hexx/s &string # Examine stringx/i &function # Examine at address
# Registersinfo registersinfo all-registers
# Threadsinfo threadsthread apply all btthread 2bt
# Source codelist # Show source around PClist function_namelist 10,20 # Lines 10-20
# Breakpointsinfo breakpointsdelete 1
# Continuing after crash (for debugging)set disassemble-next-line onrun
# Useful commandsinfo signals # Signal handlinginfo proc # Process infoinfo files # Loaded filesPractical Analysis Examples
Section titled βPractical Analysis Examplesβ# ============================================================# PRACTICAL CORE DUMP ANALYSIS# ============================================================
# Example: Debugging a crashgdb ./myapp core.5678
# 1. Quick overview(gdb) bt#0 0x00007f8a12345678 in ?? () from /lib/x86_64-linux-gnu/libc.so.6
# 2. Find the crash location(gdb) info registers rip#rip 0x555555554a2a <main+42>
# 3. Examine variables at crash(gdb) info locals#i = 10#buffer = 0x0
# 4. Check the backtrace fully(gdb) bt full
# 5. Find null pointer(gdb) print buffer#$1 = 0x0
# 6. Go up to see where buffer was set(gdb) up(gdb) list
# Common crash patterns:
# Null pointer dereference# Program received signal SIGSEGV, Segmentation fault.# 0x0000000000000000 in ?? ()
# Buffer overflow# Program received signal SIGABRT, Aborted.# __GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:50
# Double free# *** glibc detected *** ./program: double free or corruption
# Use after free# Invalid free() / delete / delete[]
# Stack overflow# Program received signal SIGSEGV, Segmentation fault.# 0x00007f8a1c00000 in ?? ()Using crash Utility
Section titled βUsing crash Utilityβ# ============================================================# ANALYZING KERNEL CORE DUMPS WITH CRASH# ============================================================
# Install crash and kernel debug infosudo apt install crashsudo debuginfo-install kernel
# Analyze kernel crash dumpsudo crash vmlinux /var/crash/vmcore
# Common crash commands:crash> ps # List processescrash> bt # Backtracecrash> bt -a # All CPU backtracescrash> kmem -i # Memory infocrash> log # Kernel log buffercrash> files # Open filescrash> net # Network socketscrash> waitq # Wait queuescrash> struct task_struct # Task structurecrash> p <PID> # Process details
# Analyze specificcrash> ps | grep <name> # Find processcrash> rd <address> 20 # Read 20 longs from addrcrash> dis <address> # Disassemble
# Extensionscrash> mod # Kernel modulescrash> irq # IRQ handlers89.3 Production Best Practices
Section titled β89.3 Production Best PracticesβConfiguration Checklist
Section titled βConfiguration Checklistβ# ============================================================# PRODUCTION CORE DUMP CONFIGURATION CHECKLIST# ============================================================
# 1. System Configuration# Enable core dumps system-wide# /etc/security/limits.conf* soft core unlimited* hard core unlimited
# /etc/sysctl.confkernel.core_pattern = /var/crash/core.%e.%p.%tkernel.core_uses_pid = 1
# 2. Storage Locationmkdir -p /var/crashchmod 1777 /var/crash
# 3. Log Rotation# /etc/logrotate.d/core dumps/var/crash/core.* { daily rotate 5 compress delaycompress missingok notifempty}
# 4. Application Configuration# Set ulimit in systemd service[Service]LimitCORE=infinity
# 5. Monitoring# Alert if core dumps appearfind /var/crash -type f -mtime -1 -ls
# 6. Security# Restrict core dump location permissions# Prevent information disclosureCore Dump Analysis Workflow
Section titled βCore Dump Analysis Workflowβββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ CORE DUMP ANALYSIS WORKFLOW ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€β ββ βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ ββ β Step 1: Collect β ββ β - Locate core dump file β ββ β - Get matching binary/executable β ββ β - Gather related logs β ββ βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ ββ β ββ βΌ ββ βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ ββ β Step 2: Initial Analysis β ββ β - Load in gdb: gdb ./program core β ββ β - Get backtrace: bt β ββ β - Identify crash location β ββ βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ ββ β ββ βΌ ββ βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ ββ β Step 3: Deep Dive β ββ β - Examine variables β ββ β - Check register values β ββ β - Analyze call chain β ββ β - Identify root cause β ββ βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ ββ β ββ βΌ ββ βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ ββ β Step 4: Fix and Prevent β ββ β - Implement fix β ββ β - Add tests β ββ β - Add monitoring β ββ β - Update code β ββ βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ ββ ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ89.4 Interview Questions
Section titled β89.4 Interview Questionsβββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ CORE DUMP INTERVIEW QUESTIONS ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€ βQ1: What is a core dump? β βA1: βA core dump is a file containing: β- Complete memory snapshot of a process at crash time β- CPU register values β- Stack traces for all threads β- Information about loaded shared libraries β- Used for post-mortem debugging of crashes β βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€ βQ2: How do you enable core dumps in Linux? β βA2: β1. System: /etc/security/limits.conf - set core unlimited β2. Kernel: sysctl kernel.core_pattern β3. Process: ulimit -c unlimited in shell β4. Program: setrlimit(RLIMIT_CORE, ...) in code β5. Systemd: LimitCORE=infinity in service file β βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€ βQ3: What does kernel.core_pattern mean? β βA3: βDefines where and how core dumps are saved: β- %p = PID β- %e = executable name β- %t = timestamp β- %h = hostname β- /var/crash/ = directory (if starts with /) β βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€ βQ4: How do you analyze a core dump with gdb? β βA4: βgdb ./program core.1234 β- bt: backtrace β- bt full: backtrace with local variables β- frame N: switch to frame N β- print var: print variable β- x/100x addr: examine memory β- info registers: register values β- thread apply all bt: all threads β βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€ βQ5: What are the differences between process and kernel core dumps? β βA5: β- Process core dump: Single process memory only β- Kernel core dump (vmcore): Entire kernel memory + all processes β- Kernel dumps need special tools (crash, kdump) β- Kernel crashes handled by kdump/kexec β βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€ βQ6: How do you prevent core dumps in production for security? β βA6: β- Set core dump size to 0 β- Use prctl(PR_SET_DUMPABLE, 0) for sensitive processes β- Store core dumps in secure location with restricted permissions β- Consider coredumpctl with systemd β- Avoid including sensitive data in core dumps β βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€ βQ7: What is the difference between gcore and gdb -c? β βA7: β- gdb -c: Analyzes existing core dump β- gcore: Creates core dump of running process β- gcore <PID>: Generate core without killing process β- Useful for debugging live processes or hung programs β βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€ βQ8: How do you debug a core dump without debug symbols? β βA8: β- Rebuild with debug symbols (-g flag) β- Use separate debug symbol packages β- Install debuginfo packages (Fedora/RHEL) β- Use objdump for basic analysis β- Function names may be missing but addresses still useful β βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€ βQ9: What is systemd-coredump and how does it work? β βA9: β- systemd-coredump is systemd's core dump handling β- Catches core dumps via kernel.core_pattern β- Stores in /var/lib/systemd/coredump/ β- Uses coredumpctl to list and extract β- Can limit size, compress, store metadata β- Configure in /etc/systemd/coredump.conf β βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€ βQ10: How do you debug multi-threaded core dumps? β βA10: β- thread apply all bt: backtrace for all threads β- info threads: list all threads β- thread N: switch to thread N β- Use bt full to see all thread-local variables β- Look for deadlock patterns in backtraces β- Check which thread received signal β ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββQuick Reference
Section titled βQuick Referenceβ# Enable core dumpsulimit -c unlimitedsysctl kernel.core_pattern=/var/crash/core.%p
# Generate core dump of running processgcore <PID>
# Analyze core dumpgdb ./program core.1234
# Common gdb commandsbt # Backtracebt full # Full backtraceframe N # Switch frameprint var # Print variablex/100x &buffer # Examine memory
# Kernel crash analysissudo crash vmlinux vmcorecrash> btcrash> ps
# List core dumpscoredumpctl listCommon Mistakes & Anti-Patterns
Section titled βCommon Mistakes & Anti-Patternsβ1. Not Enabling Core Dumps
Section titled β1. Not Enabling Core DumpsβWRONG:
# Assuming core dumps are enabled by defaultulimit -c # Shows unlimited but still no coreCORRECT:
# Enable at shell levelulimit -c unlimited
# Enable system-widesysctl -w kernel.core_pattern=/tmp/core-%e-%psysctl -w kernel.core_uses_pid=1
# Enable for systemd services systemctl edit nginx # Add: # [Service] # LimitCORE=infinityWhy: Many systems have core dumps disabled by default.
2. Core Dumps in Wrong Location
Section titled β2. Core Dumps in Wrong LocationβWRONG:
# Default location may be inaccessiblekernel.core_pattern = core # Writes to cwd, may not be accessibleCORRECT:
# Use absolute pathsysctl -w kernel.core_pattern=/var/crash/core-%e-%p-%t
# Ensure directory exists and has permissionsmkdir -p /var/crashchmod 1777 /var/crashWhy: Core dumps need a accessible location with enough space.
3. Not Stripping Debug Symbols
Section titled β3. Not Stripping Debug SymbolsβWRONG:
# Analyzing without debug symbolsgdb /usr/sbin/nginx core-file# Hard to read stack tracesCORRECT:
# Install debug symbolsdebuginfo-install nginx# Or compile with -g flag
# In gdb, usegdb -ex "set print pretty on" /usr/sbin/nginx core-filebt fullWhy: Debug symbols make analysis much more useful.
4. Storing Huge Core Dumps
Section titled β4. Storing Huge Core DumpsβWRONG:
# No size limits on core dumps# Fill up disk with multiple huge core dumpsCORRECT:
# Limit core dump sizeulimit -c 1048576 # 1GB max
# Use systemd systemctl edit nginx # [Service] # LimitCORE=1073741824
# Clean up old coresfind /var/crash -name "core*" -mtime +30 -deleteWhy: Core dumps can be very large and fill disk.
5. Not Using ABRT or systemd-coredump
Section titled β5. Not Using ABRT or systemd-coredumpβWRONG:
# Manual core dump handlingsysctl kernel.core_pattern=core# Missing many featuresCORRECT:
# Use systemd-coredumpsystemctl enable systemd-coredumpsystemctl start systemd-coredump
# Configure in /etc/systemd/coredump.conf[Coredump]ProcessSizeMax=2GStorage=persistentWhy: Provides better management and cleanup.
Summary
Section titled βSummaryβ- Core Dump: Memory snapshot of crashed process
- Enable: ulimit, sysctl, systemd service configuration
- Analyze: gdb for user space, crash for kernel
- Commands: bt, print, x/, frame, thread
- Production: Configure storage, rotation, security
Next Chapter
Section titled βNext ChapterβChapter 90: Hardware Diagnostics
Last Updated: February 2026