Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Saving core file in gdb

Tags:

gdb

core-file

Is it possible to save/dump core file using gdb? Sometimes I want to save file to analyze it later.

like image 340
Maciej Piechotka Avatar asked Sep 24 '10 17:09

Maciej Piechotka


People also ask

What is core file in gdb?

What is a core file? A core file is an image of a process that has crashed It contains all process information pertinent to debugging: contents of hardware registers, process status, and process data. Gdb will allow you use this file to determine where your program crashed.

Where are core dumps stored?

By default, all core dumps are stored in /var/lib/systemd/coredump (due to Storage=external ) and they are compressed with zstd (due to Compress=yes ). Additionally, various size limits for the storage can be configured. Note: The default value for kernel. core_pattern is set in /usr/lib/sysctl.

What is in a core file?

A . core file is created in the current directory when various errors occur. Errors such as memory-address violations, illegal instructions, bus errors, and user-generated quit signals, commonly cause this core dump. The core file that is created contains a memory image of the terminated process.


2 Answers

Issue the 'generate-core-file' command in gdb.

(gdb) help generate-core-file Save a core file with the current state of the debugged process. Argument is optional filename.  Default filename is 'core.<process_id>'. (gdb) break main Breakpoint 1 at 0x400e0b: file utils/udec.c, line 36. (gdb) r Starting program: /home/nos/build/utils/udec  Breakpoint 1, main (argc=1, argv=0x7fffffffe9a8) at utils/udec.c:36 36              int fileargc = 1; (gdb) generate-core-file Saved corefile core.7336 
like image 95
nos Avatar answered Oct 06 '22 07:10

nos


You can also use gcore <pid> to produce cores.

like image 26
Meinew Avatar answered Oct 06 '22 09:10

Meinew