当前位置: 技术问答>linux和unix
gdb 调试错行的问题,请高手赐教
来源: 互联网 发布时间:2017-04-08
本文导语: 操作步骤: 1、写一个最简单的test.c 1 #include 2 int main(void) 3 { 4 printf("hell"); 5 return 0; 6 } 2、gcc -g test.c 3、gdb a.out 4、断点b main (g...
操作步骤:
1、写一个最简单的test.c
1 #include
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
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:
...
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
int main(void)
{
printf("hell");
return 0;
}
1、写一个最简单的test.c
1 #include
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
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:
...
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
int main(void)
{
printf("hell");
return 0;
}
|
呃,见识了。。。
打断点打到函数所在行号上,调试时也是停在该行或该行以下的第一句可执行语句/有效行上,和打断点到函数名上效果一样;只是显示断点的位置不同,这个在调试时应该不是很重要吧
打断点打到函数所在行号上,调试时也是停在该行或该行以下的第一句可执行语句/有效行上,和打断点到函数名上效果一样;只是显示断点的位置不同,这个在调试时应该不是很重要吧
|
没什么问题啊,断点自动跳到函数进去以后的第一行有效代码前了,不就是这样么。
|
断点不能设在函数名上,那不是可执行语句。停不来。让CPU接着运行,运行的是printf,不是main
|
6楼正解,本来就是这样的。