我在OSX上使用gdb,它似乎既没有gcore
也没有generate-core-file
命令:
$ 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)
鉴于此,我如何通过GDB生成核心转储或近似的核心转储?
(我怀疑我可以使用dump memory
,但这需要一个地址范围,而我正在努力寻找正确的info
调用以获得正确的内存范围...)
答案 0 :(得分:8)
运行lldb --attach-pid
,然后使用process save-core
命令保存核心。请注意,该过程将在您附加到该过程时暂停,因此如果这是一个重要过程,请务必小心。
$ 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
...
答案 1 :(得分:0)
请参阅How to generate a core file for a crashed app in XCode + gdb?
另外,也许新的gdb有一个适用于MacOS的gcore。我不知道,但你可以四处寻找并找出答案。