Skip to content

Commit 8a1e023

Browse files
committed
dwarf_loader: Initial support for DW_TAG_template_type_param tag
We don't really need to pretty print these, as the names of the classes already come with it, for instance: ⬢[acme@toolbox [email protected]]$ pdwtags popup.cpp.o | grep ^'struct integral_constant' -A11 die__process_class: tag not supported 0x30 (template_value_parameter) at <5f0>! die__process_function: tag not supported 0x2f (template_type_parameter) at <1417>! die__process_class: tag not supported 0x4107 (GNU_template_parameter_pack) at <f1d8>! die__process_function: tag not supported 0x4108 (GNU_formal_parameter_pack) at <69aea>! struct integral_constant<bool, true> { typedef bool value_type; value_type operator std::integral_constant<bool, true>::value_type(const struct integral_constant<bool, true> *); value_type operator()(const struct integral_constant<bool, true> *); /* size: 1, cachelines: 0, members: 0 */ /* padding: 1 */ /* last cacheline: 1 bytes */ }; /* size: 0 */ -- struct integral_constant<bool, false> { typedef bool value_type; value_type operator std::integral_constant<bool, false>::value_type(const struct integral_constant<bool, false> *); value_type operator()(const struct integral_constant<bool, false> *); /* size: 1, cachelines: 0, members: 0 */ /* padding: 1 */ /* last cacheline: 1 bytes */ }; /* size: 0 */ ⬢[acme@toolbox [email protected]]$ But lets collect this info, that only shows up in C++ (maybe other languages, Rust?), we'll end up using it maybe for using them for looking up all templates, or all templates of a given type or value, etc. I'll do the same for DW_TAG_template_value_parameter and support both in DW_TAG_subprogram. DW_TAG_GNU_template_parameter_pack must be some variation on this theme... Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
1 parent 24009d1 commit 8a1e023

File tree

3 files changed

+39
-1
lines changed

3 files changed

+39
-1
lines changed

dwarf_loader.c

+21-1
Original file line numberDiff line numberDiff line change
@@ -1082,6 +1082,18 @@ static void arch__set_register_params(const GElf_Ehdr *ehdr, struct cu *cu)
10821082
}
10831083
}
10841084

1085+
static struct template_type_param *template_type_param__new(Dwarf_Die *die, struct cu *cu, struct conf_load *conf)
1086+
{
1087+
struct template_type_param *ttparm = tag__alloc(cu, sizeof(*ttparm));
1088+
1089+
if (ttparm != NULL) {
1090+
tag__init(&ttparm->tag, cu, die);
1091+
ttparm->name = attr_string(die, DW_AT_name, conf);
1092+
}
1093+
1094+
return ttparm;
1095+
}
1096+
10851097
static struct parameter *parameter__new(Dwarf_Die *die, struct cu *cu,
10861098
struct conf_load *conf, int param_idx)
10871099
{
@@ -1800,7 +1812,6 @@ static int die__process_class(Dwarf_Die *die, struct type *class,
18001812
case DW_TAG_GNU_template_parameter_pack:
18011813
case DW_TAG_GNU_template_template_param:
18021814
#endif
1803-
case DW_TAG_template_type_parameter:
18041815
case DW_TAG_template_value_parameter:
18051816
/*
18061817
* FIXME: probably we'll have to attach this as a list of
@@ -1811,6 +1822,15 @@ static int die__process_class(Dwarf_Die *die, struct type *class,
18111822
*/
18121823
tag__print_not_supported(die);
18131824
continue;
1825+
case DW_TAG_template_type_parameter: {
1826+
struct template_type_param *ttparm = template_type_param__new(die, cu, conf);
1827+
1828+
if (ttparm == NULL)
1829+
return -ENOMEM;
1830+
1831+
type__add_template_type_param(class, ttparm);
1832+
continue;
1833+
}
18141834
case DW_TAG_inheritance:
18151835
case DW_TAG_member: {
18161836
struct class_member *member = class_member__new(die, cu, is_union, conf);

dwarves.c

+6
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,7 @@ void __type__init(struct type *type)
365365
{
366366
INIT_LIST_HEAD(&type->node);
367367
INIT_LIST_HEAD(&type->type_enum);
368+
INIT_LIST_HEAD(&type->template_type_params);
368369
type->sizeof_member = NULL;
369370
type->member_prefix = NULL;
370371
type->member_prefix_len = 0;
@@ -1329,6 +1330,11 @@ void type__add_member(struct type *type, struct class_member *member)
13291330
namespace__add_tag(&type->namespace, &member->tag);
13301331
}
13311332

1333+
void type__add_template_type_param(struct type *type, struct template_type_param *ttparam)
1334+
{
1335+
list_add_tail(&ttparam->tag.node, &type->template_type_params);
1336+
}
1337+
13321338
struct class_member *type__last_member(struct type *type)
13331339
{
13341340
struct class_member *pos;

dwarves.h

+12
Original file line numberDiff line numberDiff line change
@@ -1121,6 +1121,15 @@ static __pure inline int tag__is_class_member(const struct tag *tag)
11211121
return tag->tag == DW_TAG_member;
11221122
}
11231123

1124+
/* struct template_type_param - parameters to a template, stored in 'struct type'
1125+
*/
1126+
struct template_type_param {
1127+
struct tag tag;
1128+
const char *name;
1129+
};
1130+
1131+
void template_type_param__delete(struct template_type_param *ttparam);
1132+
11241133
int tag__is_base_type(const struct tag *tag, const struct cu *cu);
11251134
bool tag__is_array(const struct tag *tag, const struct cu *cu);
11261135

@@ -1172,6 +1181,7 @@ struct type {
11721181
uint8_t fwd_decl_emitted:1;
11731182
uint8_t resized:1;
11741183
uint8_t is_signed_enum:1;
1184+
struct list_head template_type_params;
11751185
};
11761186

11771187
void __type__init(struct type *type);
@@ -1289,6 +1299,8 @@ static inline struct class_member *class_member__next(struct class_member *membe
12891299
list_for_each_entry_safe_reverse(pos, n, &(type)->namespace.tags, tag.node)
12901300

12911301
void type__add_member(struct type *type, struct class_member *member);
1302+
void type__add_template_type_param(struct type *type, struct template_type_param *ttparm);
1303+
12921304
struct class_member *
12931305
type__find_first_biggest_size_base_type_member(struct type *type,
12941306
const struct cu *cu);

0 commit comments

Comments
 (0)