Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dumping core in gdb on OSX (no "gcore" or "generate-core-file")

I'm using gdb on OSX, which seems to have neither the gcore nor generate-core-file commands:

$ gdb
GNU gdb 6.3.50-20050815 (Apple version gdb-1705) (Fri Jul  1 10:50:06 UTC 2011)
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "x86_64-apple-darwin".
(gdb) gcore
Undefined command: "gcore".  Try "help".
(gdb) generate-core-file
Undefined command: "generate-core-file".  Try "help".
(gdb)

Given this, how might I go about generating a core dump, or something approximating one, via GDB?

(I suspect I can use dump memory, but that requires an address range, and I'm struggling to find the right info invocation to get the right memory range...)

like image 376
Kristian Glass Avatar asked Apr 30 '12 16:04

Kristian Glass


1 Answers

Run lldb --attach-pid, then use the process save-core command to save the core. Note that the process will be paused right from when you attach to it, so be careful if it’s an important process.

$ lldb --attach-pid <pid>
(lldb) process attach --pid 76669
Process 76669 stopped
Executable module set to "/bin/bash".
Architecture set to: x86_64h-apple-macosx.
(lldb) process save-core "core"
mach_header: 0xfeedfacf 0x01000007 0x00000008 0x00000004 0x00000030 0x00000e08 0x00000000 0x00000000
...
Saving data for segment at 0x7fd455200000
...
like image 154
andrewdotn Avatar answered Oct 09 '22 05:10

andrewdotn