catchsegv
Debug segmentation faults in programs
SYNOPSIS
catchsegv command [arguments...]
PARAMETERS
command
The executable program to be run under catchsegv's supervision.
[arguments...]
Any command-line arguments to pass to the specified command.
DESCRIPTION
catchsegv is a utility provided by the GNU C Library (glibc) development packages. Its primary purpose is to help diagnose segmentation faults (SIGSEGV) by intercepting them and printing a symbolic backtrace of the program's execution stack at the time of the fault. Instead of the program simply crashing, catchsegv preloads a special shared library, libSegFault.so, into the target application's address space. This library installs a signal handler for SIGSEGV. When a segmentation fault occurs, this handler is invoked, and it attempts to print a meaningful backtrace, often including function names and line numbers if the program was compiled with debugging symbols. This makes it a quick and convenient tool for developers to get initial insights into where and why a program crashed due to memory access errors, without needing to attach a full-fledged debugger like GDB immediately. It's particularly useful for non-interactive debugging or for quickly identifying the crash location in command-line tools.
CAVEATS
catchsegv is not a full debugger; it only provides a backtrace and does not allow interactive inspection, memory modification, or stepping through code.
It typically requires the installation of glibc development packages to provide libSegFault.so.
It only works with dynamically linked executables, as its mechanism relies on the dynamic linker (LD_PRELOAD).
The quality and detail of the backtrace (e.g., function names, line numbers) depend on whether the target program was compiled with debugging symbols (e.g., with -g flag). Without them, only memory addresses will be shown.
While typically minimal, preloading a library can introduce a slight overhead or alter program behavior in subtle ways.
HOW IT WORKS
Under the hood, catchsegv is typically a shell script wrapper. It sets the LD_PRELOAD environment variable to point to the libSegFault.so shared library (e.g., LD_PRELOAD=/usr/lib/libSegFault.so) before executing the specified command. This instructs the dynamic linker to load libSegFault.so into the process's memory space before any other libraries. libSegFault.so then installs a signal handler for SIGSEGV that, upon detection of a segmentation fault, generates and prints a symbolic backtrace to stderr.
CONFIGURING <I>LIBSEGFAULT.SO</I> VIA ENVIRONMENT VARIABLES
The behavior of the preloaded libSegFault.so can be influenced by several environment variables, though these are not direct catchsegv parameters:
SEGFAULT_OUTPUT_METHOD: Specifies where the backtrace output should go (e.g., STDOUT, STDERR, FILE=<path>, PIPE=<command>). Default is usually STDERR.
SEGFAULT_SIGNAMES: Set to 1 to include signal names in the backtrace output.
SEGFAULT_USE_ALTSTACK: Set to 1 to use an alternative signal stack, which can be useful in cases where the stack might be corrupted.
HISTORY
catchsegv and its underlying shared library, libSegFault.so, are long-standing utilities within the GNU C Library (glibc) ecosystem. They were developed as part of glibc's debugging and diagnostic features to provide developers with a quick way to get actionable information from segmentation faults without requiring a full debugger session. Its exact introduction date into mainline glibc is not widely publicized, but it has been a standard part of glibc development tools for many years, evolving with the library itself.