How to use a core dump file in Linux?

If a program that crashes leaves a core dump, you can use GDB to obtain a stack trace. Core dumps are saved in a file on your hard disk and are usually named something along the lines of “core” or “core.1234″. To obtain a stack trace from one of these files, run the following command:

$ sudo gdb program core.1234

We use sudo here to make sure we have read access to both files. Once GDB has loaded up, we can run the “bt” command to display stack trace of the program. Here is an example,

(gdb) bt
#0 0x40c8b6ec in s7_listen () from /usr/lib/
#1 0x40c8be4e in DlgcHost_GcSS7::s7_Listen () from /usr/lib/
#2 0x40278255 in gc_Listen () at eval.c:41
#3 0x08049ac1 in route () at eval.c:41
#4 0x0804986a in main () at eval.c:41
#5 0x402c9507 in __libc_start_main (main=0x8049220 , argc=2, ubp_av=0xbfffeae4, init=0x8048d64 <_init>, fini=0x804b4f0 <_fini>, rtld_fini=0x4000dc14 <_dl_fini>, stack_end=0xbfffeadc) at ../sysdeps/generic/libc-start.c:129

We assume the program is compiled with special switches to generate debugging symbols (the -g compiler switch) and extra information is stored in the program file. Otherwise it is very hard to figure out what went wrong by looking at the stack trace.

Share Button

Leave a comment

Your email address will not be published. Required fields are marked *