How to fix breakpoint error when debugging in Eclipse?

China☆狼群 提交于 2020-01-04 02:06:46

问题


Need to debug a JAR file "ProA", so import the source code in the project, but there is a strange error in Eclipse while trying to set a breakpoint. Detail as below:

Unable to install breakpoint due to missing line number attributes.
Modify compiler options to generate line number attributes.

I have try to several method to solve, but failed.

  1. Under Window > Preferences: Java > Compiler > Classfile Generation, all options have to be to True
  2. In .settings folder of your project, look for a file called org.eclipse.jdt.core.prefs. Verify or set org.eclipse.jdt.core.compiler.debug.lineNumber=generate
  3. Add the debug=true flag in the build.xml, just like this: <javac srcdir="./src/java" destdir="./bin" debug="true">

Any help will be appreciated.


回答1:


I have had the same problem, but reading your post helped me resolve mine. I changed org.eclipse.jdt.core.prefs as follow:

BEFORE:

eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
org.eclipse.jdt.core.compiler.compliance=1.7
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.source=1.7

AFTER:

eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.7
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.source=1.7

Another way to modify these options within the Project> Properties> Java Compiler. So, there is no need to modify manually the org.eclipse.jdt.core.prefs file. There you need to make sure that the Classfile Generation options are checked.




回答2:


In the JAR the line number attributes are missing in the compiled bytecode. With the added source code Eclipse knows the line numbers, but not the Java VM that executes the bytecode and does not see the source code.

It would be useless if Eclipse told the Java VM to stop at a specific line, because the Java VM does not know which command is in which line and so when to stop.

The only solution is to recreate the JAR or at least the bytecode (.class files) with line information of the class(es) where you want to set a breakpoint.



来源:https://stackoverflow.com/questions/20344230/how-to-fix-breakpoint-error-when-debugging-in-eclipse

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!