为什么我的 Eclipse 项目有幻像调试器断点?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/723199/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Why does my Eclipse project have phantom debugger breakpoints?
提问by skiphoppy
I've got a small project which, when run in the Eclipse debugger, always seems to stop in FileInputStream.class line 106, where files are opened. There are no breakpoints set, but Eclipse behaves exactly as if I have a breakpoint here. If I clear all breakpoints, it still happens.
我有一个小项目,当在 Eclipse 调试器中运行时,它似乎总是停在 FileInputStream.class 第 106 行,在那里打开文件。没有设置断点,但 Eclipse 的行为就像我在这里设置了断点一样。如果我清除所有断点,它仍然会发生。
I have a second much-larger project in the same Eclipse workspace which does not suffer from this problem.
我在同一个 Eclipse 工作区中有第二个更大的项目,它没有遇到这个问题。
I just moved the smaller project off of my old Linux machine, where I developed it in Europa Eclipse and had this problem, onto my new Windows machine, where I continue to see the problem in Ganymede Eclipse. The problem persists across operating systems and across Eclipse versions, yet apparently not across projects. I don't get it! I grepped through every file in this project's directory and couldn't find anything that might be a file somehow directing Eclipse to stop in FileInputStream.
我只是将较小的项目从我在 Europa Eclipse 中开发并遇到这个问题的旧 Linux 机器上移到我的新 Windows 机器上,在那里我继续在 Ganymede Eclipse 中看到问题。该问题在跨操作系统和跨 Eclipse 版本中仍然存在,但显然不是跨项目。我不明白!我搜索了该项目目录中的每个文件,但找不到任何可能以某种方式指示 Eclipse 停止在 FileInputStream 中的文件。
Further info: the apparent breakpoint is actually not for line 106 of FileInputStream; it appears to be an Exception breakpoint for FileNotFoundException, being thrown from native code called from that line in FileInputStream. But again, I don't appear to have any breakpoints set at all. Are Exception breakpoints defined somewhere else?
更多信息:明显的断点实际上不是 FileInputStream 的第 106 行;它似乎是 FileNotFoundException 的异常断点,是从 FileInputStream 中该行调用的本机代码抛出的。但同样,我似乎根本没有设置任何断点。异常断点是否在其他地方定义?
回答by VonC
Did you try to un-select
您是否尝试取消选择
Window > Preferences > Java > Debug : Suspend execution on uncaught exceptions
? (as mentioned in this thread, for instance)
? (例如在这个线程中提到的)
Why does Eclipse work that way?
为什么 Eclipse 会这样工作?
It goes back to 2002, when the breakpoint object hierarchy has been stripped down.
它可以追溯到 2002 年,当时断点对象层次结构已被剥离。
In order to set a breakpoint, with the old API, a client required Java Model Objects - such as
IType
,IField
, etc.
With the new API, all that is required by the debug model is type names, field names, etc.This allows clients to set breakpoints when Java Model Objects are not available.
Clients now specify the resource to associate a breakpoint with (before we constrained it to the associated Java Model resources).Breakpoints can now also be "hidden". That is, they need not be registered with the breakpoint manager.
Breakpoints can also be selectively persisted (markers only allowed all/none of a marker type to be persisted).
This makes the debug model more flexible, and gives clients more building blocks.This has also simplified some part of our Java debug implementation - for example, the feature "
suspend on any uncaught exception
", simply sets a breakpoint for the type named "java.lang.Throwable
", rather than a specificIType
in a specific project.
The breakpoint is not registered with the breakpoint manager (i.e. hidden) - it is only known and used by one client.
Another example is the "run to line breakpoint
". TheIJavaRunToLineBreakpoint
has been removed, as its special functionality is no longer required. Now, the Java debug ui simply creates a "line breakpoint" that is hidden, non persisted, and has a hit count of 1. This is an example of providing building blocks to clients.
为了设置一个断点,与旧的API,客户端所需的Java模型对象-比如
IType
,IField
等
有了由调试模型所需的新的API,所有的类型名,字段名等。这允许客户端在 Java 模型对象不可用时设置断点。
客户端现在指定要与断点关联的资源(在我们将其限制为关联的 Java 模型资源之前)。现在也可以“隐藏”断点。也就是说,它们不需要在断点管理器中注册。
断点也可以有选择地保留(标记只允许保留所有/全部标记类型)。
这使得调试模型更加灵活,并为客户提供更多构建块。这也简化了我们的 Java 调试实现的某些部分——例如,特性“
suspend on any uncaught exception
”,只是为名为“java.lang.Throwable
”的类型设置断点,而不是IType
特定项目中的特定类型。
断点没有在断点管理器中注册(即隐藏)——它只被一个客户端知道和使用。
另一个例子是“run to line breakpoint
”。在IJavaRunToLineBreakpoint
已被删除,因为它的特殊功能,不再需要。现在,Java 调试 ui 只是创建一个隐藏的、非持久化的、命中数为 1 的“行断点”。这是向客户端提供构建块的示例。
回答by Mark Scheel
I had a similar problem but the accepted solution did not work for me. I am doing Eclipse Android development and had set some breakpoints and later unset them. Even though I disabled them Eclipse kept stopping execution at these phantom breakpoints. The solution for me was to open the Breakpoints window:
我有一个类似的问题,但接受的解决方案对我不起作用。我正在做 Eclipse Android 开发,并设置了一些断点,后来取消了它们。即使我禁用了它们,Eclipse 仍然会在这些幻像断点处停止执行。我的解决方案是打开断点窗口:
Window > Show View > Other...
窗口 > 显示视图 > 其他...
Debug > Breakpoints
调试 > 断点
Then right click any breakpoint and select "Remove All"
然后右键单击任何断点并选择“全部删除”
Unfortunately you have to reset all your valid breakpoints, but this worked for me and has prevented much angst and frustration going forward.
不幸的是,您必须重置所有有效断点,但这对我有用,并且避免了很多焦虑和沮丧。
Some pictures to guide others:
一些图片来指导他人:
回答by HAL9000
For those who don't find other solutions useful, I found my personal solution to my problem. I work with a .jar library which is generated by building another project into the workspace. If I set a breakpoint in a .java into the library project, then the breakpoint will be triggered when debugging the final project. However when debugger pauses the execution the .class file is shown which has its own breakpointsand therefore the breakpoint set into the .java file is not shown here!
对于那些没有发现其他解决方案有用的人,我找到了我个人的问题解决方案。我使用一个 .jar 库,该库是通过将另一个项目构建到工作区中而生成的。如果我在.java 中设置断点到库项目中,那么在调试最终项目时会触发断点。但是,当调试器暂停执行时,会显示 .class 文件,该文件具有自己的断点,因此此处未显示设置到 .java 文件中的断点!
Solution:In order to remove the breakpoint you have to remove the breakpoint into the .java file, in the library project.
解决方案:为了删除断点,您必须将断点删除到库项目中的 .java 文件中。
回答by javagrendel
I ran into an issue where a source file had persistent markers for breakpoints that didn't exist. I tried cleaning the project, doing a full build, restarting Eclipse - nothing worked.
我遇到了一个问题,其中源文件具有不存在的断点的持久标记。我尝试清理项目,进行完整构建,重新启动 Eclipse - 没有任何效果。
I went digging through the Eclipse metadata, and found the projects .markers file. Deleting that file finally fixed the issue.
我深入研究了 Eclipse 元数据,找到了项目 .markers 文件。删除该文件最终解决了问题。
For anyone else having this issue, open your workspace directory, then navigate to .metadata/.plugins/org.eclipse.core.resources/.projects/your project, then rename/remove file .markers.
对于遇到此问题的其他人,请打开您的工作区目录,然后导航到 .metadata/.plugins/org.eclipse.core.resources/.projects/您的项目,然后重命名/删除文件 .markers。
For example, if your workspace folder is ~/workspace, and your project is named Foo, you could do:
例如,如果您的工作区文件夹是 ~/workspace,并且您的项目名为 Foo,您可以执行以下操作:
$ mv ~/workspace/.metadata/.plugins/org.eclipse.core.resources/.projects/Foo/.markers ~/safe.Foo.markers
回答by Christopher
For those who didn't find a solution from the previous answers, they can try what solved my problem. It is I think similar to HAL9000 problem/solution
对于那些没有从以前的答案中找到解决方案的人,他们可以尝试解决我的问题的方法。我认为类似于 HAL9000 问题/解决方案
If you have two classes with the same name (in two different projects) the breakpoints on the one, apply on the other one as well. Both of them show in the "Breakpoints" window.
如果你有两个同名的类(在两个不同的项目中),一个上的断点,也适用于另一个。它们都显示在“断点”窗口中。
Solution: If you remove the breakpoint from the class - with the same name - that you are not using it removes the breakpoint from the class you are debugging.
解决方案:如果您从类中删除断点 - 具有相同的名称 - 您没有使用它,则会从您正在调试的类中删除断点。