Complete Guide to Attaching IntelliJ IDEA Debugger to Running Java Processes

Nov 27, 2025 · Programming · 15 views · 7.8

Keywords: IntelliJ IDEA | Remote Debugging | Java Process

Abstract: This article provides a comprehensive guide on attaching IntelliJ IDEA debugger to running Java processes. It covers remote debug configuration setup, JVM debug agent parameters, debug session management, and prerequisites. With step-by-step instructions and code examples, developers can master remote debugging techniques to enhance problem-solving efficiency.

Remote Debugging Overview

IntelliJ IDEA offers powerful remote debugging capabilities that allow developers to attach the debugger to locally or remotely running Java processes. This debugging approach is particularly valuable for production environment troubleshooting, distributed system debugging, and applications that cannot be started directly in the development environment.

Debugging Prerequisites

To achieve full debugging functionality, three key conditions must be met:

Debug Agent Configuration

The target Java process must load the debug agent during startup. The debug agent is a component responsible for communicating with the debugger through socket connections. Configuration example:

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

Debug Information Compilation

Application bytecode needs to contain debug information, which is generated during compilation using the -g compiler flag. Debug information includes critical data such as local variable names and line number mappings. The absence of this information will limit debugger functionality.

Source Code Access

It is recommended to have access to the source code of the project being debugged. IntelliJ IDEA can match debugging events with source code and display relevant debugging information in the editor, providing an intuitive debugging experience.

Creating Remote Debug Configuration

Configuring remote debug connection in IntelliJ IDEA requires the following steps:

  1. Open run configuration dialog via Run > Edit Configurations... menu
  2. Click the + button in the upper left corner to add new configuration
  3. Select Remote option in the left-most panel
  4. Name the configuration (e.g., "remote-debugging")
  5. Configure connection parameters and save

JVM Debug Parameters Detailed

The debug agent parameters include several key options:

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

Parameter explanation:

Environment variable configuration example:

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

Initiating Debug Session

After configuration, follow these steps to start debugging:

  1. Start the target Java application normally
  2. Select the created remote debug configuration in IntelliJ IDEA
  3. Click the Debug button to initiate debug session
  4. IntelliJ IDEA will connect to the JVM and initialize remote debugging

Advanced Debugging Features

Startup Suspension

Changing suspend=n to suspend=y makes the application wait for debugger connection during startup, suitable for scenarios requiring breakpoints during application initialization.

IntelliJ IDEA Debug Agent

To utilize advanced features like async stack traces, load IntelliJ IDEA's dedicated debug agent:

-javaagent:"/path/to/debugger-agent.jar"

Read-Only Debug Mode

For local processes without debug agent enabled, the debugger can be attached in read-only mode. This mode allows viewing call stacks and related local variables, useful for initial diagnosis when programs hang.

Debug Session Management

Disconnecting

To end a debug session, click the Stop button in the Debug tool window toolbar or press Ctrl+F2. Unlike local debugging, remote processes continue running after debugger disconnection.

Process Termination

When the remote process is no longer needed, it can be terminated by closing the corresponding debugger tab. IntelliJ IDEA will prompt to choose between terminating the process or simply disconnecting.

Practical Application Scenarios

Remote debugging is particularly useful in the following scenarios:

By mastering IntelliJ IDEA's remote debugging techniques, developers can more efficiently locate and resolve complex runtime issues, improving software quality and development efficiency.

Copyright Notice: All rights in this article are reserved by the operators of DevGex. Reasonable sharing and citation are welcome; any reproduction, excerpting, or re-publication without prior permission is prohibited.