Fundamentals 4 min read

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.

ITPUB
ITPUB
ITPUB
Locate Segmentation Faults Quickly with Core Dumps and GDB

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.

Core dump concept illustration
Core dump concept illustration
Program output with segmentation fault
Program output with segmentation fault
GDB analysis of core file
GDB analysis of core file

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.

GDBCore Dumpsegmentation faultlinux debugging
ITPUB
Written by

ITPUB

Official ITPUB account sharing technical insights, community news, and exciting events.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.