How to debug a Java application without access to the source code?

Daniel Brückner picture Daniel Brückner · Nov 7, 2013 · Viewed 9.1k times · Source

I need to debug a Java application I have no source code for. It is running locally on a Jetty server. Decompiling using JD-GUI works fine. Attaching JDB via a socket connection or shared memory works fine, too.

Where I fail is joining the pieces together. I mainly tried Eclipse with the JD-Eclipse plugin and remote debugging. I failed to find a way to successfully attach the debugger to a running process. Everything seems to assume that I have at least parts of the application available as source code in a project, but I have not. And it is quite a large application (200+ MiB of JAR files and 500+ MiB of other stuff) so trying to build a project from all the decompiled classes and getting this to run is not an option unless it is easy to automate.

What I really need is being able to attach a debugger to a running process, see and navigate the decompiled code, set breakpoints and inspect variables and objects. It does not matter if the code could be recompiled. Conditional breakpoints and expression evaluation would be nice to have.

Answer

Imran picture Imran · Nov 7, 2013

You can probably do this with the help of a combination of jd-eclipse and its extension jd-eclipse realignment fragment.

JD-Eclipse

Realignment fragment

The process for installing this is quite simple:

  • Install JD-Eclipse following the steps provided in the JD-Eclipse site (the process is quite simple)
  • Restart Eclipse
  • Download Realignment realignment.jd.ide.eclipse_1.0.2.jar
  • Copy the file to the \dropins
  • Restart Eclipse
  • Go to Windows -> Preferences
  • Navigate to General -> Editors -> File Associations
  • Select *.class in the File types section, select Realignment for JD Class File Editor in the Associated editors section and click the Default button.
  • Press OK and start debugging!