GDB "jump" 命令没有跳转到有效上下文?
GDB "jump" command doesn't jump to a valid context?
我希望跳转到相同上下文或函数外部的一行。我有一个 "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?
I also tried "jump +1" and "jump +14". Same result, don't work.
"jump" 如何按照我的方式工作?
好吧,它正在执行您要求它执行的操作。它
- 跳到第6行
- 执行了代码
printf("%d\n",c);
,打印了值 (97)。 See here to know why the value is 97
- 继续执行,执行完毕。证明
[Inferior 1 (process 6583) exited normally]
那么,您的程序已经 结束 了。不再是 运行.
FWIW,如果你想stop/interrupt正常执行再次,你必须设置多个断点after[=31] =] 让它等待的跳转目的地。
我希望跳转到相同上下文或函数外部的一行。我有一个 "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?
I also tried "jump +1" and "jump +14". Same result, don't work.
"jump" 如何按照我的方式工作?
好吧,它正在执行您要求它执行的操作。它
- 跳到第6行
- 执行了代码
printf("%d\n",c);
,打印了值 (97)。 See here to know why the value is 97 - 继续执行,执行完毕。证明
[Inferior 1 (process 6583) exited normally]
那么,您的程序已经 结束 了。不再是 运行.
FWIW,如果你想stop/interrupt正常执行再次,你必须设置多个断点after[=31] =] 让它等待的跳转目的地。