Debugging ironruby code hosted by a c# app

I’m experimenting a little with ironruby and I just want to know if
there’s any way to debug ironruby code that is hosted by a c# windows
app. Any ideas?

thanks,
Santiago

If your app is executing simple Ruby files it is possible to debug them
in VS. You need to turn on debugging when you create a ScriptRuntime:

var setup = new ScriptRuntimeSetup();
setup.DebugMode = true;
setup.AddRubySetup();
var runtime = Ruby.ScriptRuntime(setup);
runtime.ExecuteFile(“foo.rb”);

Run your app with attached VS debugger and place breakpoint to foo.rb.

Note that DebugMode slows down execution significantly and is therefore
not quite usable for larger app frameworks (gems, rails, etc.). We don’t
have any better debugging experience right now. We are working towards
one but it will take some time.

Tomas

You can attach the VS debugger to your process, and as long as you’ve
told the IronRuby engine to generate debug-able code, you can place
breakpoints in Ruby code. The stack trace and watch windows are very
verbose, as they show you the IronRuby internals, but with some extra
digging around you can find the values of your variables and such.

You can initialize the IronRuby engine to generate debug-able code like
this:

// Program.cs:
using IronRuby;
using Microsoft.Scripting.Hosting;

namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args) {
// There might be a more concise way of doing it with
Ruby.CreateEngine((ls) => {}), but I’m not sure
var setup = new ScriptRuntimeSetup() { DebugMode = true };
setup.LanguageSetups.Add(Ruby.CreateRubySetup());
var engine = Ruby.CreateRuntime(setup).GetRubyEngine();

        // place a breakpoint in foo.rb, and it'll break there
        engine.ExecuteFile("foo.rb");
    }
}

}

Foo.rb:

puts ‘hi’

Note: don’t create foo.rb in VS, as it’ll a Unicode file, and IronRuby
will give you a wonky exception like " undefined method `puts’ for
main:Object"

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs