0

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.

pierrotlefou
  • 39,805
  • 37
  • 135
  • 175
  • Did my answer help? Any followup questions I can help answer? Did open4 give you what you needed? – Sam Post Feb 03 '10 at 06:11
  • Sam, open4 is helpful but I have not been successful in using it to solve my problem. I will accept you answer if there will be no other answers. – pierrotlefou Feb 03 '10 at 07:55

1 Answers1

2

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
  • 3,721
  • 3
  • 17
  • 14