A Debugger is a REPL is a Debugger

I love debuggers! The last time I used a debugger seriously was in 2017 or so, when I was still coding in Kotlin. Ive since switched to working with native code, and, sadly gdb and lldb are of almost no help for me. This is because they are mere debuggers, but what I need is a REPL, and a debugger, all in one. In this article I show a more productive way to use debuggers as REPLS.

The trick boils down to two IntelliJ IDEA features, Run to Cursor and Quick Evaluate Expression.

The first feature, run to cursor, resumes the program until it reaches the line where the cursor is at. It is a declarative alternative to the primitive debugger features for stepping into, over, and out rather telling the debugger how to do every single step, you just directly tell it where do you want to be:

The second feature, quick evaluate expression, evaluates selected test in the context of the current stack frame. Crucially, this neednt be some pre-existing expression, you can type new stuff and evaluate it!

Run to cursor sets up the interesting context, and quick evaluate allows you to poke around. This two features completely change how I used debuggers instead of stepping through my program and observing it, I zap between interesting points of its execution and run experiments.

Authors of debuggers & REPLs, take note of these features of the workflow:

Theres no prompt anywhere. The medium of interaction is the 2D program text, not 1D command line. Its a vi interface, not ed interface.

From the debugger side, we support seamless evaluation of new program text in context. When entering new text, you get full code completion experience. I havent used this a tonne, but it should also be possible to reload code with your changes.

From the REPL side, you need breakpoints. Top-level context is rarely interesting! You need to be able to place yourself in the middle of your application, where you have access to all the locals. Debuggers do this via setting breakpoints, but the click-on-the-fringe (or, worse, enter file:line:column textually) UI is atrocious. Theres a perfectly fine pointing device in any editor the cursor. Just get the program execution to that point!