分段错误的行数 [英] Line number of segmentation fault
本文介绍了分段错误的行数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我可以设置任何 gcc 选项来提供分段错误的行号吗?
Is there any gcc option I can set that will give me the line number of the segmentation fault?
我知道我可以:
- 逐行调试
- 将 printfs 放入代码中以缩小范围.
bt
/where
on gdb give No stack.- 有用的建议
bt
/where
on gdb give No stack.- Helpful suggestion
推荐答案
我不知道 gcc 选项,但是你应该能够使用 gdb 运行应用程序,然后当它崩溃时,键入 where
在堆栈退出时查看堆栈,这应该可以让您关闭.
I don't know of a gcc option, but you should be able to run the application with gdb and then when it crashes, type where
to take a look at the stack when it exited, which should get you close.
$ gdb blah
(gdb) run
(gdb) where
为了完整性而
您还应该确保使用 -g
gcc 选项在可执行文件中包含行号时使用调试标志构建应用程序.
You should also make sure to build the application with debug flags on using the -g
gcc option to include line numbers in the executable.
另一种选择是使用 bt
(回溯)命令.
Another option is to use the bt
(backtrace) command.
这篇关于分段错误的行数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文