简体   繁体   English

Eclipse在调试时跳过行

[英]Eclipse skipping lines while debugging

I am new to both java and eclipse, I have been trying to debug an android app on a device. 我是java和eclipse的新手,我一直在尝试在设备上调试Android应用程序。 It is a small project with a jar file reference. 这是一个带有jar文件引用的小项目。 I read similar questions but they didn't help. 我读了类似的问题,但他们没有帮助。

What I need is to be able to debug the source codes of the jar file so I attached the source codes ( which I obtained using a decompiler ) and I am able to go into source codes of the library so I thought I did that correctly. 我需要的是能够调试jar文件的源代码,所以我附上了源代码(我使用反编译器获得),我能够进入库的源代码,所以我认为我做得正确。 But I can not succeed in debugging into these source codes; 但我无法成功调试这些源代码; in debug mode it skipps breakpoints (only the ones in the source files which are attached to jar file) and when I try to 'step into code' it goes to random lines skips lines when debugging. 在调试模式下,它会跳过断点(只有源文件中附加到jar文件中的断点),当我尝试“进入代码”时,它会转到随机行,在调试时跳过行。

I am using the latest versions of eclipse, android sdk and jdk. 我使用的是最新版本的eclipse,android sdk和jdk。 I don't know what causes this problem and I'd like to know. 我不知道是什么导致了这个问题,我想知道。

Thanks in advance, I hope I explained sufficiently. 在此先感谢,我希望我能够充分解释。

The problem is, that you can't decompile the class files to debug it. 问题是,您无法反编译类文件以进行调试。 Because the lines of the decompiled files will differ to the original Java source code lines (imagine: the real source code has some comments and other things which will not be compiled into class files)! 因为反编译文件的行与原始Java源代码行不同(想象一下:真正的源代码有一些注释和其他不会编译成类文件的东西)!

So, if your Eclipse shows you the current debug line 42 , then it only tells you, that the debugger will present you the 42th line of code in the class file. 因此,如果您的Eclipse向您显示当前的调试行42 ,那么它只会告诉您调试器将在类文件中显示42th行代码。 This won't match your decompiled java source file. 这与您反编译的java源文件不匹配。

However, you could decompile the class files with the option add line numbers as comments . 但是,您可以使用选项添加行号作为注释来反编译类文件。 These line numbers in comments you can compare to the actual stacktrace line numbers. 注释中的这些行号可以与实际的堆栈跟踪行号进行比较。 This could help you a little bit to imagine the issue. 这可以帮助您想象一下这个问题。

edit: as Laurent B recommended, you will be able to realign the code with JD-Eclipse , see: http://mchr3k.github.io/jdeclipse-realign/ 编辑:正如Laurent B推荐的那样,您将能够使用JD-Eclipse重新调整代码,请参阅: http//mchr3k.github.io/jdeclipse-realign/

+1 for the comment! 评论+1! :) :)

edit2: You won't be able to decompile with line numbers if the class files are compiled with the flag -g:none : edit2:如果使用标志-g:none编译类文件,您将无法使用行号进行反编译:

-g:none -g:无
Do not generate any debugging information. 不要生成任何调试信息。

So if this is the case: try to find the original source code of your jar file! 因此,如果是这种情况:尝试找到jar文件的原始源代码!

A decompiler will not get the exact source code but will try to recreate it from the generated bytecode. 反编译器不会获得确切的源代码,但会尝试从生成的字节码重新创建它。

This is an entropic process so Decompile(Compile(Source)) will not output Source (you loose information) such as line number. 这是一个熵过程,所以Decompile(Compile(Source))不会输出Source(你松散的信息),比如行号。 That is why you will need the original source code. 这就是为什么你需要原始的源代码。 If you don't have it, you will have to use your immagination to be able to follow the code :) 如果你没有它,你将不得不使用你的想象力来遵循代码:)

EDIT : apparently some decompiler tools can do that for you as stated by bobbel. 编辑:显然一些反编译工具可以为你做,如bobbel所述。 see jdeclipse plugin . 看看jdeclipse插件

尝试按F6逐行调试代码

Decompiled source code sometimes acts like that. 经过反编译的源代码有时就像那样。 Unfortunately, the only solution for you is to stop debugging the jar and search the web for the source code and add it to your project. 不幸的是,唯一的解决方案是停止调试jar并在Web上搜索源代码并将其添加到项目中。

Its shows that the source file and Jar is not same. 它表明源文件和Jar不一样。 Try to get the right version of Source. 尝试获取正确的Source版本。

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

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