9

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.

6
  • Look up "jad, the Java Decompiler". Results won't always be perfect, but it'll give you sources if you really need sources. Commented Nov 7, 2013 at 17:53
  • 1
    Decompiling is not the problem; debugging a running process using a decompiler to obtain the source is where I am struggling. Commented Nov 7, 2013 at 18:06
  • So you have already decompiled and have a copy of source, but you're having trouble connecting the debugger to both the source and the process at the same time? Commented Nov 7, 2013 at 18:10
  • 1
    There are 200+ megabytes of JAR files and 500+ megabytes of other stuff - turning this into a compilable project is probably close to impossible and not worth the effort just for tracking down one or two bugs. (Comment copied verbatim from matheszabi's answer.) Commented Nov 7, 2013 at 18:16
  • DO you really need the whole codebase compilable? Or do you need particular classes compilable? Commented Nov 7, 2013 at 18:17

2 Answers 2

2

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!
Sign up to request clarification or add additional context in comments.

8 Comments

I already did what you described. How can I start debugging from there? Just hitting debug will not work because I have no source and no project to lunch. I tried remote debugging but either nothing happens or I get a connection error.
What JVM options are you using to start the process for remote debugging?
-Xrunjdwp:transport=dt_socket,address=8023,server=y,suspend=n
One thing more that in order for the source to be found, if the jar files being used in the project belong to a different project, they need to be added to the build path as “Add External JARs…“.Otherwise if “Add Jar”, is used you will get this message "Source not found"
One step closer - I managed to attach the debugger from within Eclipse to yEd - which I am currently using for testing -, suspend all threads and inspect the call stack. I am not sure what I did wrong or what went wrong before, but it is probably just due to the fact that I am very new - 3 days - to Eclipse.
|
1

here is a possible solution:

  1. run the jar with arguments below:

java -agentlib:jdwp=transport=dt_shmem,address=XXXXX,server=y,suspend=n -jar YourJar

  1. run jdb in eclipse using Run->External Tools to connect to the running jvm

jdb -attach XXXXX

  1. set breakpoints using jdb cmd like:

stop at <TheClassName>:<ThePosition>

I will try it when I'm free, will update if it works

updates:

I've figured it out today:

  1. unzip jar file

  2. jdb -sourcepath [unzipped jar path] -classpath [your main class path]

  3. after jdb initializing, excute:

stop at <package>.<yourclass>:<linenunmber>
run <your main class, for example org.springframework.boot.loader.JarLauncher>
  1. after breakpoint triggered, you can step by step debug using jdb command

jdb debug

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.