Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JDB debugging of Groovy/Grails code

I'm attempting to debug some issues in some (rather bletcherous) Grails code that I inherited. I'm a relative noob in Groovy and Grails although an old Java guy.

Here's the problem: I have this thing running with jconsole and jdb hooks in, but it's tough to use the debugger because so much of the code is in closures. So, for example,

def niftyMethod = {
    // do something nifty
    anObject.doSomethingThatBreaks()
}

as the implementation of a single method on a controller.

Being a closure, the name (by the time the debugger sees it) is TheController.closure527 (or something like that), and notably hard to find.

So, how can one find the map from the block name to the closure?

More generally, are there any good tutorials on doing this sort of thing?

Ideally the answer won't involve changing over to IntelliJ, as if God had meant us to use IDEs like that She wouldn't have given us EMACS.

like image 328
Charlie Martin Avatar asked Oct 15 '22 00:10

Charlie Martin


1 Answers

This isn't what you want to hear, but debugging is the only reason that I use intellij for my grails programming. If it were easy to do what you're asking, I'd leave it for a better editor. The weak, non-standard key bindings drive me crazy, but sometimes debugging is the best way to find the problem.

The best thing that I can think of is to compile the code and open up the Class.closure123 then pipe them through javap and grep through them to identify the right closure. Painful, but I'm not sure there's a better way.

Alternatively, you could throw an exception from the code, look at the stack trace and then find the right underlying class from there.

I know, gross.

like image 127
Ted Naleid Avatar answered Oct 27 '22 01:10

Ted Naleid