日期:2014-05-16  浏览次数:20699 次

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
------解决方案--------------------
引用:
……
这里也很奇怪,next竟然跑到空行上去了@ @       
(gdb) n
612         
(gdb) l
……
呃,见识了。。。
打断点打到函数所在行号上,调试时也是停在该行或该行以下的第一句可执行语句/有效行上,和打断点到函数名上效果一样;只是显示断点的位置不同,这个在调试时应该不是很重要吧
------解决方案--------------------
没什么问题啊,断点自动跳到函数进去以后的第一行有效代码前了,不就是这样么。
------解决方案--------------------
引用:
没什么问题啊,断点自动跳到函数进去以后的第一行有效代码前了,不就是这样么。


6楼正解,本来就是这样的。