[Dwarf-Discuss] Discrepancy Between Implementation and Spec in Template Types

Jay Kamat jaygkamat@gmail.com
Thu Apr 9 17:36:54 GMT 2020


I wasn't on the list when I originally sent this message, and it didn't show 
up in the archive, so I'm sending it again. Sorry if there's duplication:

Hi!

I'm currently working on a debugger which consumes dwarf information
and I noticed a possible discrepancy between output from popular
compilers (gcc, clang) and the DWARF 5 and 4 spec.

In section 'D.11 Template Example' for the given source:

template<class T>
struct wrapper {
	T comp;
};
wrapper<int> obj;

It says:

The actual type of the component comp is int, but in the DWARF the
type references the DW_TAG_template_type_parameter for T, which in
turn references int. This implies that in the original template comp
was of type T and that was replaced with int in the instance.

And this is reflected in the example output:

11$: DW_TAG_structure_type
       DW_AT_name("wrapper")
12$:    DW_TAG_template_type_parameter
           DW_AT_name("T")
           DW_AT_type(reference to "int")
13$:    DW_TAG_member
           DW_AT_name("comp")
           DW_AT_type(reference to 12$)

Where the 'comp' DW_TAG_member has a type referencing to the
DW_TAG_template_type_parameter. However, upon compiling the given
example and dumping the dwarf (gcc 8.3.0, clang 7.0.1), I get:

0x0000085e:   DW_TAG_structure_type
               DW_AT_name  ("wrapper<int>")
               DW_AT_byte_size (0x04)
               DW_AT_decl_file ("/home/jay/Code/tmp/test/test.cpp")
               DW_AT_decl_line (6)
               DW_AT_decl_column   (0x08)
               DW_AT_sibling   (0x00000880)

0x0000086b:     DW_TAG_member
                 DW_AT_name    ("comp")
                 DW_AT_decl_file   ("/home/jay/Code/tmp/test/test.cpp")
                 DW_AT_decl_line   (7)
                 DW_AT_decl_column (0x04)
                 DW_AT_type    (0x00000057 "int")
                 DW_AT_data_member_location    (0x00)

0x00000878:     DW_TAG_template_type_parameter
                 DW_AT_name    ("T")
                 DW_AT_type    (0x00000057 "int")

Where the 'comp' DW_TAG_member points directly to the "int" type, and
nothing points to 0x878.

The information provided by the indirection mentioned in the spec is
useful, as it lets us determine which members are template parameters
(and could let us reconstruct the original templated type). As is, we
can only tell that there is a template parameter, and that it was
filled with type "int" in this case.

Is there a reason for this discrepancy, and is there anything that can
be done to resolve it? If I'm overlooking something simple, sorry!

Thanks in advance,
-Jay


PS: Sorry if this has already been discussed, but the search function
on the archive seems to be throwing an error:

Unable to read word database file
'/dh/mailman/rank/archives/private/dwarf-discuss-dwarfstd.org/htdig/db.words.db'
Did you run htdig?



More information about the Dwarf-discuss mailing list