summaryrefslogtreecommitdiffstats
path: root/libbacktrace
diff options
context:
space:
mode:
Diffstat (limited to 'libbacktrace')
-rw-r--r--libbacktrace/Android.build.mk73
-rwxr-xr-x[-rw-r--r--]libbacktrace/Android.mk325
-rw-r--r--libbacktrace/BacktraceImpl.cpp19
-rwxr-xr-x[-rw-r--r--]libbacktrace/BacktraceImpl.h4
-rwxr-xr-x[-rw-r--r--]libbacktrace/UnwindCurrent.cpp24
-rw-r--r--libbacktrace/UnwindMap.cpp6
6 files changed, 192 insertions, 259 deletions
diff --git a/libbacktrace/Android.build.mk b/libbacktrace/Android.build.mk
new file mode 100644
index 0000000..3c80cc2
--- /dev/null
+++ b/libbacktrace/Android.build.mk
@@ -0,0 +1,73 @@
+#
+# Copyright (C) 2014 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+include $(CLEAR_VARS)
+
+LOCAL_MODULE := $(module)
+LOCAL_MODULE_TAGS := $(module_tag)
+
+LOCAL_ADDITIONAL_DEPENDENCIES := \
+ $(LOCAL_PATH)/Android.mk \
+ $(LOCAL_PATH)/Android.build.mk \
+
+LOCAL_CFLAGS := \
+ $(common_cflags) \
+ $($(module)_cflags) \
+ $($(module)_cflags_$(build_type)) \
+
+LOCAL_CONLYFLAGS += \
+ $(common_conlyflags) \
+ $($(module)_conlyflags) \
+ $($(module)_conlyflags_$(build_type)) \
+
+LOCAL_CPPFLAGS += \
+ $(common_cppflags) \
+ $($(module)_cppflags) \
+ $($(module)_cppflags_$(build_type)) \
+
+LOCAL_C_INCLUDES := \
+ $(common_c_includes) \
+ $($(module)_c_includes) \
+ $($(module)_c_includes_$(build_type)) \
+
+LOCAL_SRC_FILES := \
+ $($(module)_src_files) \
+ $($(module)_src_files_$(build_type)) \
+
+LOCAL_STATIC_LIBRARIES := \
+ $($(module)_static_libraries) \
+ $($(module)_static_libraries_$(build_type)) \
+
+LOCAL_SHARED_LIBRARIES := \
+ $($(module)_shared_libraries) \
+ $($(module)_shared_libraries_$(build_type)) \
+
+LOCAL_LDLIBS := \
+ $($(module)_ldlibs) \
+ $($(module)_ldlibs_$(build_type)) \
+
+ifeq ($(build_type),target)
+ include external/stlport/libstlport.mk
+
+ include $(BUILD_$(build_target))
+endif
+
+ifeq ($(build_type),host)
+ # Only build if host builds are supported.
+ ifeq ($(build_host),true)
+ include $(BUILD_HOST_$(build_target))
+ endif
+endif
diff --git a/libbacktrace/Android.mk b/libbacktrace/Android.mk
index 0ae8839..33af0a3 100644..100755
--- a/libbacktrace/Android.mk
+++ b/libbacktrace/Android.mk
@@ -1,14 +1,23 @@
-LOCAL_PATH:= $(call my-dir)
+#
+# Copyright (C) 2014 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
-common_src := \
- BacktraceImpl.cpp \
- BacktraceMap.cpp \
- BacktraceThread.cpp \
- thread_utils.c \
+LOCAL_PATH:= $(call my-dir)
common_cflags := \
-Wall \
- -Wno-unused-parameter \
-Werror \
common_conlyflags := \
@@ -17,274 +26,148 @@ common_conlyflags := \
common_cppflags := \
-std=gnu++11 \
-common_shared_libs := \
+build_host := false
+ifeq ($(HOST_OS),linux)
+ifeq ($(HOST_ARCH),$(filter $(HOST_ARCH),x86 x86_64))
+build_host := true
+endif
+endif
+
+#-------------------------------------------------------------------------
+# The libbacktrace library.
+#-------------------------------------------------------------------------
+libbacktrace_src_files := \
+ BacktraceImpl.cpp \
+ BacktraceMap.cpp \
+ BacktraceThread.cpp \
+ thread_utils.c \
+
+libbacktrace_shared_libraries_target := \
libcutils \
libgccdemangle \
- liblog \
# To enable using libunwind on each arch, add it to this list.
-libunwind_architectures := arm arm64
+libunwind_architectures := arm arm64 x86 x86_64
ifeq ($(TARGET_ARCH),$(filter $(TARGET_ARCH),$(libunwind_architectures)))
-
-#----------------------------------------------------------------------------
-# The native libbacktrace library with libunwind.
-#----------------------------------------------------------------------------
-include $(CLEAR_VARS)
-
-LOCAL_SRC_FILES:= \
- $(common_src) \
+libbacktrace_src_files += \
UnwindCurrent.cpp \
UnwindMap.cpp \
UnwindPtrace.cpp \
-LOCAL_CFLAGS := \
- $(common_cflags) \
-
-LOCAL_CONLYFLAGS += \
- $(common_conlyflags) \
-
-LOCAL_CPPFLAGS += \
- $(common_cppflags) \
-
-LOCAL_MODULE := libbacktrace
-LOCAL_MODULE_TAGS := optional
-
-LOCAL_C_INCLUDES := \
- $(common_c_includes) \
+libbacktrace_c_includes := \
external/libunwind/include \
-LOCAL_SHARED_LIBRARIES := \
- $(common_shared_libs) \
+libbacktrace_shared_libraries := \
libunwind \
libunwind-ptrace \
-LOCAL_ADDITIONAL_DEPENDENCIES := \
- $(LOCAL_PATH)/Android.mk
-
-include external/stlport/libstlport.mk
+libbacktrace_shared_libraries_host := \
+ liblog \
-include $(BUILD_SHARED_LIBRARY)
+libbacktrace_static_libraries_host := \
+ libcutils \
else
-
-#----------------------------------------------------------------------------
-# The native libbacktrace library with libcorkscrew.
-#----------------------------------------------------------------------------
-include $(CLEAR_VARS)
-
-LOCAL_SRC_FILES:= \
- $(common_src) \
+libbacktrace_src_files += \
Corkscrew.cpp \
-LOCAL_CFLAGS := \
- $(common_cflags) \
-
-LOCAL_CONLYFLAGS += \
- $(common_conlyflags) \
-
-LOCAL_CPPFLAGS += \
- $(common_cppflags) \
-
-LOCAL_MODULE := libbacktrace
-LOCAL_MODULE_TAGS := optional
-
-LOCAL_C_INCLUDES := \
- $(common_c_includes) \
+libbacktrace_c_includes := \
system/core/libcorkscrew \
-LOCAL_SHARED_LIBRARIES := \
- $(common_shared_libs) \
+libbacktrace_shared_libraries := \
libcorkscrew \
- libdl \
-
-LOCAL_ADDITIONAL_DEPENDENCIES := \
- $(LOCAL_PATH)/Android.mk
-include external/stlport/libstlport.mk
+libbacktrace_shared_libraries_target += \
+ libdl \
-include $(BUILD_SHARED_LIBRARY)
+libbacktrace_ldlibs_host := \
+ -ldl \
endif
-#----------------------------------------------------------------------------
-# libbacktrace test library, all optimizations turned off
-#----------------------------------------------------------------------------
-include $(CLEAR_VARS)
-
-LOCAL_MODULE := libbacktrace_test
-LOCAL_MODULE_FLAGS := debug
-
-LOCAL_SRC_FILES := \
- backtrace_testlib.c
-
-LOCAL_CFLAGS += \
- -std=gnu99 \
+module := libbacktrace
+module_tag := optional
+build_type := target
+build_target := SHARED_LIBRARY
+include $(LOCAL_PATH)/Android.build.mk
+build_type := host
+include $(LOCAL_PATH)/Android.build.mk
+
+#-------------------------------------------------------------------------
+# The libbacktrace_test library needed by backtrace_test.
+#-------------------------------------------------------------------------
+libbacktrace_test_cflags := \
-O0 \
-LOCAL_ADDITIONAL_DEPENDENCIES := \
- $(LOCAL_PATH)/Android.mk
-
-include $(BUILD_SHARED_LIBRARY)
-
-#----------------------------------------------------------------------------
-# libbacktrace test executable
-#----------------------------------------------------------------------------
-include $(CLEAR_VARS)
-
-LOCAL_MODULE := backtrace_test
-LOCAL_MODULE_FLAGS := debug
-
-LOCAL_SRC_FILES := \
- backtrace_test.cpp \
- thread_utils.c \
-
-LOCAL_CFLAGS += \
- $(common_cflags) \
+libbacktrace_test_src_files := \
+ backtrace_testlib.c \
+
+module := libbacktrace_test
+module_tag := debug
+build_type := target
+build_target := SHARED_LIBRARY
+include $(LOCAL_PATH)/Android.build.mk
+build_type := host
+include $(LOCAL_PATH)/Android.build.mk
+
+#-------------------------------------------------------------------------
+# The backtrace_test executable.
+#-------------------------------------------------------------------------
+backtrace_test_cflags := \
-fno-builtin \
- -fstack-protector-all \
-O0 \
-g \
- -DGTEST_OS_LINUX_ANDROID \
-DGTEST_HAS_STD_STRING \
-ifeq ($(TARGET_ARCH),arm64)
+ifneq ($(TARGET_ARCH),arm64)
+backtrace_test_cflags += -fstack-protector-all
+else
$(info TODO: $(LOCAL_PATH)/Android.mk -fstack-protector not yet available for the AArch64 toolchain)
- LOCAL_CFLAGS += -fno-stack-protector
+ common_cflags += -fno-stack-protector
endif # arm64
-LOCAL_CONLYFLAGS += \
- $(common_conlyflags) \
-
-LOCAL_CPPFLAGS += \
- $(common_cppflags) \
+backtrace_test_cflags_target := \
+ -DGTEST_OS_LINUX_ANDROID \
-LOCAL_SHARED_LIBRARIES += \
- libcutils \
- libbacktrace_test \
- libbacktrace \
+backtrace_test_src_files := \
+ backtrace_test.cpp \
+ thread_utils.c \
-LOCAL_LDLIBS := \
+backtrace_test_ldlibs := \
-lpthread \
-LOCAL_ADDITIONAL_DEPENDENCIES := \
- $(LOCAL_PATH)/Android.mk
-
-include $(BUILD_NATIVE_TEST)
-
-#----------------------------------------------------------------------------
-# Only x86 host versions of libbacktrace supported.
-#----------------------------------------------------------------------------
-ifeq ($(HOST_ARCH),x86)
-
-#----------------------------------------------------------------------------
-# The host libbacktrace library using libcorkscrew
-#----------------------------------------------------------------------------
-include $(CLEAR_VARS)
-
-
-LOCAL_CFLAGS += \
- $(common_cflags) \
-
-LOCAL_CONLYFLAGS += \
- $(common_conlyflags) \
-
-LOCAL_C_INCLUDES := \
- $(common_c_includes) \
-
-LOCAL_SHARED_LIBRARIES := \
- libgccdemangle \
- liblog \
-
-LOCAL_MODULE := libbacktrace
-LOCAL_MODULE_TAGS := optional
-
-LOCAL_ADDITIONAL_DEPENDENCIES := \
- $(LOCAL_PATH)/Android.mk
-
-ifeq ($(HOST_OS),linux)
-LOCAL_SRC_FILES += \
- $(common_src) \
- Corkscrew.cpp \
-
-LOCAL_C_INCLUDES += \
- system/core/libcorkscrew \
-
-LOCAL_SHARED_LIBRARIES := \
- libcorkscrew \
-
-LOCAL_CPPFLAGS += \
- $(common_cppflags) \
-
-LOCAL_LDLIBS += \
- -ldl \
+backtrace_test_ldlibs_host := \
-lrt \
-else
-LOCAL_SRC_FILES += \
- BacktraceMap.cpp \
+backtrace_test_shared_libraries := \
+ libbacktrace_test \
+ libbacktrace \
-endif
+backtrace_test_shared_libraries_target := \
+ libcutils \
-include $(BUILD_HOST_SHARED_LIBRARY)
+module := backtrace_test
+module_tag := debug
+build_type := target
+build_target := NATIVE_TEST
+include $(LOCAL_PATH)/Android.build.mk
+build_type := host
+include $(LOCAL_PATH)/Android.build.mk
#----------------------------------------------------------------------------
-# The host test is only supported on linux.
+# Special truncated libbacktrace library for mac.
#----------------------------------------------------------------------------
-ifeq ($(HOST_OS),linux)
+ifeq ($(HOST_OS),darwin)
-#----------------------------------------------------------------------------
-# libbacktrace host test library, all optimizations turned off
-#----------------------------------------------------------------------------
include $(CLEAR_VARS)
-LOCAL_MODULE := libbacktrace_test
-LOCAL_MODULE_FLAGS := debug
+LOCAL_MODULE := libbacktrace
+LOCAL_MODULE_TAGS := optional
LOCAL_SRC_FILES := \
- backtrace_testlib.c
-
-LOCAL_CFLAGS += \
- -std=gnu99 \
- -O0 \
-
-LOCAL_ADDITIONAL_DEPENDENCIES := \
- $(LOCAL_PATH)/Android.mk
+ BacktraceMap.cpp \
include $(BUILD_HOST_SHARED_LIBRARY)
-#----------------------------------------------------------------------------
-# libbacktrace host test executable
-#----------------------------------------------------------------------------
-include $(CLEAR_VARS)
-
-LOCAL_MODULE := backtrace_test
-LOCAL_MODULE_FLAGS := debug
-
-LOCAL_SRC_FILES := \
- backtrace_test.cpp \
- thread_utils.c \
-
-LOCAL_CFLAGS += \
- $(common_cflags) \
- -fno-builtin \
- -fstack-protector-all \
- -O0 \
- -g \
- -DGTEST_HAS_STD_STRING \
-
-LOCAL_SHARED_LIBRARIES := \
- libbacktrace_test \
- libbacktrace \
-
-LOCAL_LDLIBS := \
- -lpthread \
-
-LOCAL_ADDITIONAL_DEPENDENCIES := \
- $(LOCAL_PATH)/Android.mk
-
-include $(BUILD_HOST_NATIVE_TEST)
-
-endif # HOST_OS == linux
-
-endif # HOST_ARCH == x86
+endif # HOST_OS-darwin
diff --git a/libbacktrace/BacktraceImpl.cpp b/libbacktrace/BacktraceImpl.cpp
index 39296b4..855810e 100644
--- a/libbacktrace/BacktraceImpl.cpp
+++ b/libbacktrace/BacktraceImpl.cpp
@@ -21,9 +21,6 @@
#include <sys/types.h>
#include <unistd.h>
-#define __STDC_FORMAT_MACROS
-#include <inttypes.h>
-
#include <string>
#include <backtrace/Backtrace.h>
@@ -82,10 +79,10 @@ std::string Backtrace::GetFunctionName(uintptr_t pc, uintptr_t* offset) {
return func_name;
}
-bool Backtrace::VerifyReadWordArgs(uintptr_t ptr, uint32_t* out_value) {
- if (ptr & 3) {
+bool Backtrace::VerifyReadWordArgs(uintptr_t ptr, word_t* out_value) {
+ if (ptr & (sizeof(word_t)-1)) {
BACK_LOGW("invalid pointer %p", (void*)ptr);
- *out_value = (uint32_t)-1;
+ *out_value = (word_t)-1;
return false;
}
return true;
@@ -143,18 +140,18 @@ BacktraceCurrent::BacktraceCurrent(
BacktraceCurrent::~BacktraceCurrent() {
}
-bool BacktraceCurrent::ReadWord(uintptr_t ptr, uint32_t* out_value) {
+bool BacktraceCurrent::ReadWord(uintptr_t ptr, word_t* out_value) {
if (!VerifyReadWordArgs(ptr, out_value)) {
return false;
}
const backtrace_map_t* map = FindMap(ptr);
if (map && map->flags & PROT_READ) {
- *out_value = *reinterpret_cast<uint32_t*>(ptr);
+ *out_value = *reinterpret_cast<word_t*>(ptr);
return true;
} else {
BACK_LOGW("pointer %p not in a readable map", reinterpret_cast<void*>(ptr));
- *out_value = static_cast<uint32_t>(-1);
+ *out_value = static_cast<word_t>(-1);
return false;
}
}
@@ -171,7 +168,7 @@ BacktracePtrace::BacktracePtrace(
BacktracePtrace::~BacktracePtrace() {
}
-bool BacktracePtrace::ReadWord(uintptr_t ptr, uint32_t* out_value) {
+bool BacktracePtrace::ReadWord(uintptr_t ptr, word_t* out_value) {
if (!VerifyReadWordArgs(ptr, out_value)) {
return false;
}
@@ -184,7 +181,7 @@ bool BacktracePtrace::ReadWord(uintptr_t ptr, uint32_t* out_value) {
// To disambiguate -1 from a valid result, we clear errno beforehand.
errno = 0;
*out_value = ptrace(PTRACE_PEEKTEXT, Tid(), reinterpret_cast<void*>(ptr), NULL);
- if (*out_value == static_cast<uint32_t>(-1) && errno) {
+ if (*out_value == static_cast<word_t>(-1) && errno) {
BACK_LOGW("invalid pointer %p reading from tid %d, ptrace() strerror(errno)=%s",
reinterpret_cast<void*>(ptr), Tid(), strerror(errno));
return false;
diff --git a/libbacktrace/BacktraceImpl.h b/libbacktrace/BacktraceImpl.h
index af014d5..48dd11c 100644..100755
--- a/libbacktrace/BacktraceImpl.h
+++ b/libbacktrace/BacktraceImpl.h
@@ -61,7 +61,7 @@ public:
BacktraceCurrent(BacktraceImpl* impl, BacktraceMap* map);
virtual ~BacktraceCurrent();
- bool ReadWord(uintptr_t ptr, uint32_t* out_value);
+ bool ReadWord(uintptr_t ptr, word_t* out_value);
};
class BacktracePtrace : public Backtrace {
@@ -69,7 +69,7 @@ public:
BacktracePtrace(BacktraceImpl* impl, pid_t pid, pid_t tid, BacktraceMap* map);
virtual ~BacktracePtrace();
- bool ReadWord(uintptr_t ptr, uint32_t* out_value);
+ bool ReadWord(uintptr_t ptr, word_t* out_value);
};
Backtrace* CreateCurrentObj(BacktraceMap* map);
diff --git a/libbacktrace/UnwindCurrent.cpp b/libbacktrace/UnwindCurrent.cpp
index 17b71b9..81e69bb 100644..100755
--- a/libbacktrace/UnwindCurrent.cpp
+++ b/libbacktrace/UnwindCurrent.cpp
@@ -16,6 +16,7 @@
#define LOG_TAG "libbacktrace"
+#include <sys/ucontext.h>
#include <sys/types.h>
#include <backtrace/Backtrace.h>
@@ -27,27 +28,6 @@
#include "UnwindCurrent.h"
#include "UnwindMap.h"
-// Define the ucontext_t structures needed for each supported arch.
-#if defined(__arm__)
- // The current version of the <signal.h> doesn't define ucontext_t.
- #include <asm/sigcontext.h> // Ensure 'struct sigcontext' is defined.
-
- // Machine context at the time a signal was raised.
- typedef struct ucontext {
- uint32_t uc_flags;
- struct ucontext* uc_link;
- stack_t uc_stack;
- struct sigcontext uc_mcontext;
- uint32_t uc_sigmask;
- } ucontext_t;
-#elif defined(__i386__)
- #include <asm/sigcontext.h>
- #include <asm/ucontext.h>
- typedef struct ucontext ucontext_t;
-#elif !defined(__mips__) && !defined(__aarch64__)
- #error Unsupported architecture.
-#endif
-
//-------------------------------------------------------------------------
// UnwindCurrent functions.
//-------------------------------------------------------------------------
@@ -158,7 +138,7 @@ void UnwindCurrent::ExtractContext(void* sigcontext) {
context->regs[13] = uc->uc_mcontext.arm_sp;
context->regs[14] = uc->uc_mcontext.arm_lr;
context->regs[15] = uc->uc_mcontext.arm_pc;
-#elif defined(__mips__) || defined(__i386__)
+#else
context->uc_mcontext = uc->uc_mcontext;
#endif
}
diff --git a/libbacktrace/UnwindMap.cpp b/libbacktrace/UnwindMap.cpp
index 03bb192..8268db6 100644
--- a/libbacktrace/UnwindMap.cpp
+++ b/libbacktrace/UnwindMap.cpp
@@ -45,7 +45,7 @@ UnwindMap::~UnwindMap() {
pthread_mutex_lock(&g_map_mutex);
if (--g_map_references == 0) {
// Clear the local address space map.
- unw_map_set(unw_local_addr_space, NULL);
+ unw_map_local_set(NULL);
unw_map_cursor_destroy(&map_cursor_);
}
pthread_mutex_unlock(&g_map_mutex);
@@ -61,8 +61,8 @@ bool UnwindMap::Build() {
if (g_map_references == 0) {
return_value = (unw_map_cursor_create(&map_cursor_, pid_) == 0);
if (return_value) {
- // Set the local address space to this cursor map.
- unw_map_set(unw_local_addr_space, &map_cursor_);
+ // Set the local address space map to our new map.
+ unw_map_local_set(&map_cursor_);
g_map_references = 1;
g_map_cursor = map_cursor_;
}