启动 gdb 并使用 ruby 打印变量值
我想编写一个 ruby 程序,它可以通过启动 gdb 然后打印该值来检查程序的变量值。我怎样才能做到这一点?
如果我在 shell 中,我会这样做:
shell > gdb test
[...gbd started]
(gdb) p variable
$1 = 20
(gdb)
我也喜欢听到可以实现相同目标的其他方法,而不必使用 gdb。
I want to write a ruby program that could inspect the variable value of a program by launch the gdb
and then print
that value. How could I achieve this?
If I were in the shell, I would do this :
shell > gdb test
[...gbd started]
(gdb) p variable
$1 = 20
(gdb)
I also like to hear other ways that can achieve the same goal, not necessaliy to use gdb.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试 open4,它允许您将 stdin、stdout、stderr 打开到任意命令。您可以完全按照您的描述使用 open4 来运行 gdb,我亲自这样做过并且效果非常好。可能想要创建一个处理运行命令和返回状态的包装类,因为 open4 只是为您提供文件句柄。
Try open4, which allows you to open stdin, stdout, stderr to an arbitrary command. You could use open4 to run gdb exactly as you describe, I have done this personally and it works quite nicely. Might want to create a wrapper class that handles running commands and returning status, as open4 just gives you file handles.