pragma(breakpoint)

Ben Jones fake at fake.fake
Fri Aug 22 09:11:55 UTC 2025


In my dconf talk I mentioned an idea for helping to debug 
template metaprogramming issues and took a first pass at 
implementing my idea here: https://github.com/dlang/dmd/pull/21758

The insight I had is that when I debug TMP code, I spray my code 
with pragma(msg) and am doing basically printf debugging.  What 
would a "real" debugger for metaprograms look like?

I've implemented the first pieces that I think would be in such a 
tool:

* a way to specify breakpoints (pragma(breakpoint)
* a way to print a "backtrace"

In my implementation those two are intertwined and 
pragma(breakpoint) just prints the "backtrace" at that point in 
semantic analysis which is computed by tracing the scopes.

Ideally (eventually) pragma(breakpoint) would pause the compiler 
and provide analogues to normal debugger functions such as 
examining values (I think this would be the ability to info about 
various AST nodes), and once you're done inspecting the state of 
the compiler, you can "continue" to keep compiling.

Something that fell out naturally in the implementation is that 
you can make the breakpoints conditional by putting them in a 
static if block.

Does this seem like a useful addition?  What's missing from my 
outline and/or implementation.  How do people think they might 
use a tool like this?


More information about the Digitalmars-d mailing list