简体   繁体   English

使用Java源代码进行调试

[英]Debugging using Java source code

Is there a way to include whole Java source code into an eclipse project so the program is easier to debbug (eg by inserting println in methods you otherwise couldn't insert anything)? 有没有办法将整个Java源代码包含到eclipse项目中,从而使程序更容易调试(例如,通过在方法中插入println,否则将无法插入任何内容)?

I have a bug in my code. 我的代码中有错误。 But to better understand why the bug in my code appears, I'd like to see what intermediate results in some system method (on which use the bug occurs) are. 但是,为了更好地理解代码中的错误为什么会出现,我想看看某种系统方法(使用该错误的系统方法)产生了哪些中间结果。

For example, I'd like to know what JViewPort.scrollRectToVisible() exactly does and how my input behaves in it by printing out some intermediate results that occur in the method itself. 例如,我想通过打印出方法本身发生的一些中间结果来了解JViewPort.scrollRectToVisible()的确切功能以及我的输入在其中的行为。

EDIT: 编辑:

Instead of using JRE System Library X, I want to add the source code from JDK as if I had written the code myself. 我不想使用JRE System Library X,而是想从JDK添加源代码,就像我自己编写代码一样。 I want to be able to edit any System class just as I am able to edit any class I created myself. 我希望能够编辑任何系统类,就像我能够编辑自己创建的任何类一样。 I want editable .java files, not packed .jars... 我想要可编辑的.java文件,而不是压缩的.jars ...

You would need to add the 3rd-party library to your Eclipse workspace as an project. 您需要将第3方库作为项目添加到Eclipse工作区中。 (How you would do that depends on the code you are dealing with.) Once you have done that, you can hack your copy of the library to add trace prints etcetera. (如何执行操作取决于所处理的代码。)完成之后,您可以修改库的副本以添加跟踪打印等。

A better alternative is to simply attach the source code for the 3rd-party library so that the debugger can show you source as you step through the code, set breakpoints,. 更好的替代方法是简单地附加第三方库的源代码,以便调试器在逐步执行代码,设置断点时可以向您显示源代码。 Then use "advanced breakpoint" techniques instead of trace prints; 然后使用“高级断点”技术代替跟踪打印; eg http://www.vogella.com/articles/EclipseDebugging/article.html#advanced 例如http://www.vogella.com/articles/EclipseDebugging/article.html#advanced

Eclipse have built-in support for what you wanna do. Eclipse内置了对您想做的事情的支持。

All you have to do is set breakpoint and execute application in debugging mode. 您要做的就是设置断点并以调试模式执行应用程序。

Eclipse调试图标

You can use these icons in Eclipse debugging perspective. 您可以在Eclipse调试透视图中使用这些图标。

Follow along Eclipse Debugging Tutorial for details. 遵循Eclipse Debugging Tutorial以获得详细信息。

You cannot change the library code, but you can view it by using de-compiler . 您无法更改库代码,但可以使用de-compiler进行查看。 The max you can do is this. 您最大可以做的就是这个。 Now if you change any code in the libraries which you reached via the de-compiler, you would find an error stating " the integrity of the .jar package has changed which is not allowed " 现在,如果您更改了通过反编译器访问的库中的任何代码,则会发现错误,指出“ 不允许更改.jar软件包的完整性

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

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