How to generate core files on a Mac?

早过忘川 提交于 2019-12-13 03:16:29

问题


I have a program that I hope to debug in gdb for a segmentation fault, but I'm not sure how I can generate a core file from it.

I tried $ ulimit -c unlimited, but when ran the program and then navigated into /cores/, there is no core file generated there when I typed ls.

Am I missing anything here?

Thanks in advance!


回答1:


The way you enable core file generation is dependent on your shell. The syntax you're showing is for someone using sh or bash as their shell, and it should work fine. e.g.

% sh
sh-3.2$ cat>/tmp/a.c
int main ()
{
  void (*f)() = 0;
  f();
}
sh-3.2$ clang -g /tmp/a.c -o /tmp/a.out
sh-3.2$ ulimit -c unlimited
sh-3.2$ /tmp/a.out
Segmentation fault: 11 (core dumped)
sh-3.2$ ls -l /cores/core.10893 
-r--------  1 jason  admin  367714304 Nov 16 13:13 /cores/core.10893

sh-3.2$ gdb -q /tmp/a.out /cores/core.10893 
Reading symbols for shared libraries .. done
Reading symbols for shared libraries . done
Reading symbols for shared libraries 
warning: Could not find object file "/var/folders/5h/nlzqfv116jnc68g495d_3j4m0000gn/T/a-pUbMeU.o" - no debug information available for "/tmp/a.c".

.......................... done
#0  0x0000000000000000 in ?? ()
(gdb) add-dsym /tmp/a.out.dSYM 
Added dsym "/tmp/a.out.dSYM" to "[memory object "/private/tmp/a.out" at 0x10f5d7000]".
(gdb) bt
#0  0x0000000000000000 in ?? ()
#1  0x000000010f5d7f3d in main () at /tmp/a.c:4
(gdb) 


来源:https://stackoverflow.com/questions/13212000/how-to-generate-core-files-on-a-mac

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!