DEV Community

Discussion on: How do you write a breakpointed visual debugger?

Collapse
 
brandinchiu profile image
Brandin Chiu

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.

Collapse
 
adam_cyclones profile image
Adam Crockett 🌀

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

Collapse
 
brandinchiu profile image
Brandin Chiu

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.

Thread Thread
 
adam_cyclones profile image
Adam Crockett 🌀

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.

Thread Thread
 
brandinchiu profile image
Brandin Chiu

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.

Thread Thread
 
adam_cyclones profile image
Adam Crockett 🌀

Excellent suggestions Brandon, thank you. 😁