Generating core files from gdb

While debugging a problem a few weeks back, I needed to generate a core file from a hung process. I typically use the gcore utility to generate core files from running processes, but in this case I was already attached to the process with gdb, so gcore failed:

$ gcore 2575
ptrace: Operation not permitted.
You can’t do that without a process to debug.

Gak! I remembered reading about a gdb option that would dump core, so I wandered off to read through my gdb notes. Sure enough, gdb has a “generate-core-file” command to create a core file:

$ gdb -q – 2575

Attaching to process 2575
Reading symbols from /usr/sbin/gpm...(no debugging symbols found)...done.
Using host libthread_db library "/lib/tls/libthread_db.so.1".
Reading symbols from /lib/tls/libm.so.6...(no debugging symbols found)...done.
Loaded symbols for /lib/tls/libm.so.6
Reading symbols from /lib/tls/libc.so.6...
(no debugging symbols found)...done.
Loaded symbols for /lib/tls/libc.so.6
Reading symbols from /lib/ld-linux.so.2...(no debugging symbols found)...done.
Loaded symbols for /lib/ld-linux.so.2

0x0046e7a2 in _dl_sysinfo_int80 () from /lib/ld-linux.so.2

(gdb) generate-core-file
Saved corefile core.2575

(gdb) detach
Detaching from program: /usr/sbin/gpm, process 2575

(gdb) quit

$ ls -al core.*
-rw-r--r--  1 root root 2468288 Dec 11 13:49 core.2575

Nifty! I am starting to wonder if there is anything gdb can’t do. :)

3 Comments

harish  on March 8th, 2007

Can gdb allow a breakpoint at a function in a .so file that is yet to be loaded??

Alex Brown  on June 19th, 2007

(gdb) help future-break
Set breakpoint at expression. If it can’t be done now, attempt it
again each time code is dynamically loaded.

BillAtHRST  on June 24th, 2008

use following:

set breakpoint pending on

to set breakpoint(s) that will be re-evaluated when code is dynamically loaded

Leave a Comment