我有一个程序,我希望在 gdb 中调试分段错误,但我不确定如何从中生成核心文件。
我试过$ ulimit -c unlimited
了,但是当运行程序然后导航到 /cores/ 时,当我输入ls
.
我在这里错过了什么吗?
提前致谢!
启用核心文件生成的方式取决于您的 shell。您显示的语法适用于使用sh
或bash
作为他们的 shell 的人,它应该可以正常工作。例如
% 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)