2 * (c) 2008-2009 Technische Universität Dresden
3 * This file is part of TUD:OS and distributed under the terms of the
4 * GNU Lesser General Public License 2.1.
5 * Please see the COPYING-LGPL-2.1 file for details.
7 #include <l4/util/backtrace.h>
12 #if defined NOT_FOR_L4 && defined __PIC__
16 static _Unwind_Reason_Code (*uw_bt) (_Unwind_Trace_Fn, void *);
17 static _Unwind_Ptr (*uw_getpc) (struct _Unwind_Context *);
22 void *handle = dlopen ("libgcc_s.so.1", 0);
27 uw_bt = dlsym (handle, "_Unwind_Backtrace");
28 uw_getpc = dlsym (handle, "_Unwind_GetIP");
34 #define uw_getgr _Unwind_GetGR
35 #define uw_getpc _Unwind_GetIP
36 #define uw_bt _Unwind_Backtrace
37 #define uw_getcfa _Unwind_GetCFA
48 static _Unwind_Reason_Code
49 __bt_helper(struct _Unwind_Context *ctx, void *a)
51 struct Bt_arg *arg = a;
53 /* Skip first function, it is l4util_backtrace ... */
55 arg->pc_array[arg->cnt] = (void *)uw_getpc (ctx);
56 if (++arg->cnt == arg->max)
57 return _URC_END_OF_STACK;
59 return _URC_NO_REASON;
64 l4util_backtrace(void **pc_array, int max)
66 struct Bt_arg arg = { .pc_array = pc_array, .max = max, .cnt = -1 };
68 #if defined NOT_FOR_L4 && defined __PIC__
69 static int initialized = 0;
81 uw_bt (__bt_helper, &arg);
83 if (arg.cnt > 1 && arg.pc_array[arg.cnt - 1] == (void*)0)
85 return arg.cnt != -1 ? arg.cnt : 0;