Issue 190407.2: Allow debug functions that clarify which of a union is valid.

Author: Shawn Landden
Champion: Eric Christopher
Date submitted: 2019-04-07
Date revised:
Date closed: 2023-11-13
Type: Enhancement
Status: Withdrawn (Incomplete)
DWARF Version: 6

Section 5.7, pg 113

In some large code bases I work on (such as Zig's stage1 compiler), there is a structure with a large union, of which only one is valid at a certain time, and clarified based on an ID attribute. It would be nice if the DWARF standard could clarify a way that the program could provide a clarifying function that would say which option of the union is valid at any certain time.

While this function that gets called would be hard to write in C or C++ (and the compiler doesn't have enough information to figure this out), as there is not much introspection abilities, in Zig it would be easy, and it would improve the utility of the debugger.


2023-11-13: Unclear what original author is asking for here -- a way of calling a function (i.e., an inferior call) to resolve the variant, or some clarification in the standard. It was suggested that Ada's variant records might work the same way, so that Zig could use the same mechanism that Ada uses.

(Todd A): I don't know anything about Zig, but if it allows a languaged-defined mapping of IDs to particular fields of the union, then maybe it's not so different from Ada variant records. The Zig compiler could add DW_TAG_variant and DW_TAG_variant_parts to indicate which field is valid. Unless it really does require calling a function, as the proposal implies. But maybe that wasn't so much a requiement as an off-hand thought. It seems like this might not require new DWARF but, yeah, we'd need someone who knows Zig to weigh in on this.