How to run JDI application in IntelliJ

Answered

I am creating a simple debugger application in Java. I am using the Java Debugging interface. This is the link to my project.

 

When I run the application in the terminal it works perfectly. But when run in the IntelliJ it not work as expected. 

 

This is the command I use to run the application in the terminal:

java -cp "tools.jar : ." Debugger 

 

In the code from the debugger node, I am waiting for ClassPrepareEvent and BreakPointEvent. In the terminal debugger, the node receives that event from the debuggee VM. But when run in IntelliJ debugged node send VmDeathEvent right after VmStartEvent and then get the VmDisconnectEvent.

Why this happens. Is there any configuration that I should set in IntelliJ for this type of application?

 

Thank you in advance!

1
6 comments

How do you run the application from the command line? May you show the exact command? 

And what error is returned in IDE? Is it "VM initialization failed"? 

0
Avatar
Permanently deleted user

Thank you! I update the question with the command I use to run the application in the terminal. Actually, I am not getting an error. It just works in the way expected. The remote VM doesn't send the ClassPreparationEvent and BreakPointEvent. It Just sends VMDeathEvent right after VMStartEvent.

0

May you share com.sun.tool jar that is in use in your project? 

Are you using the same java for the project in IDE? May you share these two screenshots of your project: 

https://i.imgur.com/xl8tu0t.png

https://i.imgur.com/dgKwcie.png

And please show your run/debug configuration. 

0
Avatar
Permanently deleted user

Link to the jar

Both images are the same as yours. I think the problem is related to the virtual JVM connection? I get VMDisconnectException .

0

> Both images are the same as yours.

On my screenshots, JBR (JetBrains Runtime) is used to start the project. Is it the same for you? If so, please use JDK (like OpenJDK) to start the application. JBR should be used to start IDE, but not applications. 

> I think the problem is related to the virtual JVM connection?

Yes, most probably. 

And please show your run/debug configuration. 

 
0

Reason:

    At launch, the Connector parses the parameters and generates an array of shell execution instructions. It is executed by exec . The point is that when executing a command with exec, the current project (such as idea-debug in this example) is used as the execution directory by default. The class `site.wtfu.framework.HelloWorld` that needs to be executed by targetVM in the parameters passed above does not exist in the execution directory, so targetVM starts with an error. also directly out of the race.
    If validation is required, Use process.getErrorStream() to obtain a targetVM exception exit message.
    

fIxED:

  1. Modify the AbstractLauncher.java( https://github.com/openjdk/jdk/blob/a474b37212da5edbd5868c9157aff90aae00ca50/src/jdk.jdi/share/classes/com/sun/tool S/jdi/AbstractLauncher java# L189) source code, passing in directory with exec. It's obviously inconvenient.
  2. Meet targetVM:
    The compiled HelloWorld.class is constructed from the directory required by exec. 

    like this:
    1:  cd to project root directory:
    2:  cp -R target/classes/* .
    3:  Re-run using the idea RUN button
     

REFER:

0

Please sign in to leave a comment.