$cat testleak01.cpp
#include<iostream>
int main()
{
int*p=new int[3];
return 0;
}
使用调试信息进行编译
$g++ testleak01.cpp -g
然后用lldb启动
(lldb) b main
Breakpoint 1: where = a.out`main + 22 at testleak01.cpp:4, address = 0x0000000100000f86
(lldb) r
Process 87960 launched: '/Users/x/Documents/learn/a.out' (x86_64)
Process 87960 stopped
* thread #1: tid = 0x60b7ec, 0x0000000100000f86 a.out`main + 22 at testleak01.cpp:4, queue = 'com.apple.main-thread', stop reason = breakpoint 1.1
frame #0: 0x0000000100000f86 a.out`main + 22 at testleak01.cpp:4
1 #include<iostream>
2 int main()
3 {
-> 4 int*p=new int[3];
5 return 0;
6 }
(lldb) process save-core mycore
... a lot of stuff
半分钟后我得到了一个巨大的核心文件(500M+),像这样,root是它的所有者
-rw------- 1 root staff 589529088 2 25 21:06 mycore
然后我尝试加载它并且
$lldb -c mycore
(lldb) target create --core "mycore"
error: Unable to find process plug-in for core file '/Users/x/Documents/learn/mycore'
为什么它不能识别自己生成的core文件? 我期望使用 lldb 加载 a.out 和 mycore 以检查转储文件作为进程映像。
就我而言,这是错误生成的核心文件。同一应用程序的多个并行实例几乎同时崩溃,我得到了 3 个核心文件。其中 2 个 lldb 工作正常,但其中一个我得到“无法找到核心文件的进程插件”。
ls -la /cores/core*
-r-------- 1 build admin 1605496832 Jun 24 09:53 core.83754
-r-------- 1 build admin 1615982592 Jun 24 09:53 core.83773
-r-------- 1 build admin 1605496832 Jun 24 09:53 core.83797
当我使用“file”命令测试核心文件时,我发现它确实不可读:
file /cores/core*
/cores/core.83754: Mach-O 64-bit core x86_64
/cores/core.83773: Mach-O 64-bit core x86_64
/cores/core.83797: data
我认为这是一个 MacOS 错误,有时无法正确写入核心转储。