Debug a crashed application
Sometimes, it is not possible to debug an application directly. In these situations, you can collect information about the application at the moment of its termination and analyze it afterwards.
Core dumps: what they are and how to use them Copy linkLink copied!
A core dump records parts of an application’s memory when the application stops. After an application fails, you can analyze the core dump, along with the executable and debuginfo, by using a debugger.
The Linux operating system kernel can record core dumps automatically, if this functionality is enabled. Alternatively, send a signal to any running application to generate a core dump regardless of its actual state.
Some limits might affect the ability to generate a core dump. To see the current limits:
$ ulimit -a
Record application crashes with core dumps Copy linkLink copied!
To record application crashes, configure core dump saving and add information about the system.
Procedure Copy linkLink copied!
Inspect application crash states with core dumps Copy linkLink copied!
To inspect the state of an application at the moment it terminated unexpectedly, use core dumps.
Before you begin Copy linkLink copied!
- You must have a core dump file and sosreport from the system where the crash occurred.
- GDB and elfutils must be installed on your system.
Procedure Copy linkLink copied!
Create and access a core dump with coredumpctl Copy linkLink copied!
To manage and analyze core dumps directly on the affected system, use coredumpctl. This tool simplifies finding, capturing, and inspecting crash data. Identify an unresponsive process, force a core dump, and verify its successful capture to diagnose application failures.
Before you begin Copy linkLink copied!
- The system must be configured to use
systemd-coredumpfor core dump handling. To verify this is true:$ sysctl kernel.core_patternThe configuration is correct if the output starts with the following:
kernel.core_pattern = |/usr/lib/systemd/systemd-coredump
Procedure Copy linkLink copied!
Dump process memory with gcore Copy linkLink copied!
To capture the memory state of a running process without terminating it, use the gcore utility. This creates a core dump file for offline analysis. The result is a snapshot of the application’s memory that helps you investigate issues while the service remains available.
Before you begin Copy linkLink copied!
- You must understand what core dumps are and how they are created. For details, see Core dumps: what they are and how to use them.
- GDB must be installed on the system. For details, see Installing tools for debugging applications.
.Procedure
- Identify the process id (pid). Use tools such as
ps,pgrep, andtop:$ ps -C some-program - Dump the memory of this process:
$ gcore -o filenamepidThis creates a file filename and dumps the process memory in it. While the memory is being dumped, the execution of the process is halted.
- After the core dump is finished, the process resumes normal execution.
- Create an SOS report to provide additional information about the system:
# sosreportThis creates a tar archive containing information about your system, such as copies of configuration files.
- Transfer the program’s executable file, core dump, and the SOS report to the computer where the debugging will take place.
- Optional: Remove the core dump and SOS report after transferring them, to free up disk space.
- Identify the process id (pid). Use tools such as
Dump protected process memory with GDB Copy linkLink copied!
To dump protected process memory, configure GNU Debugger (GDB) to ignore core dump filters. Capture memory regions flagged as non-dumpable, such as those conserving resources or holding sensitive data. Use the gcore command within GDB to generate the complete core file.
Before you begin Copy linkLink copied!
- You must understand what core dumps are. For details, see Core dumps: what they are and how to use them.
- GDB must be installed on the system. For details, see Installing tools for debugging applications.
- GDB must be already attached to the process with protected memory. For details, see Attaching GDB to a process.
.Procedure
- Set GDB to ignore the settings in the
/proc/PID/coredump_filterfile:(gdb) set use-coredump-filter off - Set GDB to ignore the memory page flag
VM_DONTDUMP:(gdb) set dump-excluded-mappings on - Dump the memory:
(gdb) gcore core-fileReplace core-file with name of file where you want to dump the memory.
- Set GDB to ignore the settings in the