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.

4

2 回答 2

2

您可以借助 jd-eclipse 及其扩展 jd-eclipse 重新对齐片段的组合来完成此操作。

京东-Eclipse

重排片段

安装它的过程非常简单:

  • 按照 JD-Eclipse 站点中提供的步骤安装JD- Eclipse(过程非常简单)
  • 重启 Eclipse
  • 下载重新对齐realignment.jd.ide.eclipse_1.0.2.jar
  • 将文件复制到 \dropins
  • 重启 Eclipse
  • 转到 Windows -> 首选项
  • 导航到常规 -> 编辑器 -> 文件关联
  • 在 File types 部分中选择 *.class,在 Associated editors 部分中选择 Realignment for JD Class File Editor,然后单击 Default 按钮。
  • 按确定并开始调试!
于 2013-11-07T18:00:42.183 回答
1

这是一个可能的解决方案:

  1. 使用以下参数运行 jar:

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

  1. 使用 Run->External Tools 在 Eclipse 中运行 jdb 以连接到正在运行的 jvm

jdb -attach XXXXX

  1. 使用 jdb cmd 设置断点,例如:

stop at <TheClassName>:<ThePosition>

有空我会试试,如果好用会更新

更新:

我今天想通了:

  1. 解压jar文件

  2. jdb -sourcepath [解压的jar路径] -classpath [你的主类路径]

  3. jdb初始化后,执行:

stop at <package>.<yourclass>:<linenunmber>
run <your main class, for example org.springframework.boot.loader.JarLauncher>
  1. 触发断点后,可以使用 jdb 命令逐步调试

jdb调试

于 2019-10-25T09:06:11.980 回答