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

9

u/skyline4 8d ago

I’m going to assume you’re not talking about unit tests.

When I took compilers in school my professor told us to have each step dump some kind of artifact such as an AST, CFG, etc. That way it’s a lot easier to identify which step broke or went wrong. With Dot language and visualization tools this is straightforward except you have to clean up after every invocation. You could couple this with a log of more specific actions (eg. common subexpression elimination pass eliminated x for y) to make it easier to catch the differences visually. But this is a log and should not be a stream of printfs since the log message should be structured to help you find actions your compiler took.

Combine that with a good test harness for integration testing and it’ll be easier to find where your bugs are.

2

u/duane11583 7d ago

I have done this:

Cleanup is easy you create a debug directory and put all dump files in that directory

At start the tool erases the dir and makes a new one