简体   繁体   English

GDB“跳转”命令不会跳转到有效上下文吗?

[英]GDB “jump” command doesn't jump to a valid context?

I wish to jump to a line, either in same context, or outside the function. 我希望跳转到同一上下文中或函数外部的一行。 I've got a "test.c" 我有一个“ 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 }

Then compiled it with gcc test.c -g and run it using gdb a.out . 然后使用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". 我还尝试了“跳转+1”和“跳转+14”。 Same result, don't work. 结果相同,不起作用。

How "jump" could work in my way? “跳跃”如何以我的方式起作用?

Well, it's doing what you asked it to do. 好吧,它正在执行您要求的操作。 It

[Inferior 1 (process 6583) exited normally]

So, your program is over already. 因此,您的程序已经结束 It's no longer running. 它不再运行。

FWIW, if you want to stop/interrupt the normal the execution again , you have to set more that one break point after the jump destination to make it wait. FWIW,如果你想停止/中断正常的再次执行,你必须设置更多的跳转目标一个破发点,以使其等待。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM