+2023-09-27 Omar Sandoval <osandov@fb.com>
+
+ * libdwP.h ((Dwarf): Add elfpath.
+ * dwarf_begin_elf.c (__libdw_debugdir): Replace declaration with...
+ (__libdw_elfpath): New declaration.
+ (__libdw_set_debugdir): New declaration.
+ (__libdw_debugdir): Replace with..
+ (__libdw_elfpath): New function.
+ (__libdw_set_debugdir): New function.
+ (valid_p): Call __libdw_elfpath and __libdw_set_debugdir instead of
+ __libdw_debugdir.
+ * dwarf_end.c (dwarf_end): Free dwarf->elfpath.
+
2023-09-27 Omar Sandoval <osandov@fb.com>
* libdw_find_split_unit.c (try_split_file): Make static.
return result;
}
-
-/* Helper function to set debugdir field. We want to cache the dir
- where we found this Dwarf ELF file to locate alt and dwo files. */
char *
-__libdw_debugdir (int fd)
+__libdw_elfpath (int fd)
{
/* strlen ("/proc/self/fd/") = 14 + strlen (<MAXINT>) = 10 + 1 = 25. */
char devfdpath[25];
sprintf (devfdpath, "/proc/self/fd/%u", fd);
- char *fdpath = realpath (devfdpath, NULL);
- char *fddir;
- if (fdpath != NULL && fdpath[0] == '/'
- && (fddir = strrchr (fdpath, '/')) != NULL)
- {
- *++fddir = '\0';
- return fdpath;
- }
- return NULL;
+ return realpath (devfdpath, NULL);
+}
+
+
+void
+__libdw_set_debugdir (Dwarf *dbg)
+{
+ if (dbg->elfpath == NULL || dbg->elfpath[0] != '/')
+ return;
+ size_t dirlen = strrchr (dbg->elfpath, '/') - dbg->elfpath + 1;
+ dbg->debugdir = malloc (dirlen + 1);
+ if (dbg->debugdir == NULL)
+ return;
+ memcpy (dbg->debugdir, dbg->elfpath, dirlen);
+ dbg->debugdir[dirlen] = '\0';
}
}
if (result != NULL)
- result->debugdir = __libdw_debugdir (result->elf->fildes);
+ {
+ result->elfpath = __libdw_elfpath (result->elf->fildes);
+ __libdw_set_debugdir(result);
+ }
return result;
}
close (dwarf->alt_fd);
}
- /* The cached dir we found the Dwarf ELF file in. */
+ /* The cached path and dir we found the Dwarf ELF file in. */
+ free (dwarf->elfpath);
free (dwarf->debugdir);
/* Free the context descriptor. */
/* The underlying ELF file. */
Elf *elf;
+ /* The (absolute) path to the ELF file, if known. To help locating
+ dwp files. */
+ char *elfpath;
+
/* The (absolute) path to the ELF dir, if known. To help locating
alt and dwo files. */
char *debugdir;
int __libdw_addrx (Dwarf_CU *cu, Dwarf_Word idx, Dwarf_Addr *addr);
-/* Helper function to set debugdir field in Dwarf, used from dwarf_begin_elf
+/* Helper function to set elfpath field in Dwarf, used from dwarf_begin_elf
and libdwfl process_file. */
-char * __libdw_debugdir (int fd);
+char * __libdw_elfpath (int fd);
+
+/* Helper function to set debugdir field in Dwarf after elfpath field has been
+ set. */
+void __libdw_set_debugdir (Dwarf *dbg);
/* Given the directory of a debug file, an absolute or relative dir
+2023-09-27 Omar Sandoval <osandov@fb.com>
+ * dwfl_module.c (__libdwfl_module_free): Free mod->elfpath instead of
+ mod->elfdir.
+ * dwfl_module_getdwarf.c (load_dw): Set mod->dw->elfpath and call
+ __libdw_set_debugdir instead of setting mod->dw->debugdir.
+ * libdwflP.h (Dwfl_Module): Replace elfdir with elfpath.
+ * offline.c (process_elf): Call __libdw_elfpath and set mod->elfpath
+ instead of mod->elfdir.
+
2023-04-24 John Gallagher <john@gllghr.com>
* gzip.c: Fix memory leak in unzip()
free (mod->reloc_info);
free (mod->name);
- free (mod->elfdir);
+ free (mod->elfpath);
free (mod);
}
}
/* We might have already closed the fd when we asked dwarf_begin_elf to
- create an Dwarf. Help out a little in case we need to find an alt or
- dwo file later. */
- if (mod->dw->debugdir == NULL && mod->elfdir != NULL
+ create an Dwarf. Help out a little in case we need to find an alt,
+ dwo, or dwp file later. */
+ if (mod->dw->elfpath == NULL && mod->elfpath != NULL
&& debugfile == &mod->main)
- mod->dw->debugdir = strdup (mod->elfdir);
+ {
+ mod->dw->elfpath = strdup (mod->elfpath);
+ __libdw_set_debugdir (mod->dw);
+ }
/* Until we have iterated through all CU's, we might do lazy lookups. */
mod->lazycu = 1;
Elf_Data *symxndxdata; /* Data in the extended section index table. */
Elf_Data *aux_symxndxdata; /* Data in the extended auxiliary table. */
- char *elfdir; /* The dir where we found the main Elf. */
+ char *elfpath; /* The path where we found the main Elf. */
Dwarf *dw; /* libdw handle for its debugging info. */
Dwarf *alt; /* Dwarf used for dwarf_setalt, or NULL. */
/* Don't keep the file descriptor around. */
if (mod->main.fd != -1 && elf_cntl (mod->main.elf, ELF_C_FDREAD) == 0)
{
- /* Grab the dir path in case we want to report this file as
+ /* Grab the path in case we want to report this file as
Dwarf later. */
- mod->elfdir = __libdw_debugdir (mod->main.fd);
+ mod->elfpath = __libdw_elfpath (mod->main.fd);
close (mod->main.fd);
mod->main.fd = -1;
}