diff --git a/ctf_encoder.c b/ctf_encoder.c index eded132..780ef01 100644 --- a/ctf_encoder.c +++ b/ctf_encoder.c @@ -253,6 +253,8 @@ int cu__encode_ctf(struct cu *self) hlist_add_head(&function->tool_hnode, head); } + cu__cache_symtab(self); + GElf_Sym sym; const char *sym_name; cu__for_each_cached_symtab_entry(self, id, sym, sym_name) { diff --git a/dwarves.h b/dwarves.h index 1f07504..3352afd 100644 --- a/dwarves.h +++ b/dwarves.h @@ -124,10 +124,11 @@ struct cu { struct ptr_table tags_table; char *name; char *filename; - Elf *elf; - Dwfl_Module *dwfl; void *priv; struct cu_orig_info *orig_info; + Elf *elf; + Dwfl_Module *dwfl; + uint32_t cached_symtab_nr_entries; uint8_t addr_size; uint8_t extra_dbg_info:1; uint16_t language; @@ -147,6 +148,11 @@ struct cu *cu__new(const char *name, uint8_t addr_size, const char *filename); void cu__delete(struct cu *self); +static inline void cu__cache_symtab(struct cu *self) +{ + self->cached_symtab_nr_entries = dwfl_module_getsymtab(self->dwfl); +} + /** * cu__for_each_cached_symtab_entry - iterate thru the cached symtab entries * @cu: struct cu instance @@ -155,10 +161,9 @@ void cu__delete(struct cu *self); * @name: char pointer where the symbol_name will be stored */ #define cu__for_each_cached_symtab_entry(cu, id, pos, name) \ - uint32_t n = dwfl_module_getsymtab(cu->dwfl); \ for (id = 1, \ name = dwfl_module_getsym(cu->dwfl, id, &sym, NULL); \ - id < n; \ + id < cu->cached_symtab_nr_entries; \ ++id, name = dwfl_module_getsym(cu->dwfl, id, &sym, NULL)) /**