37

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.

David Rabinowitz
  • 29,904
  • 14
  • 93
  • 125
NSPKUWCExi2pr8wVoGNk
  • 2,449
  • 2
  • 22
  • 26

8 Answers8

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.

Emmanuel Dupuy
  • 1,407
  • 10
  • 12
  • @Emmanuel Dupuy: any progress on "debug classes without sources" ? – rafalmag Jul 26 '12 at 11:40
  • 1
    @rafalmag The realignment algorithm is ready. You can test it here: http://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: http://sourceforge.net/projects/realignmentjd – Emmanuel Dupuy Jul 26 '12 at 18:37
  • 1
    Also, https://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! – Caspar Aug 24 '12 at 10:09
  • Any progress on JD-Eclipse? – user626528 Mar 12 '15 at 08:04
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.

Thorbjørn Ravn Andersen
  • 73,784
  • 33
  • 194
  • 347
  • 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. – NSPKUWCExi2pr8wVoGNk Dec 15 '09 at 12:51
  • 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. – Thorbjørn Ravn Andersen Dec 15 '09 at 14:21
  • 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. – Thorbjørn Ravn Andersen Jul 22 '10 at 13:57
  • @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. – Thorbjørn Ravn Andersen Aug 10 '11 at 19:29
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/

avkosinsky
  • 241
  • 4
  • 2
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

user231960
  • 31
  • 2
3

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.
sweetfa
  • 5,457
  • 2
  • 48
  • 62
  • This is the first mention of a solution for the line-numbers I've seen! Thanks. Sadly the homepage is down! – sandos May 19 '11 at 14:03
  • 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. – sweetfa May 20 '11 at 21:49
  • 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. – sandos May 24 '11 at 08:25
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)

David Rabinowitz
  • 29,904
  • 14
  • 93
  • 125
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/

Community
  • 1
  • 1
Rafael
  • 21
  • 1
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

mchr
  • 6,161
  • 6
  • 52
  • 74
  • Have you used the same patch as [another project](http://gauchoacomecable.wordpress.com/2011/10/14/eclipse-debug-java-without-source-code-jd-eclipse-and-realignment/)? Pity that this feature has not gone to master code, we won't have two code forks then. – dma_k Jan 10 '13 at 18:38
  • No. As per http://mchr3k.github.com/jdeclipse-realign/ I forked a different project. – mchr Jan 10 '13 at 22:14