[Dwarf-Discuss] How to generate DWARF info for a template alias to a raw pointer

Robinson, Paul paul.robinson@sony.com
Fri May 6 17:08:27 GMT 2022


> Could someone help to point out what kind of DWARF info should
> be generated for below c++ source? Thanks
>?
> ```
> template<class T>
> using ptr = T*;
>?
> ptr<int>? abc;
> ```
>?
> We declare a template alias here, so we may generate
> `DW_TAG_template_type_parameter` like:
>?
> ```
> 0x00000057:?? DW_TAG_base_type
> ??????????????? DW_AT_name? ("int")
> ??????????????? DW_AT_byte_size????????? (0x04)
> ??????????????? DW_AT_encoding?????????? (DW_ATE_signed)
>?
> 0x0000005e:?? DW_TAG_pointer_type
> ??????????????? DW_AT_type??? (0x00000057 "int")
>?
> 0x00000064:?? DW_TAG_template_alias
> ??????????????? DW_AT_name? ("ptr")
> ??????????????? DW_AT_type??? (0x0000005e "int *")
>?
> 0x00000076:???? DW_TAG_template_type_parameter
> ????????????????? DW_AT_name?????????????? ("T")
> ???????? ?????????DW_AT_type? (0x00000057 "int")
>?
> 0x0000007e:?? DW_TAG_variable
> ??????????????? DW_AT_name? ("abc")
> ??????????????? DW_AT_type??? (0x00000064 "ptr<int>")
> ```

This all looks okay to me, with DW_TAG_template_type_parameter
being a child of DW_TAG_template_alias.  There's an alias
named `ptr`, its formal parameter is `T`, its actual parameter
is `int`, and so the alias is a typedef of `int *`.

> ` DW_TAG_template_type_parameter ` should be for a notation to
> create a template base on another template, but as you can see
> the referred type?0x0000005e?is not a template. What kind of
> DWARF info should we generate here? We should use 
> ` DW_TAG_typedef` instead of ` DW_TAG_template_type_parameter`
> for this special case?

DW_TAG_template_type_parameter is correctly describing the
parameter to the template.

There's no need for a DW_TAG_typedef, because DW_TAG_template_alias
is implicitly a typedef.

--paulr




More information about the Dwarf-discuss mailing list