Added generic unwinding with libelf 47/63547/2
authorAdrian Szyndela <adrian.s@samsung.com>
Thu, 24 Mar 2016 11:56:12 +0000 (12:56 +0100)
committerKarol Lewandowski <k.lewandowsk@samsung.com>
Tue, 12 Apr 2016 16:05:04 +0000 (18:05 +0200)
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
src/crash-stack/crash-stack.c

index f09b572..3bde52f 100644 (file)
@@ -1,4 +1,20 @@
 #include "crash-stack.h"
+#include <elfutils/libdwfl.h>
+
+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);
 }
 
index 69a1e0d..8f535ea 100644 (file)
@@ -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]);