summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSerhei Makarov <[email protected]>2025-02-03 16:45:20 -0500
committerSerhei Makarov <[email protected]>2025-02-03 16:45:28 -0500
commitd4c0992f6dda5ed9e62190a808a2cd4d651a9220 (patch)
tree6ba841e34e3859575e33ba8dc34b0a796bd58978
parent69fcf83f3dd4ed848503c8cc91d4edb226493323 (diff)
fixup for DRAFT e38ce78: cache Elf * in open_elf
Caching behaviour is improving. The commented assert still catches some cases where a redundant Elf * is being created. * dwfl_module_getdwarf.c (open_elf): Cache file->elf in Dwfl_Process_Tracker.
-rw-r--r--libdwfl/dwfl_module_getdwarf.c12
-rw-r--r--libdwfl/dwfl_process_tracker_find_elf.c1
2 files changed, 12 insertions, 1 deletions
diff --git a/libdwfl/dwfl_module_getdwarf.c b/libdwfl/dwfl_module_getdwarf.c
index 6f98c02b..6aa87fdf 100644
--- a/libdwfl/dwfl_module_getdwarf.c
+++ b/libdwfl/dwfl_module_getdwarf.c
@@ -79,6 +79,18 @@ open_elf (Dwfl_Module *mod, struct dwfl_file *file)
if (error != DWFL_E_NOERROR)
return error;
+ /* Cache file->elf in Dwfl_Process_Tracker if available: */
+ if (mod->dwfl->tracker != NULL && file->name != NULL)
+ {
+ dwfltracker_elftab_ent *ent = __libdwfl_process_tracker_elftab_find (mod->dwfl->tracker, file->name, false/* should_resize */);
+ if (ent != NULL)
+ {
+ /* assert(ent->elf == NULL || ent->elf == file->elf); */ /* TODO(PRERELEASE): Guard against redundant/leaked Elf *. */
+ assert(ent->fd == file->fd); /* TODO(PRERELEASE): Guard against redundant open. */
+ ent->elf = file->elf;
+ }
+ }
+
GElf_Ehdr ehdr_mem, *ehdr = gelf_getehdr (file->elf, &ehdr_mem);
if (ehdr == NULL)
{
diff --git a/libdwfl/dwfl_process_tracker_find_elf.c b/libdwfl/dwfl_process_tracker_find_elf.c
index d1871071..20c48bea 100644
--- a/libdwfl/dwfl_process_tracker_find_elf.c
+++ b/libdwfl/dwfl_process_tracker_find_elf.c
@@ -82,7 +82,6 @@ dwfl_process_tracker_find_elf (Dwfl_Module *mod,
/* XXX fd < 0 implies elf_from_remote_memory, uses base, not cacheable */
if (tracker != NULL && ent != NULL && fd >= 0 && *file_name != NULL)
{
- /* TODO(WIP): *elfp may be NULL here, need to be populated later. */
ent->elf = *elfp;
ent->fd = fd;
rc = fstat(fd, &sb);