I wonder how to write a visual debugger? My question I guess is one that isn't asked all that often. And usually the articles are fairly hard to follow.
Given I have a hypothetical programming language and I want to step through some code, how exactly do I pause execution and evaluate and so on. Do these tools just read the an AST until a given point or is something more low level happening?
Has anyone wrote one? I'd love to hear your thoughts! 👨🔬
Top comments (8)
This is a fairly complex ask, as I would expect that you would need to write a custom interpreter for whatever language you're trying to debug. This is probably the most difficult part.
Some debuggers however are open source, so I would suggest forking one of those projects and working from there.
Thanks for reaching out, I realize this is a big ask so that's why I ask how they work more than anything else. OS is always an option but finding the right project when you don't understand it yet is like catch22
This is purely speculative, but I believe the debuggers run your code through a custom interpreter /compiler.
You're essentially taking over/replacing the process that normally executes your code.
This is why xdebug for PHP is written in C, for example, since PHP uses a C interpreter.
Interesting, this sounds reasonable. Okay so I am writing (very slowly) a programming language and did plan to put an interpreter together at some point. This Language is aiming to be compiled. My language is a subset of ES5 JavaScript with some bits that are wildly off spec, such as CSS as primitives and data structures. I guess I would look at forking an old js debugger and fixing it up.
That's probably a good way to get started to understanding how it works.
Eventually you'll probably want to cut out the middleman so you can debug your subset of Javascript without having to compile it first.
You could also look to see if there are any open source typescript debuggers, as that's more or less the same thing you're trying to do.
Excellent suggestions Brandon, thank you. 😁
If I wanted to do this I would definitely use LLVM. I suspect you would get the debugger for free (LLDB).
See this tutorial
Thank you that's a good start 🔥