Replay a breakpoint with the values your program had
Set a breakpoint, use your app as usual, and watch the hit play back in the editor line by line, with real values and nobody pressing Step.
Before you start
- A Java or Kotlin program (any JVM), started from a runner in the Run panel. Gradle and Maven projects are found by their build files; any other command can be a runner.
- Debug information in the build, so variables keep their names:
javac -g, or Gradle’s and Maven’s defaults. - No model. The recording, the values and the playback are all computed on your Mac.
Why replay instead of step#
A debugger is the most direct way to see what code does, and the slowest to use: you guess where to stop, press Step dozens of times, open variables one by one, and start over when the value you needed was set three calls earlier.
WTFCode turns that around. When a breakpoint is hit, a driver walks the function at full speed, records every line with its values, and lets your program go on. The editor then plays the recording at a pace you can follow, and it goes backwards too, which a live debugger can’t. Your request isn’t held while you watch, so nothing times out.
Debug a program#
- Set a breakpoint.
Open the source file and click the gutter beside a line, or press ⌘F8 on the caret’s line. The dot is hollow until loaded code has that line, then solid.
- Add a runner if the program has none.
Open the Run panel (⌥R) and choose New runner…. Give it a name and the command that starts your program, such as
./gradlew bootRunorjava -cp out Loop. Tick Run in a shell for pipes,&&and variables. - Choose Debug.
Right-click the runner and choose Debug, or use Debug in its header. WTFCode starts the same command with the JVM’s debug agent and attaches to every JVM it starts, Gradle and your app included. The header reads Debugger attached.
- Use your program.
Send the request, click through the screen, or run the job that reaches the line. Only the thread that hit is paused, and only for the milliseconds the walk takes.
- Watch the hit.
The editor opens at the breakpoint and plays the recording. Each line end shows the values the run had, such as
n = 7anddoubled = 14, and the card under the line is tagged Recorded, with its place: Line 3 · 1 of 3.
What a recording holds#
| Recorded | Details |
|---|---|
| Every line of your code | From the hit until its function returns, with the variables in scope and this, which changed, and the call stack. |
| Calls into your code | Stepped into when the callee is your folder’s code and less than two calls deep. Library, JDK and Kotlin runtime calls are stepped over. One-line getters and data-class members are skipped. |
| Returns and throws | A function’s return is a stop with its value; a throw in your code is a stop with what was thrown. |
| Values | Read by structure, never by running your code: strings, numbers, enums, BigDecimal; lists, sets and maps as their size and first three elements; other objects as their fields, one level deep. |
A walk stops after 5,000 steps and says so in its note. Every debug run is kept: Debug History in the command palette plays any of them again.
Playback and live stepping#
| Key | Does |
|---|---|
| Space | Pause or resume the playback |
| ↑ | Back a step |
| ↓ | Next step; on a held hit, step over |
| → | On a held hit, step into |
| ← | On a held hit, step out |
| F9 | Resume a held program |
| ⌘F8 | Toggle a breakpoint on the caret’s line |
| ⌘⇧F8 | View Breakpoints: every breakpoint of the folder, by file |
Hold on the card keeps the next hit of that breakpoint paused, for the times you want a classic session. Step it by hand with the keys above (F8, F7 and ⇧F8 in the IntelliJ keymap); each hand step comes back as a new stop. A held breakpoint’s dot turns orange with a pause mark.
View Breakpoints opens one at its line, holds it, or removes one or all. Stop debugging in the runner’s header lets the program run on without breakpoints.
Breakpoints work on a plain Run too#
Run, Restart and a group of runners start a saved runner with the debug agent too, so a breakpoint set before or while it runs is hit either way. Debug on a run that’s already attached just answers it; one started before is started again. Runs with no runner behind them, such as builds and Find Bugs’ tests, are left alone.
Current limits#
- JVM only for now. Python, Node and Go aren’t debugged yet. Their walkthroughs work without running anything.
- The card’s words come from the values, not from a model. A model reading the recording to explain each step is next.
- Kotlin coroutines aren’t grouped: a suspension that resumes on another thread ends the walk there. Breakpoints in inline functions are placed only in the file’s own classes.
- A held breakpoint is lost if an edit moves its line; set it again.
- Gradle’s daemon keeps its debug port after the run; WTFCode lets go of it when the run ends.
Troubleshooting#
The breakpoint dot stays hollow
No loaded class has that line yet. The class may not be loaded until the code path runs, or the line has no code (a blank line, a comment, a lone brace). Move it to the first line with a statement.
Local variables are missing from the line ends
The program was compiled without debug information, so the JVM has no names for them. Build with -g (javac) or the default Gradle and Maven settings.
Debugger attached, but nothing plays
The breakpoint hasn’t been reached. Check the runner’s log for the request, and that the breakpoint is in code that request runs. The program’s output should start with Picked up JAVA_TOOL_OPTIONS and Listening for transport dt_socket; if not, the program was started outside its runner.
Next steps#
Something unclear or out of date? Tell us; a person on the team reads every note.