gdb 调试错行的问题,请高手赐教
操作步骤:
1、写一个最简单的test.c
1 #include <stdio.h>
2 int main(void)
3 {
4 printf("hell");
5 return 0;
6 }
2、gcc -g test.c
3、gdb a.out
4、断点b main
(gdb) b main
Breakpoint 1 at 0x400530: file test.c, line 4.
这个时候发现断下来是第4行,而上面我自己编写的test.c中main是在第2行,求高手赐教如何才能在gdb正确显示行数。
详细信息如下:
[root@localhost douglas]# gcc -g test.c
[root@localhost douglas]# gdb a.out
GNU gdb (GDB) Fedora (7.5.0.20120926-25.fc18)
Copyright (C) 2012 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-redhat-linux-gnu".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
Reading symbols from /home/douglas/a.out...done.
(gdb) b main
Breakpoint 1 at 0x400530: file test.c, line 4.
(gdb) shell vi test.c
#include <stdio.h>
int main(void)
{
printf("hell");
return 0;
}
[解决办法]
断点不能设在函数名上,那不是可执行语句。停不来。让CPU接着运行,运行的是printf,不是main
[解决办法]