确定C code,它会导致分段错误的行? [英] Determine the line of C code that causes a segmentation fault?
本文介绍了确定C code,它会导致分段错误的行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我们如何确定这个错误是我们code,导致分段错误?
How do we determine where the mistake is in our code that causes a segmentation fault?
写一些code后,决定在那里我有一个分段错误,可以的gcc显示我有一个错误(或输入错误)在一个特定的行号 - 因为该行造成分段错误
After writing some code, to determine where I have a segmentation fault, can gcc show me my have a mistake (or typing error) in a particular line number -- because that line caused the segmentation fault?
推荐答案
GCC不能做到这一点,但肯定GDB可以。编译你的程序中使用 -g
开关,像这样的:
GCC can't do that but GDB sure can. Compile you program using the -g
switch, like this:
gcc program.c -g
然后使用gdb的:
Then use gdb:
$ gdb ./a.out
(gdb) run
<segfault happens here>
(gdb) backtrace
<offending code is shown here>
这里是一个很好的教程,让你开始使用GDB。
Here is a nice tutorial to get you started with GDB.
这篇关于确定C code,它会导致分段错误的行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文