Groovy/Grails 代码的 JDB 调试
我正在尝试调试我继承的一些(相当糟糕的)Grails 代码中的一些问题。虽然我是一个 Java 老手,但在 Groovy 和 Grails 方面我还是一个相对菜鸟。
问题是:我用 jconsole 和 jdb 挂钩运行这个东西,但是很难使用调试器,因为很多代码都在闭包中。例如,
def niftyMethod = {
// do something nifty
anObject.doSomethingThatBreaks()
}
作为控制器上单个方法的实现。
作为一个闭包,名称(当调试器看到它时)是 TheController.closure527 (或类似的东西),并且特别难以找到。
那么,如何找到从块名称到闭包的映射呢?
更一般地说,有关于做这类事情的好的教程吗?
理想情况下,答案不会涉及转向 IntelliJ,就好像上帝想让我们使用这样的 IDE,她不会给我们 EMACS。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这不是您想听到的,但调试是我使用 intellij 进行 grails 编程的唯一原因。如果很容易做到你所要求的,我会把它留给更好的编辑。弱的、非标准的按键绑定让我发疯,但有时调试是发现问题的最好方法。
我能想到的最好的事情是编译代码并打开 Class.closure123 然后通过 javap 和 grep 通过它们来识别正确的闭包。痛苦,但我不确定是否有更好的方法。
或者,您可以从代码中抛出异常,查看堆栈跟踪,然后从那里找到正确的基础类。
我知道,恶心。
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.
使用 Intellij,设置 Eclipse 或 Emacs 键盘映射(或制作您自己的完美键盘映射),享受 21 世纪:)
Use Intellij, set the Eclipse or Emacs Keymap (or make your own perfect keymap), and enjoy the 21st century :)