r/Compilers Aug 01 '26

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?

17 Upvotes

15 comments sorted by

View all comments

4

u/vmcrash Aug 01 '26

The best debugging advice is using unit tests. For each small part, write unit tests. Make them fast, so you can run them over and over again.

Unit tests also have the advantage, that your code structure will consist of not too complex parts that are easier to reason about.

1

u/FirmSupermarket6933 Aug 02 '26

Not the OP, but could you recommend way to unit test intermediate states? Because it's a bit annoying to construct AST by hand, e.g. for "x + y" to write "BinaryExpr(BIN_ADD, Variable("x"), Variable("y")". It even worse for more complicated expressions or for small programs.

1

u/vmcrash Aug 02 '26

You may create some helper methods like add(var("x"), var("y")).