【发布时间】:2016-10-19 07:21:28
【问题描述】:
我希望跳转到一行,无论是在相同的上下文中,还是在函数之外。我有一个“test.c”
1
2 #include<stdio.h>
3 void fa(int c)
4 {
5 printf("begin\n");/*I break here*/
6 printf("%d\n",c); /*I wish to jump 1 line here*/
7 }
8 void fb(){}
9
10 int main(){
11 int b=1;
12 int i=2;
13 fa('a');
14 fb(); /*I also want to jump here*/
15 return 0;
16 }
然后使用gcc test.c -g 编译它并使用gdb a.out 运行它。
gdb a.out
GNU gdb (Ubuntu 7.11.1-0ubuntu1~16.04) 7.11.1
...
(gdb) b 5
Breakpoint 1 at 0x400571: file test.c, line 5.
(gdb) r
Starting program: /home/Troskyvs/a.out
Breakpoint 1, fa (c=97) at test.c:5
5 printf("begin\n");
(gdb) j 6
Continuing at 0x40057b.
97 # This line is odd!
[Inferior 1 (process 6583) exited normally]
(gdb) f
No stack. # Why it doesn't print line 6 source code
(gdb) j 14
The program is not being run.
# What happen here?
我也试过“跳跃+1”和“跳跃+14”。同样的结果,不工作。
“跳跃”如何以我的方式工作?
【问题讨论】:
-
首先阅读您向我们展示的代码。函数
fa有什么作用?然后检查例如this ASCII table。看看字符'a'有什么值。此外,当调试器“继续”时,这意味着它将整个程序继续到其结束,当调试器报告“正常退出”时会发生这种情况。