Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Attach IntelliJ IDEA debugger to a running Java process

People also ask

How do you attach a debugger to a process in IntelliJ?

Press Ctrl+Alt+F5 or choose Run | Attach to Process from the main menu. IntelliJ IDEA will show the list of the running local processes. Select the process to attach to. The processes launched with the debug agent are shown under Java.

How does debugger attach to process?

To attach to a process on your local computer:In Visual Studio, select Debug > Attach to Process (or press Ctrl+Alt+P) to open the Attach to Process dialog box. Check the Connection type. In most scenarios, you can use Default. Some scenarios may require a different connection type.

What is remote JVM debugging in IntelliJ?

Remote Debugging with IntelliJ IDEAUltimate. Last modified: 26 July 2022. With IntelliJ IDEA you can debug your application using an interpreter that is located on the other computer, for example, on a web server or dedicated test machine. IntelliJ IDEA provides two ways to debug remotely: Through a remote interpreter ...


Yes! Here is how you set it up.

Run Configuration

Create a Remote run configuration:

  1. Run -> Edit Configurations...
  2. Click the "+" in the upper left
  3. Select the "Remote" option in the left-most pane
  4. Choose a name (I named mine "remote-debugging")
  5. Click "OK" to save:

enter image description here

JVM Options

The configuration above provides three read-only fields. These are options that tell the JVM to open up port 5005 for remote debugging when running your application. Add the appropriate one to the JVM options of the application you are debugging. One way you might do this would be like so:

export JAVA_OPTS="-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005"

But it depends on how your run your application. If you're not sure which of the three applies to you, start with the first and go down the list until you find the one that works.

You can change suspend=n to suspend=y to force your application to wait until you connect with IntelliJ before it starts up. This is helpful if the breakpoint you want to hit occurs on application startup.

Debug

Start your application as you would normally, then in IntelliJ select the new configuration and hit 'Debug'.

enter image description here

IntelliJ will connect to the JVM and initiate remote debugging.

You can now debug the application by adding breakpoints to your code where desired. The output of the application will still appear wherever it did before, but your breakpoints will hit in IntelliJ.


It's possible, but you have to add some JVM flags when you start your application.

You have to add remote debug configuration: Edit configuration -> Remote.

Then you'lll find in displayed dialog window parametrs that you have to add to program execution, like:

-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005

Then when your application is launched you can attach your debugger. If you want your application to wait until debugger is connected just change suspend flag to y (suspend=y)


in AndroidStudio or idea

  1. Config the application will be debug, open Edit Configurations

add "VM Options" Config “-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005” remember "address"

enter image description here

  1. Config Remote Debugger if not exits, Click + to add

specify "Port" same as in Step 1 "address" enter image description here


Also, don't forget you need to add "-Xdebug" flag in app JAVA_OPTS if you want connect in debug mode.