Description
Currently the DWARF information does not include constant symbols (such as const x = 1
). This can make debugging more difficult, as constants available to the program are not available in the debugger. It also causes problems for debugging helpers. For example, our own runtime-gdb.py GDB helper hard-codes the G status constant values. This list gets out of date and means we can't cull now-unused G statuses.
We should include constants in the DWARF information. DWARF has a DW_TAG_constant for exactly this. The DW_AT_const_value attribute can be a string or any constant form, including DW_FORM_sdata, which is encoded as a LEB128, so in principle it can store arbitrary precision integers (though I don't know how well this is supported in practice). It's not clear to me how to represent floating point constants, though I suspect we'd have to truncate them to 64-bit precision to get them to actually work (despite DWARF's dizzying array of numeric type encodings; scaled packed decimal anyone?).
Doing this would be difficult right now because the compiler would have to emit constants in a way the linker could consume to produce DWARF information. It would probably be relatively straightforward if we switched to producing DWARF directly in the compiler.
/cc @ribrdb @derekparker