简体   繁体   English

如何在ECLIPSE中调试.class文件?

[英]How to debug .class files in ECLIPSE?

I am using Eclipse 3.5 and I attached the src.zip to my global settings in Eclipse. 我正在使用Eclipse 3.5,并将src.zip附加到Eclipse中的全局设置。 Windows--> Preferences -->Java -->Installed JREs -->rt.jar - Source attachment - ...../jdk/src.zip Windows - >首选项 - > Java - >已安装的JRE - > rt.jar - 源附件 - ..... / jdk / src.zip

I am successfully able to step in the java core library .class files and view the source code. 我成功地能够进入java核心库.class文件并查看源代码。 I building a Class which uses the LinkedList and I have set a breakpoint inside the LinkedList class. 我构建一个使用LinkedList的类,我在LinkedList类中设置了一个断点。

When I debug the breakpoints in my source code (my projects) are working good but when I need to step into the java core lib .classes I get the following error in my Eclipse 当我调试源代码中的断点(我的项目)工作正常但是当我需要进入java核心库.classes时,我在Eclipse中遇到以下错误 日食错误

Unable to install breakpoint in java.util.LinkedList due to missing line Number attributes. 由于缺少行号属性,无法在java.util.LinkedList中安装断点。 Modify complier options to generate line number attributes. 修改编译器选项以生成行号属性。

I checked my complier settings in Preferences and found all options checked true. 我在Preferences中检查了我的编译器设置,发现所有选项都选中了true。 在此输入图像描述 It would to great if someone can help me resolve this issue. 如果有人可以帮我解决这个问题,那就太好了。

Thanks in advance. 提前致谢。

You may have the compiler set to include debugging information in YOUR class files, but the class files in rt.jar weren't compiled that way. 您可能将编译器设置为在您的类文件中包含调试信息,但是rt.jar中的类文件没有以这种方式编译。 You need to either recompile all the source for the classes in rt.jar (not for the faint of heart), or download a debug build of the jdk . 您需要重新编译rt.jar中的类的所有源代码(不适合胆小的人),或者下载jdk的调试版本

This blog posts give a comprehensive list of points to check 博客文章提供了要检查的全面点列表

Follow the steps if you are compiling using Eclipse IDE 如果使用Eclipse IDE进行编译,请执行以下步骤

在此输入图像描述

  1. Go to windows > preferences > Java > compiler screen. 转到windows > preferences > Java > compiler屏幕。
  2. Make sure that add line number attributes to generated files (used by debugger) check box is checked. 确保选中向生成的文件添加行号属性(由调试器使用)复选框。
  3. Build again and try adding a breakpoint ahd hope it should work for you. 再次构建并尝试添加断点啊希望它应该适合你。

Note for ant builds 蚂蚁构建的注释

Follow the steps if you are compiling using ANT utility: 如果使用ANT实用程序进行编译,请按照以下步骤操作:

  1. Check the build.xml file and make sure that debug attribute is set to true in javac task 检查build.xml文件并确保在javac任务中将debug属性设置为true
  2. Also, if you are using JBoss as an app server, then make sure that you have already opened a port for socket binding of remote machine connection. 此外,如果您使用JBoss作为应用服务器,那么请确保您已经为远程机器连接的套接字绑定打开了一个端口。 If not then just ensure that C:/jboss/bin/run.bat has an entry with: 如果没有,那么只需确保C:/jboss/bin/run.bat有一个条目:
    " set JAVA_OPTS=%JAVA_OPTS% -Xdebug –Xrunjdwp:transport=dt_socket,address=5000,server=y,suspend=n " for opening port 5000 to listen all socket connections for debug/remote java application. set JAVA_OPTS=%JAVA_OPTS% -Xdebug –Xrunjdwp:transport=dt_socket,address=5000,server=y,suspend=n ”,用于打开端口5000以侦听调试/远程Java应用程序的所有套接字连接。
  3. Build again and try adding a breakpoint ahd hope it should work for you. 再次构建并尝试添加断点啊希望它应该适合你。

You should not use a JRE with a JDR src attached as the JRE classes are not well suited for debugging. 您不应该使用附加了JDR src的JRE,因为JRE类不适合调试。

Let Eclipse search for Java environments and then select the JDK from the resulting list. 让Eclipse搜索Java环境,然后从结果列表中选择JDK。 This Java environment will have the src.zip attached correctly and you should be able to investigate. 这个Java环境将正确附加src.zip,您应该能够进行调查。

Note that even JDK classes do not have full debugging information available, so you cannot see local variables etc. 请注意,即使JDK类也没有完整的调试信息,因此您无法看到局部变量等。

(Also, the Compiler settings panel only applies to your code. The JRE classes are pregenerated and the panel does not influence them). (另外,“编译器设置”面板仅适用于您的代码。预生成JRE类,面板不会影响它们)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM