diff options
author | Mark Wielaard <mjw@redhat.com> | 2014-01-07 21:00:44 +0100 |
---|---|---|
committer | Chanho Park <chanho61.park@samsung.com> | 2014-08-22 20:38:24 +0900 |
commit | 7f40999b3db608961a2ddf59b9c56b611a856611 (patch) | |
tree | b9f2d6815e8ea27e1af718450250a83f53379b47 /proc.c | |
parent | aa7a88a347fda1b709ed18745f832e15441125dd (diff) | |
download | ltrace-7f40999b3db608961a2ddf59b9c56b611a856611.tar.gz ltrace-7f40999b3db608961a2ddf59b9c56b611a856611.tar.bz2 ltrace-7f40999b3db608961a2ddf59b9c56b611a856611.zip |
Add support for using elfutils as unwinder.
This adds support for using elfutils as unwinder with -w. Since elfutils
0.158 elfutils contains a simple unwinder interface that matches nicely
on the ltrace backtrace support.
The code reuses the libunwind infrastructure already in ltrace where
possible (by defining HAVE_UNWINDER which is 1 if either libunwind or
elfutils is used). It also reuses the ltrace proc_add_library callback
to keep track of the ELF files mapped for the unwinder.
The current implementation matches the output as if libunwind was used.
But elfutils can also provide some more information since it can lookup
the DWARF debuginfo. So if the source info of an address can be found
through elfutils the backtrace will also include this as an additional
output line per frame.
Diffstat (limited to 'proc.c')
-rw-r--r-- | proc.c | 62 |
1 files changed, 62 insertions, 0 deletions
@@ -106,6 +106,11 @@ destroy_unwind(struct process *proc) if (proc->unwind_as != NULL) unw_destroy_addr_space(proc->unwind_as); #endif /* defined(HAVE_LIBUNWIND) */ + +#if defined(HAVE_LIBDW) + if (proc->dwfl != NULL) + dwfl_end(proc->dwfl); +#endif /* defined(HAVE_LIBDW) */ } static int @@ -167,6 +172,10 @@ process_bare_init(struct process *proc, const char *filename, } #endif /* defined(HAVE_LIBUNWIND) */ +#if defined(HAVE_LIBDW) + proc->dwfl = NULL; /* Initialize for leader only on first library. */ +#endif /* defined(HAVE_LIBDW) */ + return 0; } @@ -880,6 +889,59 @@ proc_add_library(struct process *proc, struct library *lib) debug(DEBUG_PROCESS, "added library %s@%p (%s) to %d", lib->soname, lib->base, lib->pathname, proc->pid); +#if defined(HAVE_LIBDW) + if (options.bt_depth > 0) { + /* Setup module tracking for libdwfl unwinding. */ + struct process *leader = proc->leader; + Dwfl *dwfl = leader->dwfl; + if (dwfl == NULL) { + static const Dwfl_Callbacks proc_callbacks = { + .find_elf = dwfl_linux_proc_find_elf, + .find_debuginfo = dwfl_standard_find_debuginfo + }; + dwfl = dwfl_begin(&proc_callbacks); + if (dwfl == NULL) + fprintf(stderr, + "Couldn't initialize libdwfl unwinding " + "for process %d: %s\n", leader->pid, + dwfl_errmsg (-1)); + } + + if (dwfl != NULL) { + dwfl_report_begin_add(dwfl); + if (dwfl_report_elf(dwfl, lib->soname, + lib->pathname, -1, + (GElf_Addr) lib->base, + false) == NULL) + fprintf(stderr, + "dwfl_report_elf %s@%p (%s) %d: %s\n", + lib->soname, lib->base, lib->pathname, + proc->pid, dwfl_errmsg (-1)); + dwfl_report_end(dwfl, NULL, NULL); + + if (leader->dwfl == NULL) { + int r = dwfl_linux_proc_attach(dwfl, + leader->pid, + true); + if (r == 0) + leader->dwfl = dwfl; + else { + const char *msg; + dwfl_end(dwfl); + if (r < 0) + msg = dwfl_errmsg(-1); + else + msg = strerror(r); + fprintf(stderr, "Couldn't initialize " + "libdwfl unwinding for " + "process %d: %s\n", + leader->pid, msg); + } + } + } + } +#endif /* defined(HAVE_LIBDW) */ + /* Insert breakpoints for all active (non-latent) symbols. */ struct library_symbol *libsym = NULL; while ((libsym = library_each_symbol(lib, libsym, |