DWARF Standard


141117.1 Adrian Prantl Arbitrary expressions as formal parameter default values Enhancement Open Adrian Prantl

Section 4, pg 
Background for discussion

Languages such as C++ allow for arbitrary expressions to be provided
as default arguments. In particular, C++11 allows any initializer
expression as a default argument as the following example from the
language specification illustrates::

    int a = 1;
    int f(int);
    int g(int x = f(a));
    void h() {
      a = 2;
      int a = 3;
      g(); // g(f(::a)) --> g(f(2))

    from (8.3.6) http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3690.pdf

It would be useful to encode default arguments in DWARF because
developers may want to evaluate expressions in the context of the
program. Currently, it is possible to encode constant-value default
arguments in DWARF. While at first it may seem tempting to try and
encode default arguments using DWARF expressions, this is actually not
possible, because DWARF expressions cannot call into user code; i.e.,
it would be impossible to express the above default argument of
::f(::a) as a DWARF expression.

We therefore suggest encoding complex default arguments as strings
containing a fragment in the programming language specified by the
compile unit. A consumer that is sophisticated enough to make use of a
default expression should also be able to evaluate a source language

Section 4.1 Data Object Entries

A DW_AT_default_value attribute for a formal parameter entry. The
value of this attribute may be a constant, or a reference to the
debugging information entry for a variable, or a reference to a
debugging information entry containing a DWARF procedure.

, or a string containing a source language fragment.
If the attribute form is of class string, that string is interpreted
as an expression in the source language defined by the compilation
unit's DW_AT_language attribute that is to be evaluated according to
the rules defined by the source language.

Table 7.5: Attribute encodings
DW_AT_default_value    0x1e   constant, reference, flag, string

11/19/2014 -- Deferred to version 6.

All logos and trademarks in this site are property of their respective owner.
The comments are property of their posters, all the rest © 2007-2017 by DWARF Standards Committee.