$npx -y skills add brunoborges/jdb-agentic-debugger --skill jdb-debuggerDebug Java applications in real time using JDB (Java Debugger CLI). Attach to running JVMs or launch new ones under JDB, set breakpoints, step through code, inspect variables, analyze threads, and diagnose exceptions. Use when debugging Java programs, investigating runtime behavi
| 1 | # Java Debugger (JDB) Skill |
| 2 | |
| 3 | Debug Java applications interactively using the JDK's built-in command-line debugger. |
| 4 | |
| 5 | ## Critical Rules for Agents |
| 6 | |
| 7 | 1. **NEVER create files in the workspace** (no `bp.txt`, `cmds.txt`, wrapper scripts, etc.). |
| 8 | Use the inline CLI flags (`--bp`, `--cmd`, `--auto-inspect`, `--timeout`) provided by the skill scripts. |
| 9 | 2. **ALWAYS use the skill scripts** in `scripts/`. Never write |
| 10 | custom JDB wrapper scripts, FIFO-based launchers, or shell scripts to drive JDB. |
| 11 | 3. **Compile first, then debug.** Ensure classes are compiled before launching JDB. |
| 12 | 4. **On Windows, invoke scripts via WSL:** `wsl bash scripts/<script>.sh` |
| 13 | |
| 14 | ## Platform Support |
| 15 | |
| 16 | ### Windows (WSL Required) |
| 17 | |
| 18 | The scripts in this skill are Bash scripts. On Windows, invoke them via WSL: |
| 19 | |
| 20 | ```bash |
| 21 | wsl bash scripts/jdb-launch.sh com.example.MyApp --sourcepath src/main/java |
| 22 | ``` |
| 23 | |
| 24 | If your compiled classes are on the Windows filesystem, WSL accesses them via `/mnt/c/`: |
| 25 | ```bash |
| 26 | wsl bash scripts/jdb-launch.sh com.example.MyApp --classpath /mnt/c/Users/you/project/out |
| 27 | ``` |
| 28 | |
| 29 | Ensure JDK is installed in WSL: |
| 30 | ```bash |
| 31 | # Ubuntu/Debian WSL |
| 32 | sudo apt update && sudo apt install -y default-jdk |
| 33 | |
| 34 | # Verify |
| 35 | which jdb && jdb -version |
| 36 | ``` |
| 37 | |
| 38 | ### Linux / macOS |
| 39 | |
| 40 | Scripts run natively. Ensure JDK is installed and `jdb` is on PATH: |
| 41 | ```bash |
| 42 | export PATH=$JAVA_HOME/bin:$PATH |
| 43 | ``` |
| 44 | |
| 45 | ## Decision Tree |
| 46 | |
| 47 | ``` |
| 48 | User wants to debug Java app → |
| 49 | ├─ App is already running with JDWP agent? |
| 50 | │ ├─ Yes → Attach: scripts/jdb-attach.sh --port <port> |
| 51 | │ └─ No → Can you restart with JDWP? |
| 52 | │ ├─ Yes → Launch with: scripts/jdb-launch.sh <mainclass> [args] |
| 53 | │ └─ No → Suggest adding JDWP agent to JVM flags (see below) |
| 54 | │ |
| 55 | ├─ What does the user need? |
| 56 | │ ├─ Set breakpoints & step through code → Interactive JDB session |
| 57 | │ ├─ Collect thread dumps / diagnostics → scripts/jdb-diagnostics.sh |
| 58 | │ └─ Catch a specific exception → Use `catch` command in JDB |
| 59 | │ |
| 60 | └─ Done debugging → Detach cleanly with `quit` or Ctrl+C |
| 61 | ``` |
| 62 | |
| 63 | ## Quick Start |
| 64 | |
| 65 | ### Option 1: Launch a new JVM under JDB |
| 66 | |
| 67 | ```bash |
| 68 | bash scripts/jdb-launch.sh com.example.MyApp --sourcepath src/main/java |
| 69 | ``` |
| 70 | |
| 71 | ### Option 2: Attach to a running JVM |
| 72 | |
| 73 | First, ensure the target JVM was started with the JDWP agent: |
| 74 | ```bash |
| 75 | java -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:5005 -jar myapp.jar |
| 76 | ``` |
| 77 | |
| 78 | Then attach: |
| 79 | ```bash |
| 80 | bash scripts/jdb-attach.sh --host localhost --port 5005 |
| 81 | ``` |
| 82 | |
| 83 | ### Option 3: Quick diagnostics (thread dump + deadlock detection) |
| 84 | |
| 85 | ```bash |
| 86 | bash scripts/jdb-diagnostics.sh --port 5005 |
| 87 | ``` |
| 88 | |
| 89 | ## Enabling JDWP on a Running Application |
| 90 | |
| 91 | If the target JVM was not started with JDWP, suggest the user restart with: |
| 92 | |
| 93 | ```bash |
| 94 | # For direct Java launch |
| 95 | java -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:5005 -cp myapp.jar com.example.Main |
| 96 | |
| 97 | # For Maven Spring Boot |
| 98 | mvn spring-boot:run -Dspring-boot.run.jvmArguments="-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:5005" |
| 99 | |
| 100 | # For Gradle |
| 101 | ./gradlew bootRun --jvmArgs="-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:5005" |
| 102 | |
| 103 | # As environment variable |
| 104 | export JAVA_TOOL_OPTIONS="-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:5005" |
| 105 | ``` |
| 106 | |
| 107 | ## Interactive JDB Session Guide |
| 108 | |
| 109 | Once inside a JDB session (launched or attached), use these commands interactively: |
| 110 | |
| 111 | ### Setting Breakpoints |
| 112 | |
| 113 | ``` |
| 114 | stop at com.example.MyClass:42 # Break at line 42 |
| 115 | stop in com.example.MyClass.myMethod # Break at method entry |
| 116 | stop in com.example.MyClass.<init> # Break at constructor |
| 117 | stop in com.example.MyClass.<clinit> # Break at static initializer |
| 118 | ``` |
| 119 | |
| 120 | For overloaded methods, specify parameter types: |
| 121 | ``` |
| 122 | stop in com.example.MyClass.process(int,java.lang.String) |
| 123 | ``` |
| 124 | |
| 125 | ### Running and Stepping |
| 126 | |
| 127 | ``` |
| 128 | run # Start the application (if launched, not attached) |
| 129 | cont # Continue execution after hitting a breakpoint |
| 130 | step # Step into the next line (enters method calls) |
| 131 | next # Step over to the next line (skips method internals) |
| 132 | step up # Run until the current method returns |
| 133 | ``` |
| 134 | |
| 135 | ### Inspecting State |
| 136 | |
| 137 | ``` |
| 138 | locals # Show all local variables in the current frame |
| 139 | print myVariable # Print value of a variable or expression |
| 140 | print myObj.getX() # Evaluate a method call |
| 141 | dump myObject # Show all fields of an object |
| 142 | eval 2 + 2 # Evaluate an arbitrary e |