Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does one debug jRuby using eclipse?

This sounds like a fairly trivial question, but I've been struggling with it for ages, abandoning Ruby and coming back to it. I am a Java/Eclipse person trying to learn Ruby, and so I would like to debug jRuby/Rails using some Eclipse plugin, on my Win 7, 64-bit computer. How come it is so hard? I could not find a step-by-step instruction (e.g. install this plug-in, this version of jRuby, install these gems, tweak these settings). In the absence of that, I am doing hit-and-miss, and everything I do seems to result in bizarre errors.

At this point in time, I am trying to use EasyEclipse (is it a good choice?). I found that the default installation (into Program Files) is not a good idea and installed it at a path with no spaces; same with jRuby. I installed two debug gems (from the top of my head, gem install ruby-debug and gem install ruby-debug-ide), then did "gem update". I am running the latest stable version of EasyEclipse and jRuby.

I am able to run a Ruby program. However, when I put on a breakpoint and try debug, debugger gets stuck at "Launching(95%)" and Console shows:

ruby 1.9.3 debugger listens on port 52188 undefined method `critical=' for Thread:Class

That, when I turn on "Use ruby-debug library" library in preferences, I get this:

   Fast Debugger (ruby-debug-ide 0.4.18, ruby-debug-base 0.10.3.2) listens on 127.0.0.1:52819
Hello, world!
Hello, world!2
Hello, world!3
Context.java:407:in `contextCopyLocals': java.lang.NoSuchMethodError: org.jruby.runtime.DynamicScope.getEvalScope()Lorg/jruby/runtime/DynamicScope;
    from Context.java:284:in `frame_locals'
    from Context$INVOKER$i$1$0$frame_locals_DBG.gen:-1:in `call'
    from JavaMethod.java:347:in `call'
    from CachingCallSite.java:326:in `cacheAndCall'
    from CachingCallSite.java:170:in `call'
    from CallOneArgNode.java:57:in `interpret'
    from LocalAsgnNode.java:123:in `interpret'
    from NewlineNode.java:105:in `interpret'
    from BlockNode.java:71:in `interpret'
    from ASTInterpreter.java:74:in `INTERPRET_METHOD'
    from InterpretedMethod.java:139:in `call'
    from CachingCallSite.java:306:in `cacheAndCall'
    from CachingCallSite.java:136:in `call'
    from CallNoArgNode.java:60:in `interpret'
    from NewlineNode.java:105:in `interpret'
    from IfNode.java:118:in `interpret'
    from NewlineNode.java:105:in `interpret'
    from IfNode.java:116:in `interpret'
    from NewlineNode.java:105:in `interpret'
    from BlockNode.java:71:in `interpret'
    from ASTInterpreter.java:112:in `INTERPRET_BLOCK'
    from Interpreted19Block.java:206:in `evalBlockBody'
    from Interpreted19Block.java:157:in `yield'
    from Block.java:142:in `yield'
    from RubyArray.java:1610:in `eachCommon'
    from RubyArray.java:1617:in `each'
    from RubyArray$INVOKER$i$0$0$each_DBG.gen:-1:in `call'
    from CachingCallSite.java:143:in `callBlock'
    from CachingCallSite.java:154:in `callIter'
    from CallNoArgBlockNode.java:64:in `interpret'
    from NewlineNode.java:105:in `interpret'
    from ASTInterpreter.java:112:in `INTERPRET_BLOCK'
    from Interpreted19Block.java:206:in `evalBlockBody'
    from Interpreted19Block.java:157:in `yield'
    from Block.java:142:in `yield'
    from RubyContinuation.java:107:in `enter'
    from RubyKernel.java:1261:in `rbCatch19Common'
    from RubyKernel.java:1254:in `rbCatch19'
    from RubyKernel$INVOKER$s$rbCatch19_DBG.gen:-1:in `call'
    from CachingCallSite.java:177:in `callBlock'
    from CachingCallSite.java:188:in `callIter'
    from FCallOneArgBlockNode.java:34:in `interpret'
    from NewlineNode.java:105:in `interpret'
    from BlockNode.java:71:in `interpret'
    from WhileNode.java:131:in `interpret'
    from NewlineNode.java:105:in `interpret'
    from BlockNode.java:71:in `interpret'
    from RescueNode.java:222:in `executeBody'
    from RescueNode.java:117:in `interpret'
    from ASTInterpreter.java:74:in `INTERPRET_METHOD'
    from InterpretedMethod.java:139:in `call'
    from CachingCallSite.java:306:in `cacheAndCall'
    from CachingCallSite.java:136:in `call'
    from CallNoArgNode.java:60:in `interpret'
    from NewlineNode.java:105:in `interpret'
    from BlockNode.java:71:in `interpret'
    from ASTInterpreter.java:74:in `INTERPRET_METHOD'
    from InterpretedMethod.java:268:in `call'
    from CachingCallSite.java:366:in `cacheAndCall'
    from CachingCallSite.java:238:in `call'
    from FCallThreeArgNode.java:40:in `interpret'
    from NewlineNode.java:105:in `interpret'
    from BlockNode.java:71:in `interpret'
    from ASTInterpreter.java:74:in `INTERPRET_METHOD'
    from InterpretedMethod.java:268:in `call'
    from CachingCallSite.java:366:in `cacheAndCall'
    from CachingCallSite.java:238:in `call'
    from CallThreeArgNode.java:61:in `interpret'
    from NewlineNode.java:105:in `interpret'
    from ASTInterpreter.java:74:in `INTERPRET_METHOD'
    from InterpretedMethod.java:112:in `call'
    from InterpretedMethod.java:126:in `call'
    from RubyClass.java:722:in `finvoke'
    from Helpers.java:486:in `invoke'
    from RubyBasicObject.java:367:in `callMethod'
    from DebugEventHook.java:566:in `callAtLine'
    from DebugEventHook.java:553:in `callAtLine'
    from DebugEventHook.java:190:in `processEvent'
    from DebugEventHook.java:97:in `eventHandler'
    from EventHook.java:30:in `event'
    from Ruby.java:2882:in `callEventHooks'
    from ASTInterpreter.java:239:in `callTraceFunction'
    from NewlineNode.java:101:in `interpret'
    from BlockNode.java:71:in `interpret'
    from ASTInterpreter.java:103:in `INTERPRET_CLASS'
    from ASTInterpreter.java:280:in `evalClassDefinitionBody'
    from ClassNode.java:138:in `interpret'
    from NewlineNode.java:105:in `interpret'
    from RootNode.java:129:in `interpret'
    from ASTInterpreter.java:121:in `INTERPRET_ROOT'
    from Ruby.java:834:in `runInterpreter'
    from Ruby.java:2674:in `loadFile'
    from ExternalScript.java:66:in `load'
    from LoadService.java:359:in `load'
    from Debugger.java:137:in `load'
    from RubyDebugger.java:207:in `debug_load'
    from RubyDebugger$INVOKER$s$0$2$debug_load_DBG.gen:-1:in `call'
    from DynamicMethod.java:225:in `call'
    from DynamicMethod.java:221:in `call'
    from CachingCallSite.java:366:in `cacheAndCall'
    from CachingCallSite.java:238:in `call'
    from FCallThreeArgNode.java:40:in `interpret'
    from LocalAsgnNode.java:123:in `interpret'
    from NewlineNode.java:105:in `interpret'
    from BlockNode.java:71:in `interpret'
    from ASTInterpreter.java:74:in `INTERPRET_METHOD'
    from InterpretedMethod.java:182:in `call'
    from CachingCallSite.java:326:in `cacheAndCall'
    from CachingCallSite.java:170:in `call'
    from CallOneArgNode.java:57:in `interpret'
    from NewlineNode.java:105:in `interpret'
    from BlockNode.java:71:in `interpret'
    from RootNode.java:129:in `interpret'
    from ASTInterpreter.java:121:in `INTERPRET_ROOT'
    from Ruby.java:834:in `runInterpreter'
    from Ruby.java:2674:in `loadFile'
    from ExternalScript.java:66:in `load'
    from LoadService.java:359:in `load'
    from RubyKernel.java:1081:in `loadCommon'
    from RubyKernel.java:1073:in `load19'
    from RubyKernel$INVOKER$s$0$1$load19_DBG.gen:-1:in `call'
    from DynamicMethod.java:209:in `call'
    from DynamicMethod.java:205:in `call'
    from CachingCallSite.java:326:in `cacheAndCall'
    from CachingCallSite.java:170:in `call'
    from FCallOneArgNode.java:36:in `interpret'
    from NewlineNode.java:105:in `interpret'
    from BlockNode.java:71:in `interpret'
    from RootNode.java:129:in `interpret'
    from ASTInterpreter.java:121:in `INTERPRET_ROOT'
    from Ruby.java:834:in `runInterpreter'
    from Ruby.java:842:in `runInterpreter'
    from Ruby.java:673:in `runNormally'
    from Ruby.java:518:in `runFromMain'
    from Main.java:390:in `doRunFromMain'
    from Main.java:279:in `internalRun'
    from Main.java:221:in `run'
    from Main.java:201:in `main'

What's going on?

I suppose I could keep googling and trying finding my way in the dark, but I've spent so much time doing it already, and surely someone has accomplished the trivial task of debugging jRuby in Eclipse before me? Help!

like image 394
Irina Rapoport Avatar asked Sep 07 '13 04:09

Irina Rapoport


People also ask

How do I debug a Java program in Eclipse?

First, we need to start the Java program within Eclipse in debug mode. This can be achieved in two ways: Right-click on the editor and select Debug As -> Java Application (shown in below screenshot) Debug the program from the toolbar (highlighted in below screenshot)

How do I debug a Java program on another machine?

– The Eclipse IDE allows you to debug applications that runs on another Java Virtual Machine (JVM) or even on another machine. You can create a new debug configuration of the Remote Java Application type. To enable remote debugging you need to start your Java application with certain flags.

How does the Eclipse platform help developers debug?

The Eclipse Platform helps developers debug by providing buttons in the toolbar and key binding shortcuts to control program execution. For more information about debugging visit: Eclipse Stepping Commands Help

How do I debug a program in Visual Studio?

Start the program in debug mode: We have three ways to do so: 1> Press F11; 2> Click item “Run” in main menu then select “Debug” in the drop list; 3> Click the bug icon on the tools panel (as below picture shows) then select “Debug As Java Application”.


1 Answers

Download the Eclipse Dynamic Languages Toolkit - Ruby Development Tools. Import your ruby on rails project. Check that your Gemfile references:

gem 'ruby-debug'

Then go to windows -> preferences, and do two things:

  • setting the eclipse ruby interpreter to: c:\jruby\bin\jruby.bat

JRuby eclipse

  • setting the eclipse ruby debug engine so it's not the "fast debugger" but "ruby built-in debugger"

enter image description here

Then in the run configuration, main tab, under "ruby script" the launch script is bin/rails, and in the arguments tab server --debugger. The interpreter tab should point to JRuby.bat

Go to run -> run and give it about 30 seconds to load the JVM, the ruby environment, and hook everything in. Then check your http://localhost:3000/

To start debug execution then type debugger in the place you want to start the debugger.

It all starts off looking something like this:

Eclipse Ruby Debugger

like image 114
rupweb Avatar answered Oct 19 '22 05:10

rupweb