E.g:
define mycmd
break $arg0
commands
print $arg0
end
end
mycmd myfunc
continue
打印:
$1 = void
而不是预期的myfunc
,因为$arg0
在命令被命中时被评估,并且因为它尚未定义显示void
。
有没有办法将其传递给commands
?
我想我可以轻松地使用Python,但是更快的方式会很酷。但是如果你准备好了Python,那就试试吧。
动机:自动化https://stackoverflow.com/a/5372742/895245,我想写的地方:
define break-stack
break $arg0
commands
tbreak $arg1
continue
end
end
break-stack ParentFunc ChildFunc
是的,我知道https://stackoverflow.com/a/20209911/895245提供了Python解决方案。
GDB 7.11,Ubuntu 16.10。
答案 0 :(得分:1)
我无法哄骗gdb的eval
以评估多行命令,例如commands
,因此这是一个使用shell
的解决方案。< / p>
define break-stack
dont-repeat
break $arg0
shell { echo commands; echo tbreak $arg1; echo continue; echo end; } > /tmp/gdbtmp
source /tmp/gdbtmp
shell rm /tmp/gdbtmp
end
如果您的echo
接受-e
选项,则可以缩短为
define break-stack
dont-repeat
break $arg0
shell echo -e "commands\ntbreak $arg1\ncontinue\nend" > /tmp/gdbtmp
source /tmp/gdbtmp
shell rm /tmp/gdbtmp
end
您的具体任务 - 当函数 b 被函数 a 调用时停止 - 可以使用最近包含的$_caller_is
便利功能来完成gdb的版本。
define break-stack
break "$arg1" if $_caller_is("$arg0")
end