Fundamentals 20 min read

Comprehensive Guide to IntelliJ IDEA Debugging Features

This article provides a step‑by‑step tutorial on using IntelliJ IDEA's Debug tool, covering preparation, main interface elements, each debugging button, variable inspection and modification, conditional breakpoints, expression evaluation, rollback, force return, multi‑thread, Stream and remote debugging, with code examples and screenshots.

Top Architect
Top Architect
Top Architect
Comprehensive Guide to IntelliJ IDEA Debugging Features

Debugging is one of the most frequently used features in IntelliJ IDEA for tracing code execution, inspecting variable changes, locating errors, and even learning third‑party frameworks. Once enabled, the program becomes fully transparent, allowing developers to see exactly what happens at each step and why.

Before diving into the Debug functions, you need to prepare the following tools:

IntelliJ IDEA

A piece of Java code to debug (the classic LeetCode "Two Sum" solution is used as an example).

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

public class ToSum {
    public static int[] twoSum(int[] nums, int target) {
        Map
map = new HashMap<>();
        for (int i = 0; i < nums.length; i++) {
            int sub = target - nums[i];
            // If the complement exists, return the pair of indices
            // Otherwise, store the current number and its index
            if (map.containsKey(sub)) {
                return new int[]{map.get(sub), i};
            }
            map.put(nums[i], i);
        }
        throw new IllegalArgumentException("No two sum solution");
    }

    public static void main(String[] args) {
        int[] nums = {2, 7, 11, 15};
        int target = 9;
        int[] ints = twoSum(nums, target);
        System.out.println(Arrays.toString(ints));
    }
}

The Debug window may not appear at the bottom of IDEA by default; you can open it by pressing Shift twice, typing "Debug", and selecting the second option.

Right‑clicking the Debug toolbar lets you place the window on any side of the IDE.

Main Interface Overview

The main Debug panel includes the following elements:

Debug : start debugging.

Breakpoint : click the left gutter to set a breakpoint; execution stops there.

Service Buttons : start/stop services, edit configurations, resume, pause, stop, view breakpoints, mute breakpoints, thread dump, settings, pin tab, etc.

Debug Buttons : Show Execution Point, Step Over (F8), Step Into (F7), Force Step Into, Step Out, Drop Frame, Run to Cursor, Evaluate Expression, Trace Current Stream Chain.

Frames : shows the call stack of the current thread.

Variables : displays current variable values and allows modification.

Watches : lets you watch specific variables continuously.

Detailed Explanation of Each Button

Service Buttons (10 buttons, may vary by IDEA version):

Rerun ‘xxx’: restart the program in Debug mode.

Edit Run Configuration: change JDK version, environment variables, or set up remote debugging.

Resume Program (F9): continue execution until the next breakpoint.

Pause Program: pause a long‑running step or a dead loop.

Stop ‘xxx’ (Ctrl+F2): terminate the current Debug session.

View Breakpoints: list all breakpoints and configure conditions, thread filters, etc.

Mute Breakpoints: disable all breakpoints (turn them gray).

Get Thread Dump: export the current stack trace.

Settings: toggle display of values, return values, etc.

Pin Tab: keep the Debug tab fixed.

Debug Buttons (9 buttons):

Show Execution Point: locate the current execution line.

Step Over (F8): execute line by line, skipping over called methods without breakpoints.

Step Into (F7): dive into called methods even if they have no breakpoints.

Force Step Into (Alt+Shift+F7): force entry into any method, useful for library code.

Step Out (Shift+F8): exit the current method back to the caller.

Drop Frame: rollback to the previous method call (the "undo" drug).

Run to Cursor: run until the cursor position without setting a breakpoint.

Evaluate Expression…: compute an expression in the current context.

Trace Current Stream Chain: visualize the processing steps of a Stream pipeline.

Variable Inspection

To view variable values you can:

Enable "Show Values" and "Show Return Values" in the Settings of the Service Buttons.

Observe the gray value hints that appear after each line of code.

Hover over a variable to see its current value; click to expand complex objects.

Use the Variables pane to modify values on the fly via Set Value… .

Add variables to the Watches pane for persistent observation.

Changing Variable Values

During a paused Debug session, select a variable in the Variables pane, click Set Value… , edit the value (e.g., change num[0] from 2 to 22), press Enter, and the program continues with the new value.

Conditional Breakpoints

You can set a condition so that a breakpoint only stops when the condition is true (e.g., stop when a variable is null ). This avoids manually stepping through many iterations.

Evaluating Expressions

Click the Evaluate Expression… button to compute arbitrary expressions (e.g., map.keySet() ) without modifying the source code.

Rollback (Drop Frame)

The Drop Frame operation lets you return to the previous method call, effectively re‑executing that method. Note that side effects (e.g., database changes) are not undone.

Force Return

If you have found a bug and want to stop further execution without terminating the whole process, use Force Return to supply a return value manually (e.g., return new int[]{2,7} from twoSum ).

Multi‑Thread Debugging

By default, Debug blocks all threads except the current one. Enable multi‑thread debugging via the View Breakpoints dialog to allow other threads to continue while the current thread is paused.

Stream Debugging

The Trace Current Stream Chain button becomes active when a breakpoint is set inside a Stream pipeline, allowing you to see each transformation step and its intermediate result.

Remote Debugging

When a bug only reproduces in production, start the remote JVM with the agent option: java -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005 -jar xxx.jar Then configure a Remote JVM Debug configuration in IDEA with the remote host IP and port (e.g., 5005). After launching the remote service, run the local Debug configuration; breakpoints will trigger on the remote process.

Conclusion

This guide has covered virtually all IDEA Debug features, from basic setup to advanced techniques such as conditional breakpoints, expression evaluation, rollback, force return, multi‑thread, Stream, and remote debugging. Mastering these tools can greatly improve development efficiency.

debuggingJavadevelopmentIntelliJ IDEAide
Top Architect
Written by

Top Architect

Top Architect focuses on sharing practical architecture knowledge, covering enterprise, system, website, large‑scale distributed, and high‑availability architectures, plus architecture adjustments using internet technologies. We welcome idea‑driven, sharing‑oriented architects to exchange and learn together.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.