A “core dumped” error means your program crashed and the system automatically saved its memory state to a file for debugging purposes. This core dump file contains a complete snapshot of your program’s memory, stack, registers, and variables at the exact moment it failed – essentially giving you a forensic record of what went wrong.
🔍 Quick Answer
Core dumps are memory snapshots created when programs crash. They help developers debug issues by preserving the exact state of memory, variables, and execution context at the time of failure. Common triggers include segmentation faults, null pointer access, and buffer overflows.
What Exactly Is a Core Dump?
When your program encounters a fatal error, the operating system captures its entire memory state and writes it to a file called a core dump. Think of it as taking a photograph of your program’s brain at the moment it died.
The core dump contains:
- Memory layout – How your program’s memory was organized
- Variable values – The exact data stored in each variable
- Stack trace – The sequence of function calls leading to the crash
- Register states – CPU register values at crash time
- Heap contents – Dynamically allocated memory
Common Scenarios That Trigger Core Dumps
| Error Type | Signal | Common Cause |
|---|---|---|
| Segmentation Fault | SIGSEGV | Accessing invalid memory address |
| Abort Signal | SIGABRT | Program called abort() or assertion failed |
| Quit Signal | SIGQUIT | User pressed Ctrl+ or kill -QUIT |
| Illegal Instruction | SIGILL | CPU encountered invalid instruction |
Finding Your Core Dump Files
Core dumps don’t always appear in obvious locations. Here’s where to look:
Linux Systems
# Check current working directory first
ls -la core*
# Check system-wide core pattern
cat /proc/sys/kernel/core_pattern
# For systemd systems
coredumpctl list
coredumpctl info <PID>
macOS
# Crash reports location
ls ~/Library/Logs/DiagnosticReports/
ls /Library/Logs/DiagnosticReports/
# Core dumps (if enabled)
ls /cores/
Windows
Windows creates minidumps in %LOCALAPPDATA%CrashDumps or uses Windows Error Reporting.
Enabling Core Dumps
Many systems disable core dumps by default. Here’s how to enable them:
⚠️ Important
Core dumps can contain sensitive information like passwords, API keys, and personal data. Only enable them in secure environments.
Linux Configuration
# Check current limit
ulimit -c
# Enable unlimited core dumps
ulimit -c unlimited
# Make permanent (add to ~/.bashrc or /etc/security/limits.conf)
echo "* soft core unlimited" >> /etc/security/limits.conf
echo "* hard core unlimited" >> /etc/security/limits.conf
# Set core dump location
echo "/tmp/cores/core.%e.%p.%t" > /proc/sys/kernel/core_pattern
Analyzing Core Dumps with GDB
GDB (GNU Debugger) is the most common tool for examining core dumps:
# Load core dump
gdb ./your_program core
# Essential GDB commands for core analysis
(gdb) bt # Show call stack
(gdb) bt full # Show call stack with local variables
(gdb) info registers # Display register values
(gdb) x/10x $sp # Examine stack memory
(gdb) print variable_name # Show variable value
(gdb) list # Show source code around crash
Real Example: Debugging a Segfault
$ gdb ./buggy_program core
(gdb) bt
#0 0x0000000000400567 in main () at segfault.c:8
(gdb) list
3 int main() {
4 char *ptr = NULL;
5 strcpy(ptr, "Hello"); // ← This line caused the crash
6 return 0;
7 }
(gdb) print ptr
$1 = 0x0 <NULL>
Memory Crash Patterns to Recognize
🚨 Null Pointer Dereference
Signature: Program crashes when accessing address 0x0 or very low memory addresses.
char *ptr = NULL;
*ptr = 'A'; // Crash: SIGSEGV at address 0x0
🚨 Buffer Overflow
Signature: Stack corruption, return address overwritten, crash in unexpected location.
char buffer[10];
strcpy(buffer, "This string is way too long"); // Overwrites stack
🚨 Double Free
Signature: Crash in malloc/free functions, heap corruption detected.
char *ptr = malloc(100);
free(ptr);
free(ptr); // Crash: double free detected
Modern Debugging Tools and Alternatives
System-Specific Tools
- Linux:
coredumpctl,crash,gdb - macOS:
lldb, Console.app, Xcode Organizer - Windows: WinDbg, Visual Studio Debugger, ProcDump
Container Environments
Docker containers require special configuration for core dumps:
# Run container with core dump support
docker run --ulimit core=-1 --security-opt seccomp=unconfined your_image
# Or in docker-compose.yml
services:
app:
ulimits:
core: -1
security_opt:
- seccomp=unconfined
Prevention Strategies
🛡️ Compile-Time Protection
# Enable debugging symbols and runtime checks
gcc -g -O0 -fsanitize=address -fsanitize=undefined -Wall -Wextra program.c
# For production builds with some protection
gcc -O2 -D_FORTIFY_SOURCE=2 -fstack-protector-strong program.c
🛡️ Runtime Analysis Tools
- AddressSanitizer (ASan): Detects buffer overflows, use-after-free
- Valgrind: Memory leak detection, bounds checking
- Static analyzers: Clang Static Analyzer, PVS-Studio, Coverity
Troubleshooting Core Dump Issues
❌ Core Dumps Not Being Generated
- Check ulimit:
ulimit -cshould not be 0 - Verify disk space in target directory
- Check permissions on core dump directory
- Ensure the process isn’t setuid/setgid (security restriction)
- Verify kernel.core_pattern setting
❌ Corrupted or Incomplete Dumps
- Insufficient disk space during dump creation
- Process killed before dump completion
- File system limitations (FAT32 has 4GB limit)
Security and Privacy Best Practices
🔒 Security Warning
Core dumps are complete memory snapshots that may contain:
- Passwords and API keys
- User data and personal information
- Cryptographic keys
- Internal system information
Always sanitize dumps before sharing and restrict access in production environments.
Production Environment Guidelines
- Disable core dumps for public-facing services
- Use restricted dump locations with proper permissions
- Implement automatic cleanup of old dump files
- Consider using crash reporting services instead
- Encrypt dumps if they must be stored
Frequently Asked Questions
Why does my program say “core dumped” but I can’t find the file?
This usually happens when core dumps are disabled by system limits. Check ulimit -c and ensure it’s not set to 0. Also verify you have write permissions in the current directory and sufficient disk space.
Can I generate a core dump of a running process?
Yes! Use gcore <PID> on Linux or kill -QUIT <PID> to trigger a dump without killing the process. In GDB, you can use the generate-core-file command.
How large are core dump files?
Core dumps can be as large as your program’s memory usage. A program using 2GB of RAM will create a ~2GB core dump. This is why many systems disable them by default.
Are core dumps created for all programming languages?
Core dumps are an operating system feature, so they work with any compiled language (C, C++, Rust, Go). Interpreted languages like Python or Java may create their own crash reports instead, though the underlying runtime can still generate core dumps.
Can I analyze core dumps from different architectures?
Generally no – you need the same architecture and similar OS version. A core dump from ARM Linux won’t work on x86 Linux. However, some advanced tools support cross-architecture analysis.
How do I clean up old core dumps automatically?
Set up a cron job to remove old dumps:
# Remove core dumps older than 7 days
0 2 * * * find /tmp/cores -name "core.*" -mtime +7 -delete
What’s the difference between core dumps and crash dumps on Windows?
Windows uses “minidumps” (smaller, essential info only) and “full dumps” (complete memory). Core dumps on Unix systems are typically complete memory snapshots, similar to Windows full dumps.