* The libdwfl code in this file is based on code from elfutils
* (libdwfl/argp-std.c, libdwfl/tests/addrcfi.c, etc).
*/
-static char *debuginfo_path;
-
-static const Dwfl_Callbacks offline_callbacks = {
- .debuginfo_path = &debuginfo_path,
- .find_debuginfo = dwfl_standard_find_debuginfo,
- .section_address = dwfl_offline_section_address,
-};
-
/*
* Use the DWARF expression for the Call-frame-address and determine
* yet used)
* -1 in case of errors
*/
-static int check_return_addr(struct dso *dso, u64 map_start, Dwarf_Addr pc)
+static int check_return_addr(struct dso *dso, Dwarf_Addr mapped_pc)
{
int rc = -1;
Dwfl *dwfl;
Dwfl_Module *mod;
Dwarf_Frame *frame;
int ra_regno;
- Dwarf_Addr start = pc;
- Dwarf_Addr end = pc;
+ Dwarf_Addr start = mapped_pc;
+ Dwarf_Addr end = mapped_pc;
bool signalp;
- const char *exec_file = dso__long_name(dso);
-
- dwfl = RC_CHK_ACCESS(dso)->dwfl;
-
- if (!dwfl) {
- dwfl = dwfl_begin(&offline_callbacks);
- if (!dwfl) {
- pr_debug("dwfl_begin() failed: %s\n", dwarf_errmsg(-1));
- return -1;
- }
-
- mod = dwfl_report_elf(dwfl, exec_file, exec_file, -1,
- map_start, false);
- if (!mod) {
- pr_debug("dwfl_report_elf() failed %s\n",
- dwarf_errmsg(-1));
- /*
- * We normally cache the DWARF debug info and never
- * call dwfl_end(). But to prevent fd leak, free in
- * case of error.
- */
- dwfl_end(dwfl);
- goto out;
- }
- RC_CHK_ACCESS(dso)->dwfl = dwfl;
- }
- mod = dwfl_addrmodule(dwfl, pc);
+ dwfl = dso__libdw_dwfl(dso);
+ if (!dwfl)
+ return -1;
+
+ mod = dwfl_addrmodule(dwfl, mapped_pc);
if (!mod) {
pr_debug("dwfl_addrmodule() failed, %s\n", dwarf_errmsg(-1));
goto out;
* To work with split debug info files (eg: glibc), check both
* .eh_frame and .debug_frame sections of the ELF header.
*/
- frame = get_eh_frame(mod, pc);
+ frame = get_eh_frame(mod, mapped_pc);
if (!frame) {
- frame = get_dwarf_frame(mod, pc);
+ frame = get_dwarf_frame(mod, mapped_pc);
if (!frame)
goto out;
}
return skip_slot;
}
- rc = check_return_addr(dso, map__start(al.map), ip);
+ rc = check_return_addr(dso, map__map_ip(al.map, ip));
pr_debug("[DSO %s, sym %s, ip 0x%" PRIx64 "] rc %d\n",
dso__long_name(dso), al.sym->name, ip, rc);
auxtrace_cache__free(RC_CHK_ACCESS(dso)->auxtrace_cache);
dso_cache__free(dso);
dso__free_a2l(dso);
- dso__free_a2l_libdw(dso);
+ dso__free_libdw(dso);
dso__free_symsrc_filename(dso);
nsinfo__zput(RC_CHK_ACCESS(dso)->nsinfo);
mutex_destroy(dso__lock(dso));
const char *short_name;
const char *long_name;
void *a2l;
- void *a2l_libdw;
+ void *libdw;
char *symsrc_filename;
-#if defined(__powerpc__)
- void *dwfl; /* DWARF debug info */
-#endif
struct nsinfo *nsinfo;
struct auxtrace_cache *auxtrace_cache;
union { /* Tool specific area */
RC_CHK_ACCESS(dso)->a2l = val;
}
-static inline void *dso__a2l_libdw(const struct dso *dso)
+static inline void *dso__libdw(const struct dso *dso)
{
- return RC_CHK_ACCESS(dso)->a2l_libdw;
+ return RC_CHK_ACCESS(dso)->libdw;
}
-static inline void dso__set_a2l_libdw(struct dso *dso, void *val)
+static inline void dso__set_libdw(struct dso *dso, void *val)
{
- RC_CHK_ACCESS(dso)->a2l_libdw = val;
+ RC_CHK_ACCESS(dso)->libdw = val;
}
+struct Dwfl;
+#ifdef HAVE_LIBDW_SUPPORT
+struct Dwfl *dso__libdw_dwfl(struct dso *dso);
+#else
+static inline struct Dwfl *dso__libdw_dwfl(struct dso *dso __maybe_unused)
+{
+ return NULL;
+}
+#endif
+
static inline unsigned int dso__a2l_fails(const struct dso *dso)
{
return RC_CHK_ACCESS(dso)->a2l_fails;
#include <unistd.h>
#include <elfutils/libdwfl.h>
-void dso__free_a2l_libdw(struct dso *dso)
+static const Dwfl_Callbacks offline_callbacks = {
+ .find_debuginfo = dwfl_standard_find_debuginfo,
+ .section_address = dwfl_offline_section_address,
+ .find_elf = dwfl_build_id_find_elf,
+};
+
+void dso__free_libdw(struct dso *dso)
{
- Dwfl *dwfl = dso__a2l_libdw(dso);
+ Dwfl *dwfl = dso__libdw(dso);
if (dwfl) {
dwfl_end(dwfl);
- dso__set_a2l_libdw(dso, NULL);
+ dso__set_libdw(dso, NULL);
+ }
+}
+
+struct Dwfl *dso__libdw_dwfl(struct dso *dso)
+{
+ Dwfl *dwfl = dso__libdw(dso);
+ const char *dso_name;
+ Dwfl_Module *mod;
+ int fd;
+
+ if (dwfl)
+ return dwfl;
+
+ dso_name = dso__long_name(dso);
+ /*
+ * Initialize Dwfl session.
+ * We need to open the DSO file to report it to libdw.
+ */
+ fd = open(dso_name, O_RDONLY);
+ if (fd < 0)
+ return NULL;
+
+ dwfl = dwfl_begin(&offline_callbacks);
+ if (!dwfl) {
+ close(fd);
+ return NULL;
+ }
+
+ /*
+ * If the report is successful, the file descriptor fd is consumed
+ * and closed by the Dwfl. If not, it is not closed.
+ */
+ mod = dwfl_report_offline(dwfl, dso_name, dso_name, fd);
+ if (!mod) {
+ dwfl_end(dwfl);
+ close(fd);
+ return NULL;
}
+
+ dwfl_report_end(dwfl, /*removed=*/NULL, /*arg=*/NULL);
+ dso__set_libdw(dso, dwfl);
+
+ return dwfl;
}
struct libdw_a2l_cb_args {
return 0;
}
-int libdw__addr2line(const char *dso_name, u64 addr,
- char **file, unsigned int *line_nr,
+int libdw__addr2line(u64 addr, char **file, unsigned int *line_nr,
struct dso *dso, bool unwind_inlines,
struct inline_node *node, struct symbol *sym)
{
- static const Dwfl_Callbacks offline_callbacks = {
- .find_debuginfo = dwfl_standard_find_debuginfo,
- .section_address = dwfl_offline_section_address,
- .find_elf = dwfl_build_id_find_elf,
- };
- Dwfl *dwfl = dso__a2l_libdw(dso);
+ Dwfl *dwfl = dso__libdw_dwfl(dso);
Dwfl_Module *mod;
Dwfl_Line *dwline;
Dwarf_Addr bias;
const char *src;
int lineno = 0;
- if (!dwfl) {
- /*
- * Initialize Dwfl session.
- * We need to open the DSO file to report it to libdw.
- */
- int fd;
-
- fd = open(dso_name, O_RDONLY);
- if (fd < 0)
- return 0;
-
- dwfl = dwfl_begin(&offline_callbacks);
- if (!dwfl) {
- close(fd);
- return 0;
- }
-
- /*
- * If the report is successful, the file descriptor fd is consumed
- * and closed by the Dwfl. If not, it is not closed.
- */
- mod = dwfl_report_offline(dwfl, dso_name, dso_name, fd);
- if (!mod) {
- dwfl_end(dwfl);
- close(fd);
- return 0;
- }
-
- dwfl_report_end(dwfl, /*removed=*/NULL, /*arg=*/NULL);
- dso__set_a2l_libdw(dso, dwfl);
- } else {
- /* Dwfl session already initialized, get module for address. */
- mod = dwfl_addrmodule(dwfl, addr);
- }
+ if (!dwfl)
+ return 0;
+ mod = dwfl_addrmodule(dwfl, addr);
if (!mod)
return 0;
#ifdef HAVE_LIBDW_SUPPORT
/*
* libdw__addr2line - Convert address to source location using libdw
- * @dso_name: Name of the DSO
* @addr: Address to resolve
* @file: Pointer to return filename (caller must free)
* @line_nr: Pointer to return line number
*
* Returns 1 on success (found), 0 on failure (not found).
*/
-int libdw__addr2line(const char *dso_name, u64 addr, char **file,
+int libdw__addr2line(u64 addr, char **file,
unsigned int *line_nr, struct dso *dso,
bool unwind_inlines, struct inline_node *node,
struct symbol *sym);
/*
- * dso__free_a2l_libdw - Free libdw resources associated with the DSO
+ * dso__free_libdw - Free libdw resources associated with the DSO
* @dso: The dso to free resources for
*
* This function cleans up the Dwfl context used for addr2line lookups.
*/
-void dso__free_a2l_libdw(struct dso *dso);
+void dso__free_libdw(struct dso *dso);
#else /* HAVE_LIBDW_SUPPORT */
-static inline int libdw__addr2line(const char *dso_name __maybe_unused,
- u64 addr __maybe_unused, char **file __maybe_unused,
+static inline int libdw__addr2line(u64 addr __maybe_unused, char **file __maybe_unused,
unsigned int *line_nr __maybe_unused,
struct dso *dso __maybe_unused,
bool unwind_inlines __maybe_unused,
return 0;
}
-static inline void dso__free_a2l_libdw(struct dso *dso __maybe_unused)
+static inline void dso__free_libdw(struct dso *dso __maybe_unused)
{
}
#endif /* HAVE_LIBDW_SUPPORT */
for (size_t i = 0; i < ARRAY_SIZE(symbol_conf.addr2line_style); i++) {
switch (symbol_conf.addr2line_style[i]) {
case A2L_STYLE_LIBDW:
- ret = libdw__addr2line(dso_name, addr, file, line_nr, dso, unwind_inlines,
+ ret = libdw__addr2line(addr, file, line_nr, dso, unwind_inlines,
node, sym);
break;
case A2L_STYLE_LLVM: