在Java中设置断点 [英] Setting breakpoints in Java

查看:316
本文介绍了在Java中设置断点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在Java中设置断点?
它只是基于源文件名和行号?类或方法名称也如图所示?

How does setting breakpoints in Java work? Is it just based on the source file name and line number? Does the class or method name also figure in?

如果我的调试器中有一个旧版本的源代码,并设置了断点,则当我逐步浏览时,光标关闭。它有多远?它可以进入错误的方法(甚至是错误的类,如果该文件中有多个类)?

If I have an old version of the source in my debugger and set a breakpoint, the cursor is off when I step through. How far off can it be? Can it go into the wrong method (or even the wrong class if there are more than one class in that file)?

当有多个类时,会发生什么JVM中的名称(如果您有多个类加载器可能会发生)?他们都得到断点?

What happens when there are multiple classes of the same name in the JVM (could happen if you have more than one classloader)? Do they all get the breakpoint?

在Web应用程序容器中,我可以为一个Web应用程序(而不是其他)设置断点吗?

In a web application container, can I set breakpoints for just one web application (and not the others)?

这是多少IDE是特定的,多少由JVM提供的调试接口确定?例如:在Eclipse中,我可以根据变量的值设置条件断点。这是否只是在JVM中的无条件断点上由Eclipse完成?

How much of this is IDE specific and how much is determined by the debugging interface that the JVM provides? For example: In Eclipse I can set conditional breakpoints based on the values of variables. Is that just filtering done by Eclipse on an unconditional breakpoint in the JVM?

推荐答案

有不同种类的断点。一些断点是基于行的,有的不是。如何影响您的实际调试取决于您的IDE实际做什么。例如,在Eclipse中,如果在方法中添加断点,那将是一个基于行的断点。如果在包含方法签名的行上添加断点,那将是一个方法入口断点。

There are different kind of breakpoints. Some breakpoints are line-based, some are not. How this affects your actual debugging depends on what your IDE actually does. For example, in Eclipse, if you add a breakpoint in the middle of a method, that will be a line-based breakpoint. If you add a breakpoint on a line containing the signature of a method, that will be a method entry breakpoint.

如果您正在查看的源代码不是正在运行的类的确切来源,线路断点不会映射到正确的线路上。所以java可能不会停止在你想要的行,你的IDE确实可以显示错误的方法,甚至错误的类。
但是方法条目断点仍然可以工作(在正确的时刻停止),即使定义了方法的行已经改变了;但是IDE可能会在调试器中显示错误的行。
(还有其他类型的事件/断点,像类加载,...你可以看一下 EventRequest 如果您想了解更多有关内部的内容)。

If the source code you're looking at is not the exact source of the class that is running, a line breakpoint won't be mapped onto the right line of course. So java might not stop at the line you intended, and your IDE indeed could be showing you the wrong method or even wrong class. But a method entry breakpoint will still work (stop at the right moment), even if the line on which the method was defined has changed; but again an IDE might show the wrong line in the debugger. (And there are other kind of events/breakpoints too, like class loading,... You could take a look at the subinterfaces of EventRequest if you want to know more about the internals).

要回答您的其他问题:断点适用于JVM中的所有类加载器。

To answer your other question: breakpoints apply to all classloaders in the JVM.

这篇关于在Java中设置断点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆