简体   繁体   中英

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"

  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 .

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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