DW_TAG_formal_parameter children of DW_TAG_inlined_subroutine are currently skipped, so callers cannot iterate parameters belonging to a specific inline expansion. Store these parameters on struct inline_expansion rather than in the surrounding lexical block. Initialize and populate the list while processing inline-subroutine children, include it in tag traversal, and release it with its parent inline expansion. Parameter type and location recoding is kept separate, to follow in a subsequent change. Signed-off-by: Thierry Treyer Signed-off-by: Alan Maguire --- dwarf_loader.c | 32 +++++++++++++++++++------------- dwarves.c | 34 ++++++++++++++++++++++++++++++++++ dwarves.h | 6 ++++++ 3 files changed, 59 insertions(+), 13 deletions(-) diff --git a/dwarf_loader.c b/dwarf_loader.c index 1e5363a..c08d2ab 100644 --- a/dwarf_loader.c +++ b/dwarf_loader.c @@ -2022,6 +2022,8 @@ static struct inline_expansion *inline_expansion__new(Dwarf_Die *die, struct cu dwarf_tag__set_attr_type(dtag, DWARF_TAG__REF_TYPE, die, DW_AT_abstract_origin, cu); exp->ip.addr = 0; exp->high_pc = 0; + exp->nr_parms = 0; + INIT_LIST_HEAD(&exp->parms); if (!cu->has_addr_info) goto out; @@ -2559,6 +2561,7 @@ static struct tag *die__create_new_string_type(Dwarf_Die *die, struct cu *cu) static struct tag *die__create_new_parameter(Dwarf_Die *die, struct ftype *ftype, struct lexblock *lexblock, + struct inline_expansion *exp, struct cu *cu, struct conf_load *conf, int param_idx) { @@ -2575,7 +2578,7 @@ static struct tag *die__create_new_parameter(Dwarf_Die *die, if (add_gnu_annotation_chain(die, param_idx, conf, &(tag__function(&ftype->tag)->annots))) return NULL; } - } else { + } else if (exp == NULL) { /* * DW_TAG_formal_parameters on a non DW_TAG_subprogram nor * DW_TAG_subroutine_type tag happens sometimes, likely due to @@ -2656,7 +2659,7 @@ static struct tag *die__create_new_subroutine_type(Dwarf_Die *die, tag__print_not_supported(die); continue; case DW_TAG_formal_parameter: - tag = die__create_new_parameter(die, ftype, NULL, cu, conf, -1); + tag = die__create_new_parameter(die, ftype, NULL, NULL, cu, conf, -1); break; case DW_TAG_unspecified_parameters: ftype->unspec_parms = 1; @@ -2946,10 +2949,14 @@ static struct tag *die__create_new_inline_expansion(Dwarf_Die *die, struct lexblock *lexblock, struct cu *cu, struct conf_load *conf); -static int die__process_inline_expansion(Dwarf_Die *die, struct lexblock *lexblock, struct cu *cu, struct conf_load *conf) +static int die__process_inline_expansion(Dwarf_Die *die, + struct inline_expansion *exp, + struct lexblock *lexblock, + struct cu *cu, struct conf_load *conf) { Dwarf_Die child; struct tag *tag; + int parm_idx = 0; if (!dwarf_haschildren(die) || dwarf_child(die, &child) != 0) return 0; @@ -2975,13 +2982,9 @@ static int die__process_inline_expansion(Dwarf_Die *die, struct lexblock *lexblo goto out_enomem; continue; case DW_TAG_formal_parameter: - /* - * Inline expansions can have their own formal - * parameter children duplicating the abstract - * origin's parameters. These are not needed - * for type reconstruction — skip them. - */ - continue; + tag = die__create_new_parameter(die, NULL, lexblock, exp, + cu, conf, parm_idx++); + break; case DW_TAG_inlined_subroutine: tag = die__create_new_inline_expansion(die, lexblock, cu, conf); break; @@ -3010,6 +3013,8 @@ static int die__process_inline_expansion(Dwarf_Die *die, struct lexblock *lexblo if (cu__table_add_tag(cu, tag, &id) < 0) goto out_delete_tag; + if (tag->tag == DW_TAG_formal_parameter) + inline_expansion__add_parameter(exp, tag__parameter(tag)); hash: cu__hash(cu, tag); struct dwarf_tag *dtag = tag__dwarf(tag); @@ -3032,8 +3037,8 @@ static struct tag *die__create_new_inline_expansion(Dwarf_Die *die, if (exp == NULL) return NULL; - if (die__process_inline_expansion(die, lexblock, cu, conf) != 0) { - tag__free(&exp->ip.tag, cu); + if (die__process_inline_expansion(die, exp, lexblock, cu, conf) != 0) { + tag__delete(&exp->ip.tag, cu); return NULL; } @@ -3115,7 +3120,8 @@ static int die__process_function(Dwarf_Die *die, struct ftype *ftype, continue; } case DW_TAG_formal_parameter: - tag = die__create_new_parameter(die, ftype, lexblock, cu, conf, param_idx++); + tag = die__create_new_parameter(die, ftype, lexblock, NULL, + cu, conf, param_idx++); break; case DW_TAG_variable: tag = die__create_new_variable(die, cu, conf, 0); diff --git a/dwarves.c b/dwarves.c index 2164030..2bb5c18 100644 --- a/dwarves.c +++ b/dwarves.c @@ -203,6 +203,27 @@ void formal_parameter_pack__delete(struct formal_parameter_pack *pack, struct cu cu__tag_free(cu, &pack->tag); } +static void inline_expansion__delete_tags(struct inline_expansion *exp, + struct cu *cu) +{ + struct tag *pos, *n; + + list_for_each_entry_safe_reverse(pos, n, &exp->parms, node) { + list_del_init(&pos->node); + tag__delete(pos, cu); + } +} + +static void inline_expansion__delete(struct inline_expansion *exp, + struct cu *cu) +{ + if (exp == NULL) + return; + + inline_expansion__delete_tags(exp, cu); + cu__tag_free(cu, &exp->ip.tag); +} + void tag__delete(struct tag *tag, struct cu *cu) { if (tag == NULL) @@ -225,6 +246,8 @@ void tag__delete(struct tag *tag, struct cu *cu) ftype__delete(tag__ftype(tag), cu); break; case DW_TAG_subprogram: function__delete(tag__function(tag), cu); break; + case DW_TAG_inlined_subroutine: + inline_expansion__delete(tag__inline_expansion(tag), cu); break; case DW_TAG_lexical_block: lexblock__delete(tag__lexblock(tag), cu); break; case DW_TAG_GNU_template_parameter_pack: @@ -1476,6 +1499,13 @@ void lexblock__add_tag(struct lexblock *block, struct tag *tag) list_add_tail(&tag->node, &block->tags); } +void inline_expansion__add_parameter(struct inline_expansion *exp, + struct parameter *parm) +{ + ++exp->nr_parms; + list_add_tail(&parm->tag.node, &exp->parms); +} + void lexblock__add_inline_expansion(struct lexblock *block, struct inline_expansion *exp) { @@ -2059,6 +2089,10 @@ static int list__for_all_tags(struct list_head *list, struct cu *cu, if (list__for_all_tags(&tag__lexblock(pos)->tags, cu, iterator, cookie)) return 1; + } else if (pos->tag == DW_TAG_inlined_subroutine) { + if (list__for_all_tags(&tag__inline_expansion(pos)->parms, + cu, iterator, cookie)) + return 1; } if (iterator(pos, cu, cookie)) diff --git a/dwarves.h b/dwarves.h index f3453ed..f620db8 100644 --- a/dwarves.h +++ b/dwarves.h @@ -825,6 +825,8 @@ struct inline_expansion { struct ip_tag ip; size_t size; uint64_t high_pc; + struct list_head parms; + uint16_t nr_parms; }; static inline struct inline_expansion * @@ -833,6 +835,10 @@ static inline struct inline_expansion * return (struct inline_expansion *)tag; } +struct parameter; +void inline_expansion__add_parameter(struct inline_expansion *exp, + struct parameter *parm); + struct label { struct ip_tag ip; const char *name; -- 2.43.5