gdb 调试错行的问题,请高手赐教

默默努力的小熊 2013-04-19 01:15:41
操作步骤:
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;
}
...全文
749 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
heartlesstoanyone 2013-04-22
  • 打赏
  • 举报
回复
引用 6 楼 fly_qj 的回复:
没什么问题啊,断点自动跳到函数进去以后的第一行有效代码前了,不就是这样么。
6楼正解,本来就是这样的。
RedWolf1999 2013-04-21
  • 打赏
  • 举报
回复
没什么问题啊,断点自动跳到函数进去以后的第一行有效代码前了,不就是这样么。
prohibit 2013-04-19
  • 打赏
  • 举报
回复
引用 4 楼 liumangxiong 的回复:
…… 这里也很奇怪,next竟然跑到空行上去了@ @ (gdb) n 612 (gdb) l ……
呃,见识了。。。 打断点打到函数所在行号上,调试时也是停在该行或该行以下的第一句可执行语句/有效行上,和打断点到函数名上效果一样;只是显示断点的位置不同,这个在调试时应该不是很重要吧
  • 打赏
  • 举报
回复
我实际中代码是这样的: ===============》如下在函数cmd_show_disk_all 下断点 断点停下来的时候却是在{上面,很奇怪,这个又没有语句 Breakpoint 2, cmd_show_disk_all (disk_list=0x7fffffffa9b0) at disk.c:608 608 { Missing separate debuginfos, use: debuginfo-install device-mapper-libs-1.02.77-4.fc18.x86_64 glibc-2.16-30.fc18.x86_64 libgcc-4.7.2-8.fc18.x86_64 libselinux-2.1.12-7.fc18.x86_64 libsepol-2.1.8-2.fc18.x86_64 libuuid-2.22.2-6.fc18.x86_64 pcre-8.31-2.fc18.x86_64 systemd-libs-195-15.fc18.x86_64 (gdb) l 603 } 604 605 int cmd_show_disk_all(disk_slot_t *disk_list) 606 { 607 if (NULL == disk_list) 608 { 609 return -1; 610 } 611 disk_manager_init(); 612 这里也很奇怪,next竟然跑到空行上去了@ @ (gdb) n 612 (gdb) l 607 if (NULL == disk_list) 608 { 609 return -1; 610 } 611 disk_manager_init(); 612 613 if (0 != get_lock()) return -10; 614 int disk_num = get_all_disk(disk_list); 615 release_lock(); 616 return disk_num;
  • 打赏
  • 举报
回复
man gdb 显示的,看样子是可以断点 break [file:]function Set a breakpoint at function (in file). 换一台redhat机器,还是有同样的问题 $ gdb a.out GNU gdb (GDB) Red Hat Enterprise Linux (7.2-60.el6) Copyright (C) 2010 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 "i686-redhat-linux-gnu". For bug reporting instructions, please see: <http://www.gnu.org/software/gdb/bugs/>... Reading symbols from /home/chenshikui/a.out...done. (gdb) b main Breakpoint 1 at 0x80483cd: file test.c, line 4. (gdb) detach The program is not being run. (gdb) q [@192 ~]$ [@192 ~]$ [@192 ~]$ vi test.c 1 #include <stdio.h> 2 int main(void) 3 { 4 printf("hello"); 5 return 0; 6 } 7
yong_f 2013-04-19
  • 打赏
  • 举报
回复
断点不能设在函数名上,那不是可执行语句。停不来。让CPU接着运行,运行的是printf,不是main
  • 打赏
  • 举报
回复
顺便说一下,test.c 是完全在linux下面用vi编写的,不存在windows编码问题。

23,121

社区成员

发帖
与我相关
我的任务
社区描述
Linux/Unix社区 应用程序开发区
社区管理员
  • 应用程序开发区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧