#include<stdio.h>
int main(void)
{
main();
return 0;
}
给出分段错误(核心转储)。另外gdb with core给出了以下内容:
warning: Can't read pathname for load map: Input/output error.
warning: no loadable sections found in added symbol-file system-supplied DSO at 0x7fff653ca000
Core was generated by `./a.out'.
Program terminated with signal 11, Segmentation fault.
#0 main () at mainrecurs.c:6
6 main();
我的问题是为什么它没有显示函数的地址,即main。通常它也会显示地址。
在Ubuntu 12.04上运行,使用gcc进行编译
更新
(gdb) info reg
rax 0x7fee4d32d568 140661474121064
rbx 0x0 0
rcx 0x4004d0 4195536
rdx 0x7fff8aba4718 140735520851736
rsi 0x7fff8aba4708 140735520851720
rdi 0x1 1
rbp 0x7fff8a3a6000 0x7fff8a3a6000
rsp 0x7fff8a3a6000 0x7fff8a3a6000
r8 0x400560 4195680
r9 0x7fee4d340740 140661474199360
r10 0x7fff8aba4480 140735520851072
r11 0x7fee4cf92680 140661470340736
r12 0x4003d0 4195280
r13 0x7fff8aba4700 140735520851712
r14 0x0 0
r15 0x0 0
rip 0x4004b8 0x4004b8 <main+4>
eflags 0x10246 [ PF ZF IF RF ]
cs 0x33 51
ss 0x2b 43
ds 0x0 0
es 0x0 0
fs 0x0 0
---Type <return> to continue, or q <return> to quit---
gs 0x0 0
UPDATE2
当我使用gcc编译时没有-g选项。我正在跟随gdb:
Reading symbols from /home/a.out...(no debugging symbols found)...done.
[New LWP 2121]
warning: Can't read pathname for load map: Input/output error.
warning: no loadable sections found in added symbol-file system-supplied DSO at 0x7fffabb90000
Core was generated by `./a.out'.
Program terminated with signal 11, Segmentation fault.
#0 0x00000000004004b8 in main ()
现在地址是可见的,但为什么没有调试选项它会给出地址?地址与print reg
答案 0 :(得分:2)
如果我没弄错的话,这就是:
#0 main () at mainrecurs.c:6
6 main();
完全您正在寻找什么。 C文件,(正确的)行号以及发生的函数。
此段错误是堆栈溢出,因为您递归调用main()
。
答案 1 :(得分:0)
如果你注意警告,你会收到类似下面的警告:
警告C4717:'main':递归所有控制路径,函数会 导致运行时堆栈溢出
gdb会给你失败的行号。
6 main();