[RFC] Debuginfo: Add default value support for subprogram arguments

Robinson, Paul Paul_Robinson at playstation.sony.com
Fri Aug 15 18:18:08 PDT 2014


> The Dwarf standard reads: 
>
> A DW_AT_default_value attribute for a formal parameter entry. The value of
> this attribute is a reference to the debugging information entry for a
> variable or subroutine, or the value may be a constant. If the attribute
> form is of class reference, the default value of the parameter is the value
> of the referenced variable (which may be constant) or the value returned by
> the referenced subroutine; a reference value of 0 means that no default
> value has been specified. If the value is of class constant, that constant
> is interpreted as a default value of the type of the formal parameter.
>
> For a constant form there is no way to express the absence of a default value. 

As a committee member I cringe at what the spec says here; you'd express the
absence of a default value by omitting the attribute, duh.

>
> As you can see, this text limits us to emitting information about default
> values being:
> - simple constants (DW_FORM_data*)
> - global variable (DW_FORM_ref*)
> - calls to functions without arguments (DW_FORM_ref*)

As written, yeah it does have that restriction.  Seems like more complicated
default-value computations could be handled with a DWARF expression, but 
there's no provision in the spec for the attribute being an expression.
(Which doesn't stop you from inventing one; go right ahead!)

>
> I tried to go a bit further and implement a more complete solution that adds:
> - any link time constant (DW_FORM_block*): in this form, the block of data
> represents the default value as it would be stored in the target memory
> - arbitrary complex expressions (DW_FORM_str*): when no other of the above
> forms fits, this dumps the default value expression as textual form. The
> debugger can then evaluate this expression in the context of the declaration
> if it has this capacity
>
> First of all, would these kind of extensions be welcome? If you agree that
> they are worthwhile, I’ll submit a request to augment the standard wording.

As I mentioned above, more complicated expressions should be expressed as
DWARF expressions, you just need to invent a way for the attribute to
reference the expression.  It's the end of a long week or I'd look up
some ways to do that for you (sorry).

You are more than welcome to propose enhancements like this on the
DWARF website (dwarfstd.org).  The deadline for new features in DWARF 5
has passed, so it would be a while before it actually made it into a
published standard, but that gives you plenty of time for your
practical experience with implementing it!

--paulr





More information about the llvm-commits mailing list