How to debug compiled Java code in Eclipse [closed]
Asked Answered
R

8

38

I wonder if there are any solutions for Eclipse IDE to debug Java code for which I have no source, i.e. to debug dynamically decompiled code, step through it, etc.? I tried to use JD-Eclipse, JadClipse, and these plug-ins work great if I want to look at some class files, but as I debug, I get "Source not found." - how can I "attach" these plug-ins to "provide" source?

My environment:

  • Eclipse 3.5
  • Windows XP (but I look for a cross platform solution, if possible)

Thank you.

Rondeau answered 15/12, 2009 at 6:2 Comment(3)
If you decompiled can you not compile it back with -g and go about debugging as would your own source code.Thremmatology
Would recompiling decompiled source result in exactly the same class files? I would think not. But if the OP can replace the class files with their own, then I suppose this is workable.Jocular
Note that IntelliJ 14+ has a decompiler built in.Manhole
O
13

I have good experience with Jadclipse - http://jadclipse.sourceforge.net/wiki/index.php/Main_Page - there is an update site at http://jadclipse.sf.net/update

For best results, use jad and configure it to list line numbers as comments which will enable the output where the code is on the correct line. This is best for debugging sessions.

Then set it to be the default view for classes. See the documentation for details. This works well for me.

Oidea answered 15/12, 2009 at 9:47 Comment(4)
Well, this approach is most suitable - it seems to work (decompiles Java classes on the fly, shows source while debugging). Seems that I was on a good way, but missed to restart Eclipse few times. It would be perfect if all lines of decompiled file would match, because now I get manny MISALIGNED.Rondeau
Agree, but jad is not open source and the author seems to have abandoned it. Hopefully the new decompilers supported by jadclipse will eventually be even better than jad.Manhole
The MISALIGNED is due to the way that jad creates the decompiled source. I believe it writes serially, and cannot move back and forth to place things better.Manhole
@tori, note I've found there to be less misaligned if the { and } are placed on the same line instead of next line. Check jadclipse configuration panel.Manhole
C
15

I have the same problem. Today, no decompilers are efficent to debug compiled Java code. I'm working on JD-Eclipse. In the next 3 to 6 months, the layout of JD-Eclipse should be really improved. We will start to debug classes without sources and solve some intractable problems.

Cynical answered 22/12, 2009 at 19:21 Comment(4)
@Emmanuel Dupuy: any progress on "debug classes without sources" ?Leash
@Leash The realignment algorithm is ready. You can test it here: java.decompiler.free.fr/?q=preview. Its integration into JD-Eclipse will take some months. It is resonable to say that it will be ready in december. Currently, JD-you-can use Eclipse + the extension of Alex Kosinsky: sourceforge.net/projects/realignmentjdCynical
Also, github.com/mchr3k/jdeclipse-realign is a fork of Alex's work which provides a nice way to toggle between decompiled class files and attached source; worked great for me with eclipse 3.7 & java 6 - makes debugging without source so much easier!Unshapen
Any progress on JD-Eclipse?Soften
O
13

I have good experience with Jadclipse - http://jadclipse.sourceforge.net/wiki/index.php/Main_Page - there is an update site at http://jadclipse.sf.net/update

For best results, use jad and configure it to list line numbers as comments which will enable the output where the code is on the correct line. This is best for debugging sessions.

Then set it to be the default view for classes. See the documentation for details. This works well for me.

Oidea answered 15/12, 2009 at 9:47 Comment(4)
Well, this approach is most suitable - it seems to work (decompiles Java classes on the fly, shows source while debugging). Seems that I was on a good way, but missed to restart Eclipse few times. It would be perfect if all lines of decompiled file would match, because now I get manny MISALIGNED.Rondeau
Agree, but jad is not open source and the author seems to have abandoned it. Hopefully the new decompilers supported by jadclipse will eventually be even better than jad.Manhole
The MISALIGNED is due to the way that jad creates the decompiled source. I believe it writes serially, and cannot move back and forth to place things better.Manhole
@tori, note I've found there to be less misaligned if the { and } are placed on the same line instead of next line. Check jadclipse configuration panel.Manhole
F
6

Realignment fragment for JD-Eclipse host plug-in. This plug-in for Eclipse makes the decompiled code line numbers actually appropriate to the line numbers from the java-class file. As a result, it becomes possible debugging without source code. https://sourceforge.net/projects/realignmentjd/

Fate answered 29/8, 2011 at 6:16 Comment(0)
P
4

You can use JD-GUI to decompile jar files and save the whole lot into a source zip file which can then be added to the source search list (via Configure Build Path).

The problem with JD-GUI is that the line numbers are out which makes debugging very difficult, so you need to

  1. extract the source files from the decompiled source zip file
  2. Run the script found at https://bushlife.com.au/groups/python/wiki/7539a/Adjust_line_numbers_in_file.html
  3. zip the generated source back up
  4. add it as the source path associated with your java file - using Configure Build Path after right clicking on the jar file in your java project.
Pellitory answered 17/2, 2011 at 7:25 Comment(3)
This is the first mention of a solution for the line-numbers I've seen! Thanks. Sadly the homepage is down!Sturgeon
Just checked the site. If you still have problems can you send specific details to spider at the site. He will crawl all over the problem.Pellitory
I managed to download and use the script, very nice. It has annoying handling of out-of-order linenumbers but it can be worked around.Sturgeon
W
3

This plugin should hopefully be of help. JD-Eclipse

In eclipse open Window -> Preferences -> General ->Editors -> File Associations Select *.class file type Associate it with JD-Eclipse Set it to default

Good Luck

Waadt answered 15/12, 2009 at 9:28 Comment(2)
This didn't work with debug, for me.Rondeau
It did not workBicameral
A
2

Decompile all the classes, put all the Java files ordered in the proper hierarchy (directory for package, etc.) and then add them as the source of the original jar by right clicking the jar file -> Java Source Attachment -> External folder.

You can also have them inside a folder in the project (click on Workspace in this case)

Aubarta answered 15/12, 2009 at 8:35 Comment(4)
Which decompiler would you recommend?Manhole
I haven't done decompilations lately (the open source advantage...) but I remember JAD and JODE to yield good results. See more at stackoverflow.com/questions/31353 and stackoverflow.com/questions/1384619Aubarta
Yes, I was considering this approach, but if there are many libraries this gets too annoying, so I am looking for a "automatic way" without any overhead.Rondeau
Take a command line decompiler, write an ant (or even shell) script that iterate through the files and generate the java files.Aubarta
P
2

The solution that worked for me is using the JD-Eclipse after applying the patch: http://java.decompiler.free.fr/?q=node/464

This is an extension of jd-eclipse which realigns the code after decompiling.

When debugging with eclipse you just need to have the jar files in the classpath and that's it! There's no need to decompile the whole jar, realign or whatsoever... Just debug and be happy :-)

Here's how to do it: http://gauchoacomecable.wordpress.com/2011/10/14/eclipse-debug-java-without-source-code-jd-eclipse-and-realignment/

Palacio answered 14/10, 2011 at 12:48 Comment(0)
B
0

I have enhanced the "Realignment for JD Eclipse" plugin to properly line up enums and fields and published it along with JD Eclipse on my own update site: http://mchr3k-eclipse.appspot.com/

Details about my changes: http://mchr3k-coding.blogspot.co.uk/2012/07/realignment-for-jd-eclipse.html

Bolide answered 10/7, 2012 at 7:21 Comment(2)
Have you used the same patch as another project? Pity that this feature has not gone to master code, we won't have two code forks then.Estate
No. As per mchr3k.github.com/jdeclipse-realign I forked a different project.Bolide

© 2022 - 2024 — McMap. All rights reserved.