views:

81

answers:

1

Hi ,

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.

+2  A: 

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.

Sam Post
sam, I will try. Thanks. +1
pierr