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

924 views Asked by At

I am using IntelliJ to debug a Java program. 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.

While single-stepping, at a certain point when stepping into a method, IntelliJ won't show the code that is being executed anymore. 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. This happens when stepping from RemoteExternalSystemProjectResolverImpl into GradleProjectResolver.

Quite suspiciously, the problem happens exactly when stepping from a class that comes from an UrlClassLoader, into a class from a PluginClassLoader.

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. 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). 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. 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?

Update: Steps to reproduce

  • Use IntelliJ to create an IntelliJ plugin project
  • create a new folder with an empty build.gradle file in it
  • Run a "guest" instance of IntelliJ in debug mode
  • Import the empty gradle project
  • In the "host" IntelliJ, go to RemoteExternalSystemProjectResolverImpl.resolveProjectInfo and set a breakpoint to the inner call to this.myDelegate.resolveProjectInfo
  • In the "guest" IntelliJ, hit the Gradle re-import button. It should hit the breakpoint.
  • Step into the function being called. This will show the frame on the stack, but no code -- not even raw or decompiled bytecode.
1

There are 1 answers

2
Stefan On

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".

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.