简体   繁体   English

Groovy / Grails代码的JDB调试

[英]JDB debugging of Groovy/Grails code

I'm attempting to debug some issues in some (rather bletcherous) Grails code that I inherited. 我试图在我继承的一些(而不是bletcherous)Grails代码中调试一些问题。 I'm a relative noob in Groovy and Grails although an old Java guy. 我是Groovy和Grails的亲戚,虽然是一个古老的Java家伙。

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. 这是问题所在:我运行了jconsole和jdb钩子,但很难使用调试器,因为大部分代码都在闭包中。 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. 作为一个闭包,名称(当调试器看到它​​时)是TheController.closure527(或类似的东西),并且特别难以找到。

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. 理想情况下,答案不会涉及转换到IntelliJ,好像上帝意味着我们使用IDE那样她不会给我们EMACS。

This isn't what you want to hear, but debugging is the only reason that I use intellij for my grails programming. 这不是你想听到的,但调试是我使用intellij进行grails编程的唯一原因。 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. 我能想到的最好的事情是编译代码并打开Class.closure123,然后通过javap和grep通过它们来管道它们以识别正确的闭包。 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. 我知道,粗暴。

使用Intellij,设置Eclipse或Emacs Keymap(或制作您自己的完美键盘图),享受21世纪:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM