爱咋咋地
分类: LINUX
2011-04-12 19:11:31
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.2575Nifty! I am starting to wonder if there is anything gdb can’t do. :)
2. show backtrace of all threads like pstack
(gdb) thread apply all bt
3. don't print information in multi-pages
set height 0
4. set the size of content for print
set print element xxxx
5. logging gdb output into a file
set logging on [file name]
set logging off