Eclipse - 调试器不会在断点处停止
我正在尝试对 JUnit 进行故障排除。在源代码中,我在两个位置设置了断点:1)在初始化静态成员的行中2)其中一个测试用例的第一行。
调试器在静态字段初始化行停止。但它并不止于测试用例。无论我在测试用例中的何处设置断点,调试器都不会在那里停止。我确信测试用例已执行,因为我可以看到我添加的日志消息出现在日志中。
任何帮助将不胜感激。
我正在使用 Eclipse Galileo 和 JUnit4 启动器。
I am trying to trouble shoot a JUnit. In the source code, I have set break point in two places: 1) in a line where a static member is initialized 2) the first line of one of the test cases.
The debugger stops in the static field initializing line. But it doesn't stop in the test case. No matter where I set the break point in the test case, the debugger doesn't stop there. I know for sure that the test case is executed as I can see the log messages that I have added appear in the log.
Any help would be greatly appreciated.
I am using Eclipse Galileo and JUnit4 launcher.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(23)
修复可能就像单击运行/跳过所有断点一样简单。为我工作。
Fix could be as simple as clicking run/skip all breakpoints. Worked for me.
确保在“运行”>下调试配置,选择“在主程序中停止”(如果适用于您的情况)。
Make sure, under Run > Debug Configurations, that 'Stop in main' is selected, if applicable to your situation.
这可能与 JDK 6 Update 14 中的错误之一有关,如中所示JDK 6 update 15 的发行说明。
如果这确实是问题所在,您应该迁移到更高版本的 JDK(但这并不能保证,因为 针对 6u16、6u18 和 7b1 的修复已发布)。最好的选择是使用 -XX:+UseParallelGC 标志。增加最小和最大堆大小,以延迟第一次GC,带来暂时的缓解。
顺便说一下,使用Eclipse 中的此错误报告来跟踪其他人的情况一直在进展。
This could be related to one of the bugs in JDK 6 Update 14, as indicated in the release notes for JDK 6 update 15.
If this indeed turns out to be the issue, you should move to a higher version of the JDK (that's no guarantee though, since fixes have been released against 6u16, 6u18 and 7b1). The best bet is to use -XX:+UseParallelGC flag. Increasing the size of the minimum and maximum heap size, to delay the first GC, bring temporary relief.
By the way, use this bug report in Eclipse to track how others have been faring.
您可能不小心跳过了 Eclipse 工具栏中的所有断点。要解决此问题,请转到 Eclipse ->运行->跳过所有断点。
You might have accidentally skipped all break points in Eclipse toolbar. To fix this go to Eclipse -> Run -> Skip All Breakpoints.
通常,当这种情况发生在我身上时(很少见,但确实如此)意味着正在执行的代码与编辑器中的代码不同。 Eclipse 时常会出现构建的类与编辑器中的代码不同步的情况。当这种情况发生时,我会得到各种奇怪的调试器行为(调试空行、跳过代码行等)。
重新启动 Eclipse、清理所有项目并重建所有内容通常可以解决问题。我还有 Maven 插件(旧版本……有一段时间没有使用它了),它也有这样做的倾向。
否则它可能是一个错误,也许是 Vineet 所说的,
希望这会有所帮助
Usually when this happens to me (rare but it does) means that the code being executed is different than the code in the editor. It will happen from time to time for Eclipse that the built classes and the code in editor are out of sync. When that happens I get all sort of weird debugger behavior (debugging empty lines, skipping lines of code etc).
Restarting Eclipse, clean all projects and rebuild everything usually clears things up. I had also the Maven plugins (older versions... had not had it for a while now) that had a tendency to do that too.
Otherwise it might be a bug, maybe the one Vineet stated,
Hope this helps
就我而言,问题是我没有在调试视角中打开调试视图,因此:
1 - 确保已打开调试视角:
2 - 确保已打开调试视图:
< a href="https://i.sstatic.net/f5qIj.png" rel="nofollow noreferrer">
In my case the problem was that I hadn't Debug view open in Debug perspective, so:
1 - Be sure you have debug perspective opened:
2 - Be sure you have debug view opened:
项目-> Clean 似乎在 JRE 8 上对我有用
Project -> Clean seemed to work for me on on JRE 8
为了使调试器能够远程工作,必须将 java .class 文件与调试信息一起编译。如果将“-g:none”选项传递给编译器,则类文件将没有必要的信息,因此调试器将无法将源代码上的断点与远程中的该类进行匹配。同时,如果 jars/class 文件被混淆,那么它们也不会有任何调试信息。根据您的回复,很可能这不是您的情况,但此信息可能对面临相同问题的其他人有用。
In order to debugger work with remote, the java .class files must be complied along with debugging information. If "-g:none" option was passed to compiler then the class file will not have necessary information and hence debugger will not be able to match breakpoints on source code with that class in remote. Meanwhile, if jars/class files were obfuscated, then they also will not have any debug info. According to your responses, most probably this is not your case, but this info could be useful for others who face the same issue.
删除所有断点并重新添加它们。
Remove all breakpoints and re-add them.
对于JDK7,运行->调试配置,勾选“调试时在测试运行后保持JUnit运行”。
For JDK7, run->Debug Configurations, check "Keep JUnit running after a test run when debugging".
我曾经遇到过一次,当时我取消选中“运行>自动构建”并忘记重新检查它。
Happened to me once, when I had unchecked "Run > Build automatically" and forgot to re-check it.
确保在顶部声明该包。
在我的常规代码中,这在断点处停止:
这不会在断点处停止:
Make sure you declare the package at the top.
In my groovy code this stops at breakpoints:
This does not stop at breakpoints:
要删除断点:
To remove the breakpoints:
还要验证其他行上的断点是否有效,这可能是调试器中的错误。我在使用 Eclipse 调试器时遇到了问题,在布尔赋值上放置断点(其代码位于下一行)不起作用 我在这里报告了这一点,但将其放在上一行或下一行中确实如此。
Also verify if breakpoints on other lines DO work, it may be a bug in the debugger. I have had a problem with the Eclipse debugger where putting a breakpoint on a boolean assignment whose code was on the next line didn't work I reported this here, but putting it on the previous or next line did.
如果不起作用 -
If nothing works-
另一个可能的问题是调试器端口可能被防火墙阻止。例如,我使用的是 mule anypoint studio(v 5.4.3)。默认调试器端口为 6666。执行流程时,不会在断点处停止。当我将端口更改为另一个端口(例如8099)时,它工作正常。
Another possible problem is that the debugger port may be blocked by the firewall. For example, I was using mule anypoint studio (v 5.4.3). The default debugger port is 6666. When a flow is executed, it would not stop at breakpoint. when I changed the port to another (e.g. 8099), it worked fine.
进入
右键->调试配置
,检查是否创建了过多的调试实例。当我从配置中删除多个调试实例并重新开始调试时,我的问题得到了解决。
Go to
Right click->Debug Configuration
and check if too many debug instances are created.My issue was resolved when i deleted multiple debug instances from configuration and freshly started debugging.
如果您使用的是 Eclipse,
请右键单击“Package Explorer”下的项目文件夹。
转到源 ->清理并选择您的项目。
这将清理所有混乱,并且您的断点现在应该可以工作。
If you are on Eclipse,
Right click on your project folder under "Package Explorer".
Goto Source -> Clean up and choose your project.
This will cleanup any mess and your break-point should work now.
创建一个新的工作空间对我来说很有效。
Creating a new workspace worked for me.
就我而言,我在同一个工作区中有多个项目。我试图调试的 java 文件存在于多个具有相同包的项目中。
我不需要其他项目,因此只需关闭不相关的项目(或从不相关的项目中删除文件)。
In my case I had multiple projects in same workspace. The java file I was trying to debug was present in more than one projects with same package.
I didn't need the other project, so simply closed unrelated projects (or remove the file from unrelated project).
关于 Vineet Reynolds 回答的另一条评论。
我发现我必须在 eclipse.ini 中设置 -XX:+UseParallelGC
我按如下方式设置虚拟机 (vm) 参数
来解决该问题。
One additional comment regarding Vineet Reynolds answer.
I found out that I had to set
-XX:+UseParallelGC
ineclipse.ini
I setup the virtual machine (vm) arguments as follows
that solved the issue.
当我有几个项目时,我意识到我从项目 A 创建了项目 B 的 Spring Boot 配置(我单击“复制”并更改参数以获取项目 B 的配置),在这种情况下,我没有调试模式,所以我删除了这个配置,并通过在 Spring Boot 应用程序中单击“新建”直接创建了一个新配置
It happened to me when I had several project, I realized that I created a spring boot configuration of a project B from a project A (I clicked on Duplicate and change the parameter to have a config for the project B) and in that case I haven't the debug mode so I removed this config and I created directly a new one by clicking New in Spring Boot App
这对我有用:
我必须将本地服务器地址放入 PHP 服务器 配置中,如下所示:
注意:该地址是我在 Apache .conf 文件中配置的地址。
注意:唯一有效的断点是“第一行中断”,之后断点就不起作用了。
注意:检查 php.ini 文件中的 xdebug 属性,并删除您认为不需要的任何属性。
This is what works for me:
I had to put my local server address in the PHP Server configuration like this:
Note: that address, is the one I configure in my Apache .conf file.
Note: the only breakpoint that was working was the 'Break at first line', after that, the breakpoints didn't work.
Note: check your xdebug properties in your php.ini file, and remove any you think is not required.