Eclipse 条件断点被破坏?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10248795/
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
Eclipse Conditional Breakpoints Broken?
提问by kand
I am trying to set up a conditional breakpoint in decompiled code, but Eclipse keeps giving me the error:
我试图在反编译代码中设置条件断点,但 Eclipse 不断给我错误:
Conditional breakpoint has compilation error(s)
Reason: Evaluations must contain either an expression or a block of well-formed statments
条件断点有编译错误
原因:求值必须包含一个表达式或一个格式正确的语句块
My case is pretty simple, just trying to compare against a string value. I've tried all of the following and I get errors with every single one:
我的情况非常简单,只是尝试与字符串值进行比较。我已经尝试了以下所有方法,但每一个都出现错误:
myObj.toString() == "abc123"
myObj.toString().equals("abc123")
if(myObj.toString() == "abc123"){ return true; }
true == true
I've also tried every combination of having or not having a semicolon at the end of the line(s) and every combination of spacing and newlines and every combination of having or not having {} surrounding my condition. Basically, I have no idea why this isn't working...
我还尝试了在行尾有或没有分号的每一种组合,以及每一种间距和换行符的组合,以及每一种在我的条件周围有或没有 {} 的组合。基本上,我不知道为什么这不起作用......
The code I am trying to debug through is inside a jar that is decompiled with JD-Eclipse. Normal breakpoints work fine in this code.
我试图调试的代码位于用 JD-Eclipse 反编译的 jar 中。正常断点在这段代码中工作正常。
Does anyone know what's going on here???
有谁知道这里发生了什么???
回答by mazaneicha
This Eclipse FAQpage contains the syntax of proper CBP definition and most common reasons for them not to work. In your case, I think the following applies:
此Eclipse FAQ页面包含正确 CBP 定义的语法以及它们不起作用的最常见原因。在你的情况下,我认为以下适用:
This can happen if you are setting a breakpoint in a class whose class file does not contain a local variable table. For example, let's say you want to set a conditional breakpoint on Class.forName(String). If you have a source attachment for rt.jar the content assist will allow you to refer to the argument by its variable name, className. However, at debug runtime, the variable name will only be known if the class file contains a local variable table. Depending on the options used at compilation time, this information may have been stripped from the class file.
如果您在类文件不包含局部变量表的类中设置断点,就会发生这种情况。例如,假设您想在 Class.forName(String) 上设置一个条件断点。如果您有 rt.jar 的源附件,内容帮助将允许您通过其变量名称 className 来引用参数。但是,在调试运行时,仅当类文件包含局部变量表时才知道变量名称。根据编译时使用的选项,此信息可能已从类文件中删除。
JD may have fabricated variable names while decompiling your jar, so using "myObj" in conditional expression produces a compile-time error.
JD 可能在反编译 jar 时伪造了变量名,因此在条件表达式中使用“myObj”会产生编译时错误。
回答by Keith Amling
Maybe conditional breakpoints are less than working in general. Consider, for example:
也许条件断点比一般的工作少。考虑,例如:
回答by Mumrah
It may be a bug in eclipse. What eclipse does is weave a new method or some such into the source for the file you set the breakpoint in and compile it up. If something goes wrong in this process your conditional breakpoint will mysteriously fail.
这可能是eclipse中的一个错误。eclipse 所做的是将一个新方法或一些类似的方法编织到您设置断点的文件的源代码中并编译它。如果在此过程中出现问题,您的条件断点将神秘地失败。
You could follow the approach I used below, running eclipse in debug to try and track down the problem:-
您可以按照我在下面使用的方法,在调试中运行 eclipse 以尝试追踪问题:-
回答by ATrubka
In case of "true == true" condition you should just add return statement:
在“true == true”条件的情况下,您应该只添加 return 语句:
return true == true;
For the rest of the problems missing local variable table should be the explanation. +1 to Mazaneicha for that.
对于缺少局部变量表的其余问题应该是解释。为此向 Mazaneicha +1。
回答by ATrubka
In case of "true == true" condition you should just add return statement:
在“true == true”条件的情况下,您应该只添加 return 语句:
return true == true;
For the rest of the problems missing local variable table should be the explanation. +1 to Mazaneicha for that.
对于缺少局部变量表的其余问题应该是解释。为此向 Mazaneicha +1。
If you're trying to refer a method argument by its name then just try to change the name to "arg0", "arg1", etc.
如果您尝试通过名称引用方法参数,则只需尝试将名称更改为“arg0”、“arg1”等。
For instance, you can do like this:
例如,你可以这样做:
arg0 == null
It's easy to guess the variable name. Just put uncondidtional breakpoint and see the list of variables in the Variables view.
很容易猜出变量名。只需放置无条件断点并查看变量视图中的变量列表。
回答by Iwan Satria
Just adding up what might help others as I have just solved this after some time. I am using JD-Eclipse for debugging, too, when I get this problem.
只是添加可能对其他人有帮助的东西,因为我在一段时间后刚刚解决了这个问题。当我遇到这个问题时,我也在使用 JD-Eclipse 进行调试。
Make sure that all the necessary jar files are in Classpath. Your conditional statement may be very simple, such as "return true"; but once the "conditional breakpoint" checkbox is checked, it could be that (I can't be sure either) Eclipse debugger will check that Eclipse project's classpath against the larger scope and not just that "return true" line.
确保所有必需的 jar 文件都在 Classpath 中。你的条件语句可能很简单,比如“return true”;但是一旦“条件断点”复选框被选中,它可能是(我也不能确定)Eclipse 调试器将检查 Eclipse 项目的类路径针对更大的范围,而不仅仅是“返回真”行。
Since I'm using JD-Eclipse, I didn't bother to add all the necessary jar files. The problem was solved after I added the jar files in the project's classpath
因为我使用的是 JD-Eclipse,所以我没有费心添加所有必要的 jar 文件。我在项目的classpath中添加jar文件后问题解决
If you're using remote debugging, you can also try to configure so that your Eclipse project's JDK is compatible with target JVM's JRE.
如果您使用远程调试,您还可以尝试进行配置,以便您的 Eclipse 项目的 JDK 与目标 JVM 的 JRE 兼容。