Operations 9 min read

Debugging Core Dumps in Embedded Linux with GDB

This guide explains what core dump files are, how to configure foreground and background processes to generate them on embedded Linux, and provides step‑by‑step commands and sample code for enabling core dumps and analyzing them with arm‑linux‑gnueabihf‑gdb.

Liangxu Linux
Liangxu Linux
Liangxu Linux
Debugging Core Dumps in Embedded Linux with GDB

What is a core file?

A core file is a snapshot of a process’s memory taken when the program crashes. It contains the raw memory image and, if available, debugging symbols, allowing post‑mortem analysis with a debugger such as GDB.

Generating core files for foreground processes

Core dump creation is controlled by the ulimit resource limits and the kernel’s core pattern settings.

ulimit -c          # show current core size limit
ulimit -a          # show all limits
ulimit -c 0        # disable core dumps
ulimit -c unlimited # no size limit
ulimit -c 1024     # limit core files to 1024 KB

Configure the file name and location via /proc/sys/kernel/core_uses_pid (add PID) and /proc/sys/kernel/core_pattern (format string). Example:

echo "1" > /proc/sys/kernel/core_uses_pid
echo "/var/core-%e-%p-%t" > /proc/sys/kernel/core_pattern

Place‑holders:

%e – executable name

%p – PID

%t – UNIX timestamp

%u – UID

%g – GID

%s – signal number

%h – hostname

Generating core files for background (daemon) processes

Daemons do not inherit the shell’s ulimit settings, so the program must enable core dumps at runtime. The typical approach is to set RLIMIT_CORE to RLIM_INFINITY and update core_pattern from within the process.

#include <stdio.h>
#include <stdlib.h>
#include <sys/time.h>
#include <sys/resource.h>

#define SHELL_CMD_CONF_CORE_FILE "echo /var/core-%e-%p-%t > /proc/sys/kernel/core_pattern"
#define SHELL_CMD_DEL_CORE_FILE  "rm -f /var/core*"

static int enable_core_dump(void)
{
    struct rlimit rlim;
    rlim.rlim_cur = RLIM_INFINITY;
    rlim.rlim_max = RLIM_INFINITY;
    system(SHELL_CMD_DEL_CORE_FILE);
    if (setrlimit(RLIMIT_CORE, &rlim) != 0) {
        printf("setrlimit error!
");
        return -1;
    }
    system(SHELL_CMD_CONF_CORE_FILE);
    printf("core dump enabled
");
    return 0;
}

int main(int argc, char **argv)
{
    enable_core_dump();
    printf("=== segmentation fault test ===
");
    int *p = NULL;
    *p = 1234; // trigger SIGSEGV
    return 0;
}

To start the daemon at boot, place an init script (e.g., /etc/init.d/S100Test) that runs the binary:

#!/bin/sh
cd /home
./test

Debugging a core file with GDB

Transfer the core file to a host with the appropriate cross‑debugger and load it together with the executable.

arm-linux-gnueabihf-gdb test
core-file core-test-190-119

If the program uses shared libraries, set the library search path inside GDB:

set solib-search-path /home/LinuxZn/lib
info sharedlibrary

Typical reasons for incomplete stack traces

The binary was built without the -g option, so no debug symbols are present.

The libc version on the target differs from the one used by the cross‑compiler, causing symbol mismatches.

Re‑compile with -g and ensure the target’s libc matches the compiler’s libc to obtain meaningful backtraces.

debuggingGDBdaemonCore DumpulimitEmbedded Linux
Liangxu Linux
Written by

Liangxu Linux

Liangxu, a self‑taught IT professional now working as a Linux development engineer at a Fortune 500 multinational, shares extensive Linux knowledge—fundamentals, applications, tools, plus Git, databases, Raspberry Pi, etc. (Reply “Linux” to receive essential resources.)

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.