Locate Segmentation Faults Quickly with Core Dumps and GDB
This guide explains what core dumps are, how to enable their generation on Linux, where the core file is created, and step‑by‑step usage of GDB to pinpoint the exact location of a segmentation fault in C programs.
What is a core dump?
A core dump is a snapshot of a program's memory at the moment it crashes, allowing developers to examine the state of the process.
Why a core file may not be generated
Many Linux systems disable core file creation by default or limit its size to zero. To enable core dumps, run the following command: ulimit -c unlimited After this, when a program crashes, a file named core will be written in the program's working directory (on Ubuntu the default name is simply core).
Understanding the core file
The core file contains a binary memory image of the crashed process, optionally with debugging symbols, and is primarily used for debugging.
Debugging the core file with GDB
Use the GNU Debugger (GDB) to analyze the core file: gdb /path/to/executable core GDB will load the executable and the core dump, showing where the segmentation fault occurred. The following screenshots illustrate the program output, the missing core file on the first run, and the GDB analysis pinpointing the fault location.
By following these steps, developers can quickly locate the exact line of code causing the segmentation fault and resolve the issue, reducing the frustration of cryptic "segmentation fault" messages.
ITPUB
Official ITPUB account sharing technical insights, community news, and exciting events.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
