如何执行完成,然后从内部命令执行另一个命令? [英] How to execute finish and then another command from inside commands?

查看:107
本文介绍了如何执行完成,然后从内部命令执行另一个命令?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的代码结构简化的例子:

This is a reduced example of the structure of my code:

void increment(int j);

int main()
{
  int i = 0;

  while(1) {
    i = increment(i);
  }

  return 0;
}

int increment(int j)
{
  return j + 1;
}

以下是相应的GDB脚本:

And here is the corresponding GDB script:

b increment
command 1
finish
print i
continue
end

问题在于 finish 命令阻止了之后发出的命令它(即打印我和继续)不会被调用。

The problem is that the finish command prevents the commands that come after it (namely print i and continue) to not be called.

有没有办法告诉GDB在任何增量调用之后打印 i

Is there a way to tell GDB to print i right after any increment call?

推荐答案

(gdb) break doSomething
Breakpoint 1 at 0x400478: file iter.c, line 5.
(gdb) commands
Type commands for breakpoint(s) 1, one per line.
End with a line saying just "end".
>python gdb.execute("print i"); gdb.execute("finish"); gdb.execute("print i");
>end

Breakpoint 1, doSomething () at iter.c:5
5     while (i < 5)
$1 = 0
main (argc=1, argv=0x7fffffffe178) at iter.c:13
13    return 0;
$2 = 5

编辑:
a第二个解决方案不需要python似乎正在定义一个新的gdb命令
并在命令中运行该命令:

edit: a 2nd work around that doesn't require python appears to be defining a new gdb command and running that in commands:

define foo
print *i
set $addrOfI = i
finish
print *$addrOfI
end

break doSomething
commands
foo
end

这篇关于如何执行完成,然后从内部命令执行另一个命令?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆