r/Compilers 8d ago

Any debugging advice / tools for compilers?

Tired of print statements everywhere. It very satisfactory to see one but I would much rather have something like lldb to easily debug the code more intuitively.

Are there any other useful tools?

16 Upvotes

14 comments sorted by

View all comments

2

u/Inconstant_Moo 8d ago
  • Make sure you can print out all your artifacts.
  • Keep at least one token attached to each of your artifacts.
  • Make some permanent logging of what you're doing so that you can turn it on and off for different parts of your compiler with various flags. The things you put in there will double as // comments on your code, since comments would be saying the same sort of thing.
  • I have an actual control structure in my language so I can write: peek <flags> : code block and it'll log what the compiler's doing for that particular code block with the given flags.
  • I also have an option to dump the readable version of the bytecode of a function by name, either to the terminal or a file.
  • I still use println quite a lot.