【问题标题】:GDB "jump" command doesn't jump to a valid context?GDB“跳转”命令没有跳转到有效的上下文?
【发布时间】: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' 有什么值。此外,当调试器“继续”时,这意味着它将整个程序继续到其结束,当调试器报告“正常退出”时会发生这种情况。

标签: c gcc gdb skip


【解决方案1】:

嗯,它正在做你要求它做的事情。它

[Inferior 1 (process 6583) exited normally]

所以,你的程序已经结束了。它不再运行。

FWIW,如果你想停止/中断正常的执行再次,你必须在跳转目的地之后设置一个以上的断点让它等待。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-12-04
    • 1970-01-01
    • 1970-01-01
    • 2019-10-02
    • 1970-01-01
    • 1970-01-01
    • 2012-10-27
    • 2011-02-01
    相关资源
    最近更新 更多