Hacker News new | ask | show | jobs
by saagarjha 1351 days ago
There are solutions, but with tradeoffs. In theory DWARF debugging metadata is Turing complete, so you could bundle an exact copy of the unoptimized program and fall back in that when someone requests something from the debugger. The JVM actually exposes this kind of level of access as API and it goes through astonishing amounts of effort to make sure that when you’re debugging the code gets shunted into the paths where this information is available rather than the highly optimized view that is normally executing.

In practice, well, things are complicated. Maintaining sane debug information across optimizations is pretty hard, and nobody really holds compiler author’s feet to the fire to make it happen. There’s a lot of low hanging fruit that should be fixed (for example an index→pointer conversion should be easy to undo, even though most compilers don’t generate the debug information for this). Likewise variables that just happen to be alive by chance should be made available. But I doubt we’ll ever get good support for things which have been fully optimized, though I think most programmers will forgive this.