调试器即REPL,即调试器
A Debugger is a REPL is a Debugger

原始链接: https://matklad.github.io/2025/03/25/debugger-is-repl-is-debugger.html

传统的调试器,例如gdb和lldb,在原生代码开发方面存在不足,缺乏有效探索所需的交互式REPL体验。一种更高效的方法是利用IntelliJ IDEA的“运行到光标处”和“快速评估表达式”功能。 “运行到光标处”能够声明式地将执行推进到光标所在位置,取代了繁琐的单步导航。“快速评估表达式”允许在当前上下文中评估任意代码片段,从而实现交互式实验。 这将调试转变为在有趣的执行点之间“跳跃”并进行即时实验的过程。此工作流程的关键方面包括:在编辑器中直接进行完整的代码补全,无缝评估上下文中的新代码,以及能够重新加载代码更改。这结合了调试器的断点功能和REPL的交互性,通过方便的点击式光标界面而不是命令行输入来访问。它有效地将调试器变成了IDE内的REPL。

Hacker News 最新 | 往期 | 评论 | 提问 | 展示 | 招聘 | 提交 登录 调试器即REPL即调试器 (matklad.github.io) ingve 1小时前 5分 | 隐藏 | 往期 | 收藏 | 1条评论 porridgeraisin 10分钟前 [–] $ alias breakpoint alias breakpoint=' while read -p"调试(Ctrl-d退出)> " debugging_line do eval "$debugging_line" done ' 可以在任何bash脚本中插入的好的断点REPL 回复 加入我们,参加6月16日至17日在旧金山举办的AI创业学校! 指南 | 常见问题 | 列表 | API | 安全 | 法律 | 申请YC | 联系我们 搜索:
相关文章
  • rr – C/C++ 的记录和重播调试器 2024-07-22
  • (评论) 2024-06-13
  • (评论) 2025-03-22
  • (评论) 2024-07-27
  • (评论) 2024-09-04

  • 原文

    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!

    联系我们 contact @ memedata.com