Add BTF inline sites to the CU representation. Signed-off-by: Alan Maguire --- btf_loader.c | 47 +++++++++++++++++++++++++++++++++++++++++++---- dwarves.c | 1 + dwarves.h | 11 +++++++++++ 3 files changed, 55 insertions(+), 4 deletions(-) diff --git a/btf_loader.c b/btf_loader.c index 4dea882..821a6d8 100644 --- a/btf_loader.c +++ b/btf_loader.c @@ -25,8 +25,6 @@ #include #include -#include - #include "dutil.h" #include "dwarves.h" @@ -36,6 +34,28 @@ struct btf_locsec_entry { uint32_t offset; }; +static void btf__add_inline_site(struct cu *cu, const char *section_name, + const struct btf_locsec_entry *entry) +{ + struct tag *tag = cu__function(cu, entry->func); + struct btf_inline_site *site; + + if (!tag || !section_name) + return; + site = zalloc(sizeof(*site)); + if (!site) + return; + site->section_name = strdup(section_name); + if (!site->section_name) { + free(site); + return; + } + site->function = tag__function(tag); + site->section_offset = entry->offset; + site->loc_proto = entry->loc_proto; + list_add_tail(&site->node, &cu->btf_inline_sites); +} + static const char *cu__btf_str(struct cu *cu, uint32_t offset) { return offset ? btf__str_by_offset(cu->priv, offset) : NULL; @@ -647,6 +667,12 @@ static int btf__load_types(struct btf *btf, struct cu *cu) * loaded. */ break; + case BTF_KIND_LOC_PARAM: + case BTF_KIND_LOC_PROTO: + case BTF_KIND_LOCSEC: + /* LOCSEC is decoded after the ordinary BTF types are loaded. */ + err = 0; + break; default: fprintf(stderr, "BTF: idx: %d, Unknown kind %d\n", type_index, type); fflush(stderr); @@ -694,7 +720,7 @@ static void btf__mark_inline_functions(struct btf *btf, struct cu *cu) for (type_index = 1; type_index < btf__type_cnt(btf); type_index++) { const struct btf_locsec_entry *entries; const char *name; - uint16_t i; + uint32_t i, nr_entries; type_ptr = btf__type_by_id(btf, type_index); type = btf_kind(type_ptr); @@ -706,12 +732,18 @@ static void btf__mark_inline_functions(struct btf *btf, struct cu *cu) if (!name || !strstarts(name, "inline")) continue; + /* LOCSEC uses the extended 24-bit vlen introduced with the + * location BTF kinds. Older libbpf headers still expose the + * original 16-bit btf_vlen() helper. + */ + nr_entries = type_ptr->info & 0x00ffffff; entries = (const struct btf_locsec_entry *)(type_ptr + 1); - for (i = 0; i < btf_vlen(type_ptr); i++) { + for (i = 0; i < nr_entries; i++) { struct tag *tag = cu__function(cu, entries[i].func); if (tag) tag__function(tag)->inlined = DW_INL_declared_inlined; + btf__add_inline_site(cu, name + strlen("inline"), &entries[i]); } } } @@ -851,6 +883,13 @@ static int cu__fixup_btf_bitfields(const struct conf_load *conf, struct cu *cu) static void btf__cu_delete(struct cu *cu) { + struct btf_inline_site *site, *n; + + list_for_each_entry_safe(site, n, &cu->btf_inline_sites, node) { + list_del(&site->node); + free(site->section_name); + free(site); + } btf__free(cu->priv); cu->priv = NULL; } diff --git a/dwarves.c b/dwarves.c index 2bb5c18..fe4f5e4 100644 --- a/dwarves.c +++ b/dwarves.c @@ -756,6 +756,7 @@ struct cu *cu__new(const char *name, uint8_t addr_size, cu->dfops = NULL; INIT_LIST_HEAD(&cu->tags); INIT_LIST_HEAD(&cu->tool_list); + INIT_LIST_HEAD(&cu->btf_inline_sites); INIT_LIST_HEAD(&cu->node); cu->addr_size = addr_size; diff --git a/dwarves.h b/dwarves.h index 746f94e..ba7dd77 100644 --- a/dwarves.h +++ b/dwarves.h @@ -292,12 +292,23 @@ struct debug_fmt_ops { bool has_alignment_info; }; +/* A BTF LOCSEC record describing one inline expansion. */ +struct function; +struct btf_inline_site { + struct list_head node; + struct function *function; + char *section_name; + uint32_t section_offset; + uint32_t loc_proto; +}; + #define ARCH_MAX_REGISTER_PARAMS 8 struct cu { struct list_head node; struct list_head tags; struct list_head tool_list; /* To be used by tools such as ctracer */ + struct list_head btf_inline_sites; struct ptr_table types_table; struct ptr_table functions_table; struct ptr_table tags_table; -- 2.43.5