I am writing a web based debugger for Ruby, but in order to do this I need to be able to call the Ruby debugger from within a Ruby program on the server side. Has this ever been done? Is this even possible?
The end product being built will allow Ruby code to be edited, executed and stepped through using just a web browser. The ruby code that is to be debugged will be "eval"ed on the server side.
I have since been pointed in the right direction by one of the stackoverflow users who has suggested using popen or expect. I have tried both of these now but have encountered the following problems:
popen: When waiting for the console you have to use a timeout block to signal the end of the debug console's output (The command line terminal can detect this, so why can't ruby).
expect: In the program below the debugger inputs get out of sync with the debugger. Why is that?
require 'pty' require 'expect' $expect_verbose = true PTY.spawn("rdebug deb.rb") do |from_debugger, to_debugger, pid| a=nil while ( a != "end" ) do from_debugger.expect(/\(rdb:1\)/ ) do |input| a = gets to_debugger.puts( a + "\n" ) end from_debugger.flush end end