10

我在 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调用来获得正确的内存范围......)

4

2 回答 2

14

运行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
...
于 2014-11-20T20:16:21.490 回答
0

请参阅如何在 XCode + gdb 中为崩溃的应用程序生成核心文件?

此外,也许较新的 gdb 具有可在 MacOS 上运行的 gcore。我不知道,但你可以四处寻找并找出答案。

于 2013-07-18T14:12:46.077 回答