简体   繁体   English

在 IntelliJ 中调试 Java 程序时,如何显示正在执行的字节码?

[英]While debugging a Java program in IntelliJ, how to show Bytecode that is being executed?

I am using IntelliJ to debug a Java program.我正在使用 IntelliJ 调试 Java 程序。 In my current case that happens to be IntelliJ itself -- to debug a problem in it -- but a similar problem occurred in the past with other code.在我目前的情况下,恰好是 IntelliJ 本身——调试其中的问题——但过去其他代码也出现过类似的问题。

While single-stepping, at a certain point when stepping into a method, IntelliJ won't show the code that is being executed anymore.单步执行时,在进入方法的某个时刻,IntelliJ 将不再显示正在执行的代码。 I am used to stepping through decompiled byte code when source is not available, but in this case IntelliJ won't show anything -- no source code, no byte code, nothing.我习惯于在源代码不可用时单步执行反编译的字节代码,但在这种情况下,IntelliJ 不会显示任何内容——没有源代码,没有字节代码,什么都没有。 This happens when stepping from RemoteExternalSystemProjectResolverImpl into GradleProjectResolver .当从RemoteExternalSystemProjectResolverImpl进入GradleProjectResolver时会发生这种情况。

Quite suspiciously, the problem happens exactly when stepping from a class that comes from an UrlClassLoader , into a class from a PluginClassLoader .非常可疑的是,问题恰好发生在从来自 UrlClassLoader 的UrlClassLoader进入来自PluginClassLoader的 class 时。

I'm aware that the debugger will have problems associating the bytecode being executed with source code when the bytecode comes from a class loader of unknown nature, since there is no well-defined mechanism for that.我知道当字节码来自未知性质的 class 加载器时,调试器将正在执行的字节码与源代码相关联时会遇到问题,因为没有明确定义的机制。 Please note that I am totally fine with stepping through decompiled code.请注意,我完全可以单步执行反编译代码。 (Even stepping through bytecode instructions would be fine, but AFAIK IntelliJ does not support that). (即使单步执行字节码指令也可以,但 AFAIK IntelliJ 不支持)。 I'm not sure how to provide matching source code myself, so I'd rather see the bytecode to be sure I'm not seeing false information.我自己不确定如何提供匹配的源代码,所以我宁愿查看字节码以确保我没有看到虚假信息。

What I do not understand is why IntelliJ won't show me that bytecode.我不明白的是为什么 IntelliJ 不会向我显示该字节码。 Unlike source code, the bytecode is avaiable since after all, it is being executed right now.与源代码不同,字节码可用的,毕竟它现在正在执行。

What should I do to make IntelliJ show the bytecode being executed?我应该怎么做才能让 IntelliJ 显示正在执行的字节码?

Update: Steps to reproduce更新:重现步骤

  • Use IntelliJ to create an IntelliJ plugin project使用 IntelliJ 创建 IntelliJ 插件项目
  • create a new folder with an empty build.gradle file in it创建一个新文件夹,其中包含一个空的 build.gradle 文件
  • Run a "guest" instance of IntelliJ in debug mode在调试模式下运行 IntelliJ 的“来宾”实例
  • Import the empty gradle project导入空的 gradle 项目
  • In the "host" IntelliJ, go to RemoteExternalSystemProjectResolverImpl.resolveProjectInfo and set a breakpoint to the inner call to this.myDelegate.resolveProjectInfo在“宿主”IntelliJ,go 到 RemoteExternalSystemProjectResolverImpl.resolveProjectInfo 并设置断点到 this.myDelegate.resolveProjectInfo 的内部调用
  • In the "guest" IntelliJ, hit the Gradle re-import button.在“来宾”IntelliJ 中,点击 Gradle 重新导入按钮。 It should hit the breakpoint.它应该到达断点。
  • Step into the function being called.进入被呼叫的 function。 This will show the frame on the stack, but no code -- not even raw or decompiled bytecode.这将显示堆栈上的帧,但没有代码——甚至没有原始或反编译的字节码。

You are possibly debugging a library that had been compiled without debug infos.您可能正在调试一个没有调试信息的库。 For this purpose, the Java compiler has the command-line option "-g".为此,Java 编译器具有命令行选项“-g”。

I assume you do not understand what bytecode is.我假设您不了解字节码是什么。 This is a bunch of numeric values which cannot be displayed in a similar manner as source code.这是一堆无法以与源代码类似的方式显示的数值。 You would not be able to read bytecode.您将无法阅读字节码。

What you are usually seeing is decompiled byte code, which depends on the existence of debug infos.你通常看到的是反编译的字节码,这取决于调试信息的存在。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM