From b3d73f1addf0078aed4ecc551dabe767c820f458 Mon Sep 17 00:00:00 2001 From: Adrian Szyndela Date: Thu, 24 Mar 2016 12:56:12 +0100 Subject: [PATCH] Added generic unwinding with libelf It is meant to work at least in some basic way on x86, x86_64 and aarch64. Change-Id: If6c5ebe7a1dc69a2d27188bbc6c9e1a87037ce98 --- src/crash-stack/crash-stack-libelf.c | 18 ++++++++++++++++++ src/crash-stack/crash-stack.c | 2 +- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/crash-stack/crash-stack-libelf.c b/src/crash-stack/crash-stack-libelf.c index f09b572..3bde52f 100644 --- a/src/crash-stack/crash-stack-libelf.c +++ b/src/crash-stack/crash-stack-libelf.c @@ -1,4 +1,20 @@ #include "crash-stack.h" +#include + +static int frame_callback (Dwfl_Frame *state, void *arg) +{ + Callstack *callstack = (Callstack*)arg; + Dwarf_Addr address; + dwfl_frame_pc (state, &address, NULL); + callstack->tab[callstack->elems++] = address; + return callstack->elems < MAX_CALLSTACK_LEN ? DWARF_CB_OK : DWARF_CB_ABORT; +} + +static int thread_callback (Dwfl_Thread *thread, void *thread_arg) +{ + dwfl_thread_getframes (thread, frame_callback, thread_arg); + return DWARF_CB_ABORT; +} Regs *get_regs_struct (void) { @@ -12,5 +28,7 @@ void *get_place_for_register_value (const char *regname, int regnum) void create_crash_stack (Regs *regs, Dwfl *dwfl, Elf *core, Callstack *callstack) { + callstack->elems = 0; + dwfl_getthreads (dwfl, thread_callback, callstack); } diff --git a/src/crash-stack/crash-stack.c b/src/crash-stack/crash-stack.c index 69a1e0d..8f535ea 100644 --- a/src/crash-stack/crash-stack.c +++ b/src/crash-stack/crash-stack.c @@ -236,7 +236,7 @@ int main(int argc, char **argv) for (it = 0; it != callstack.elems; ++it) { if (sizeof (callstack.tab[0]) > 4) - printf ("0x%016llx: ", (int64_t)callstack.tab[it]); + printf ("0x%016llx: ", (long long)callstack.tab[it]); else printf ("0x%08x: ", (int32_t)callstack.tab[it]); Dwfl_Module *module = dwfl_addrmodule (dwfl, callstack.tab[it]); -- 2.7.4