launch gdb and print out variable value using ruby
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 w开发者_C百科ays that can achieve the same goal, not necessaliy to use gdb.
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.
精彩评论