Posts tagged: debugging

Netbeans 6.9.1 and Ruby debugging

Some notes made while trying to get Netbeans 6.9.1 to debug Rails applications running on various Ruby stacks.

First and foremost, no success at all trying to use the Ruby debugging support internal to Netbeans with any combination of stacks based on Ruby MRI 1.8.6. Mind you, in every case, the code ran flawlessly under Netbeans, just not in debug mode.

When trying to run attaching the debugger to an external Ruby interpreter running in debug mode, success every time.

Combinations that were tried and succeeded. Others too numerous to mention failed somewhere along – compile, install, etc.

OS Ruby RubyGems ruby-debug-ide ruby-debug-base linecache
OS X 10.6.4 1.8.6 p111 1.0.1 0.4.4 0.10.3 0.3
OS X 10.6.4 1.8.6 p111 1.3.3 0.4.9 0.10.3 0.43
OS X 10.6.4 1.8.6 p111 1.3.5 0.4.9 0.10.3 0.43

No testing with Ruby debugging under jRuby in any combination. That’s yet to come.

A few conclusions (may be obvious to some!):

  • The combination of Ruby and RubyGems version is critical
  • It seems, after RubyGems 1.1 (more likely 1.2), the debug support stabilized
  • With RubyGems 1.3.x, the latest debug support is likely the best.

A final note, not particularly related to debugging, but rather to multiple Ruby platform support in Netbeans.

Using the same base version of Ruby for all the tests led to unmitigated user confusion when configuring the different stacks – Tools > Ruby Platforms.

An egregious hack that hasn’t appeared to hurt anything  is to manually edit the file ~/.netbeans/6.9/build.properties and add some text to the ruby_version tag for each different Ruby installation to differentiate one from another.

An example

In a console, run a command similar to:

rdebug-ide _0.4.9_ -p 7000 -d -- mongrel_rails start

Open the project in Netbeans, Debug > Attach Debugger and accept the defaults. Then use Netbeans debugging tools normally.

Ruby and Debugging

A small gathering of information about Ruby and debugging tools.

All debugging tools for Ruby ultimately exploit the same feature of Ruby – the ability of the Ruby interpreter to single-step through code and set breakpoints.  Usually, two pieces are involved – the copy of the Ruby interpreter running the Ruby code in debug mode and the program issuing debug commands (via an established interface).

Ruby comes with its own command-line debugger – rdebug. In this case, rdebug acts a shell that sends debug commands to the Ruby program executing in the same instance of Ruby. It involves a little trickery, but is no different in concept to any other debugging technique.

IDEs and other tools use essentially the same hooks, accessed through interfaces such as ruby-debug or ruby-debug-ide. In these cases, the IDE presents the source code and execution context of the program in a user-friendly fashion. When a user clicks on a breakpoint, or runs the program, the IDE sends an appropriate debug command to the Ruby interpreter running the application in debug mode.

When trying to understand why Ruby debugging sometimes doesn’t work, it helps to know that the following elements must all be in agreement:

  • The version of the OS
  • The Ruby interpreter and the debugging interface it makes available
  • The version of RubyGems
  • The library that provides ‘packaged’ access to the debugging interface (usually ruby-debug-ide or ruby-debug)
  • The implementation of the Ruby debug support in the IDE

There is no magic solution here – a lot of googling and trial and error.

An example

It is instructive to set up an IDE to debug Ruby externally, connect to a command-line instance of the program being debugged, and watch the debug console.

In a console window, in the directory containing the program, issue a command similar to:

rdebug-ide _0.4.9_ -p 7000 -d -- mongrel_rails start

In the IDE of choice,  open up the application and attach to the remote debugging session – in this case running on localhost on port 7000.

Issue breakpoints, run commands, variable inspections in the IDE and watch the activity in the console window.

Javascript Debugging

Advanced JavaScript Debugging Techniques provides a set of useful suggestions on Javascript debugging techniques.

An interesting note in one comment about a Javascript debugging environment for Windows – “If you are on MS Windows and need to debug javascript in Internet Explorer you should give a try to VWD (Visual Web Developer Express Edition).”

The JavaScript Source: Debugging Guide provides a list of common errors.

Firebug – Debugging Javascript

Firebug JavaScript Debugger and Profiler does a nice job of explaining basic debugging techniques for Javascript in Firebug. Remember to switch to the ‘Script’ tab.

Eclipse Remote Java Debugging

Remote Debugging with Eclipse – a good summary.

The VERY short version

For JVM invocation, add ‘-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=1044′

In Eclipse

  • Run > Debug Configurations > Remote Java Application
  • Host: localhost Port: 1044 (from command line above)
  • Save
  • Run – ignoring hot deploy errors (until I figure out the problem)

A little more

WordPress Themes