diff options
Diffstat (limited to 'libubacktrace')
-rw-r--r-- | libubacktrace/Makefile.in | 25 | ||||
-rw-r--r-- | libubacktrace/backtrace.c | 75 | ||||
-rw-r--r-- | libubacktrace/sysdeps/sh/Makefile.arch | 12 | ||||
-rw-r--r-- | libubacktrace/sysdeps/sh/backtrace.c | 84 |
4 files changed, 78 insertions, 118 deletions
diff --git a/libubacktrace/Makefile.in b/libubacktrace/Makefile.in index c1dd5d7ab..f75f68b75 100644 --- a/libubacktrace/Makefile.in +++ b/libubacktrace/Makefile.in @@ -12,35 +12,26 @@ CFLAGS-libubacktrace := -DNOT_IN_libc -DIS_IN_libubacktrace $(SSP_ALL_CFLAGS) LDFLAGS-libubacktrace.so := $(LDFLAGS) $(top_builddir)lib/libdl-$(VERSION).so +ifeq ($(CONFIG_ARM_EABI),y) +LIBGCC += $(shell $(CC) -print-file-name=libgcc_eh.a) +endif + LIBS-libubacktrace.so := $(LIBS) libubacktrace_FULL_NAME := libubacktrace-$(VERSION).so libubacktrace_DIR := $(top_srcdir)libubacktrace libubacktrace_OUT := $(top_builddir)libubacktrace -libubacktrace_ARCH_DIR := $(libubacktrace_DIR)/sysdeps/$(TARGET_ARCH) -libubacktrace_ARCH_OUT := $(libubacktrace_OUT)/sysdeps/$(TARGET_ARCH) - --include $(libubacktrace_ARCH_DIR)/Makefile.arch libubacktrace_SRC-y := libubacktrace_SRC-$(UCLIBC_HAS_BACKTRACE) := backtrace.c backtracesyms.c backtracesymsfd.c -CFLAGS-libubacktrace/sysdeps/$(TARGET_ARCH)/ := $(CFLAGS-libubacktrace) - -# remove generic sources, if arch specific version is present -ifneq ($(strip $(libubacktrace_ARCH_SRC-y)),) -libubacktrace_SRC-y := $(filter-out $(notdir $(libubacktrace_ARCH_SRC-y)),$(libubacktrace_SRC-y)) -libubacktrace_ARCH_SRC := $(addprefix $(libubacktrace_ARCH_DIR)/,$(libubacktrace_ARCH_SRC-y)) -libubacktrace_ARCH_OBJ := $(patsubst $(libubacktrace_ARCH_DIR)/%.c,$(libubacktrace_ARCH_OUT)/%.o,$(libubacktrace_ARCH_SRC)) -endif - +# -fexections is required for backtrace to work using dwarf2 +CFLAGS-backtrace.c := -fexceptions -libubacktrace_SRC := $(addprefix $(libubacktrace_DIR)/,$(libubacktrace_SRC-y)) -libubacktrace_OBJ := $(patsubst $(libubacktrace_DIR)/%.c,$(libubacktrace_OUT)/%.o,$(libubacktrace_SRC)) -libubacktrace_SRCS := $(libubacktrace_SRC) $(libubacktrace_ARCH_SRC) -libubacktrace_OBJS := $(libubacktrace_OBJ) $(libubacktrace_ARCH_OBJ) +libubacktrace_SRCS := $(addprefix $(libubacktrace_DIR)/,$(libubacktrace_SRC-y)) +libubacktrace_OBJS := $(patsubst $(libubacktrace_DIR)/%.c,$(libubacktrace_OUT)/%.o,$(libubacktrace_SRCS)) ifeq ($(DOPIC),y) libubacktrace-a-y := $(libubacktrace_OBJS:.o=.os) diff --git a/libubacktrace/backtrace.c b/libubacktrace/backtrace.c index 872180028..18b91b1bb 100644 --- a/libubacktrace/backtrace.c +++ b/libubacktrace/backtrace.c @@ -4,16 +4,81 @@ * User application that wants to use backtrace needs to be * compiled with -fexceptions option and -rdynamic to get full * symbols printed. - - * Copyright (C) 2010 STMicroelectronics Ltd + * + * Copyright (C) 2009, 2010 STMicroelectronics Ltd. + * + * Author(s): Giuseppe Cavallaro <peppe.cavallaro@st.com> + * - Initial implementation for glibc + * * Author(s): Carmelo Amoroso <carmelo.amoroso@st.com> + * - Reworked for uClibc + * - use dlsym/dlopen from libdl + * - rewrite initialisation to not use libc_once + * - make it available in static link too * * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball. * */ -#error "Arch specific implementation must be provided to properly work" -int backtrace (void **array, int size) + +#include <execinfo.h> +#include <dlfcn.h> +#include <stdlib.h> +#include <unwind.h> +#include <assert.h> +#include <stdio.h> + +struct trace_arg { - return -1; + void **array; + int cnt, size; +}; + +static _Unwind_Reason_Code (*unwind_backtrace) (_Unwind_Trace_Fn, void *); +static _Unwind_Ptr (*unwind_getip) (struct _Unwind_Context *); + +static void backtrace_init (void) +{ + void *handle = dlopen ("libgcc_s.so.1", RTLD_LAZY); + + if (handle == NULL + || ((unwind_backtrace = dlsym (handle, "_Unwind_Backtrace")) == NULL) + || ((unwind_getip = dlsym (handle, "_Unwind_GetIP")) == NULL)) { + printf("libgcc_s.so.1 must be installed for backtrace to work\n"); + abort(); + } } +static _Unwind_Reason_Code +backtrace_helper (struct _Unwind_Context *ctx, void *a) +{ + struct trace_arg *arg = a; + + assert (unwind_getip != NULL); + + /* We are first called with address in the __backtrace function. Skip it. */ + if (arg->cnt != -1) + arg->array[arg->cnt] = (void *) unwind_getip (ctx); + if (++arg->cnt == arg->size) + return _URC_END_OF_STACK; + return _URC_NO_REASON; +} + +/* + * Perform stack unwinding by using the _Unwind_Backtrace. + * + * User application that wants to use backtrace needs to be + * compiled with -fexceptions option and -rdynamic to get full + * symbols printed. + */ +int backtrace (void **array, int size) +{ + struct trace_arg arg = { .array = array, .size = size, .cnt = -1 }; + + if (unwind_backtrace == NULL) + backtrace_init(); + + if (size >= 1) + unwind_backtrace (backtrace_helper, &arg); + + return arg.cnt != -1 ? arg.cnt : 0; +} diff --git a/libubacktrace/sysdeps/sh/Makefile.arch b/libubacktrace/sysdeps/sh/Makefile.arch deleted file mode 100644 index 9b0de385b..000000000 --- a/libubacktrace/sysdeps/sh/Makefile.arch +++ /dev/null @@ -1,12 +0,0 @@ -# Makefile for uClibc (sh/libubacktrace) -# -# Copyright (C) 2010 STMicroelectronics Ltd -# Author: Carmelo Amoroso <carmelo.amoroso@st.com> - -# Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball. -# - -libubacktrace_ARCH_SRC-y := backtrace.c - -# -fexections is required for backtrace to work using dwarf2 -CFLAGS-backtrace.c := -fexceptions diff --git a/libubacktrace/sysdeps/sh/backtrace.c b/libubacktrace/sysdeps/sh/backtrace.c deleted file mode 100644 index 18b91b1bb..000000000 --- a/libubacktrace/sysdeps/sh/backtrace.c +++ /dev/null @@ -1,84 +0,0 @@ -/* - * Perform stack unwinding by using the _Unwind_Backtrace. - * - * User application that wants to use backtrace needs to be - * compiled with -fexceptions option and -rdynamic to get full - * symbols printed. - * - * Copyright (C) 2009, 2010 STMicroelectronics Ltd. - * - * Author(s): Giuseppe Cavallaro <peppe.cavallaro@st.com> - * - Initial implementation for glibc - * - * Author(s): Carmelo Amoroso <carmelo.amoroso@st.com> - * - Reworked for uClibc - * - use dlsym/dlopen from libdl - * - rewrite initialisation to not use libc_once - * - make it available in static link too - * - * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball. - * - */ - -#include <execinfo.h> -#include <dlfcn.h> -#include <stdlib.h> -#include <unwind.h> -#include <assert.h> -#include <stdio.h> - -struct trace_arg -{ - void **array; - int cnt, size; -}; - -static _Unwind_Reason_Code (*unwind_backtrace) (_Unwind_Trace_Fn, void *); -static _Unwind_Ptr (*unwind_getip) (struct _Unwind_Context *); - -static void backtrace_init (void) -{ - void *handle = dlopen ("libgcc_s.so.1", RTLD_LAZY); - - if (handle == NULL - || ((unwind_backtrace = dlsym (handle, "_Unwind_Backtrace")) == NULL) - || ((unwind_getip = dlsym (handle, "_Unwind_GetIP")) == NULL)) { - printf("libgcc_s.so.1 must be installed for backtrace to work\n"); - abort(); - } -} - -static _Unwind_Reason_Code -backtrace_helper (struct _Unwind_Context *ctx, void *a) -{ - struct trace_arg *arg = a; - - assert (unwind_getip != NULL); - - /* We are first called with address in the __backtrace function. Skip it. */ - if (arg->cnt != -1) - arg->array[arg->cnt] = (void *) unwind_getip (ctx); - if (++arg->cnt == arg->size) - return _URC_END_OF_STACK; - return _URC_NO_REASON; -} - -/* - * Perform stack unwinding by using the _Unwind_Backtrace. - * - * User application that wants to use backtrace needs to be - * compiled with -fexceptions option and -rdynamic to get full - * symbols printed. - */ -int backtrace (void **array, int size) -{ - struct trace_arg arg = { .array = array, .size = size, .cnt = -1 }; - - if (unwind_backtrace == NULL) - backtrace_init(); - - if (size >= 1) - unwind_backtrace (backtrace_helper, &arg); - - return arg.cnt != -1 ? arg.cnt : 0; -} |