Loading include/corkscrew/map_info.h +4 −0 Original line number Diff line number Diff line Loading @@ -63,6 +63,10 @@ map_info_t* acquire_my_map_info_list(); * previous acquired using acquire_my_map_info_list(). */ void release_my_map_info_list(map_info_t* milist); /* Flushes the cached memory map so the next call to * acquire_my_map_info_list() gets fresh data. */ void flush_my_map_info_list(); #ifdef __cplusplus } #endif Loading libcorkscrew/Android.mk +11 −8 Original line number Diff line number Diff line Loading @@ -59,23 +59,26 @@ include $(BUILD_SHARED_LIBRARY) # Build test. include $(CLEAR_VARS) LOCAL_SRC_FILES := test.c LOCAL_CFLAGS += -std=gnu99 -Werror -fno-inline-small-functions LOCAL_SRC_FILES := test.cpp LOCAL_CFLAGS += -Werror -fno-inline-small-functions LOCAL_SHARED_LIBRARIES := libcorkscrew LOCAL_MODULE := libcorkscrew_test LOCAL_MODULE_TAGS := optional include $(BUILD_EXECUTABLE) ifeq ($(HOST_OS)-$(HOST_ARCH),linux-x86) ifeq ($(HOST_ARCH),x86) # Build libcorkscrew. include $(CLEAR_VARS) LOCAL_SRC_FILES += $(generic_src_files) $(x86_src_files) LOCAL_CFLAGS += -DCORKSCREW_HAVE_ARCH LOCAL_SHARED_LIBRARIES += libgccdemangle LOCAL_STATIC_LIBRARIES += libcutils liblog LOCAL_LDLIBS += -ldl -lrt LOCAL_LDLIBS += -ldl ifeq ($(HOST_OS),linux) LOCAL_SHARED_LIBRARIES += libgccdemangle # TODO: is this even needed on Linux? LOCAL_LDLIBS += -lrt endif LOCAL_CFLAGS += -std=gnu99 -Werror LOCAL_MODULE := libcorkscrew LOCAL_MODULE_TAGS := optional Loading @@ -83,11 +86,11 @@ include $(BUILD_HOST_SHARED_LIBRARY) # Build test. include $(CLEAR_VARS) LOCAL_SRC_FILES := test.c LOCAL_CFLAGS += -std=gnu99 -Werror -fno-inline-small-functions LOCAL_SRC_FILES := test.cpp LOCAL_CFLAGS += -Werror LOCAL_SHARED_LIBRARIES := libcorkscrew LOCAL_MODULE := libcorkscrew_test LOCAL_MODULE_TAGS := optional include $(BUILD_HOST_EXECUTABLE) endif # linux-x86 endif # HOST_ARCH == x86 libcorkscrew/arch-x86/backtrace-x86.c +17 −2 Original line number Diff line number Diff line Loading @@ -75,13 +75,18 @@ typedef struct ucontext { #endif /* __BIONIC_HAVE_UCONTEXT_T */ #else /* __BIONIC__ */ #elif defined(__APPLE__) #define _XOPEN_SOURCE #include <ucontext.h> #else // glibc has its own renaming of the Linux kernel's structures. #define __USE_GNU // For REG_EBP, REG_ESP, and REG_EIP. #include <ucontext.h> #endif /* __ BIONIC__ */ #endif /* Unwind state. */ typedef struct { Loading Loading @@ -819,9 +824,15 @@ ssize_t unwind_backtrace_signal_arch(siginfo_t* siginfo __attribute__((unused)), const ucontext_t* uc = (const ucontext_t*)sigcontext; unwind_state_t state; #if defined(__APPLE__) state.reg[DWARF_EBP] = uc->uc_mcontext->__ss.__ebp; state.reg[DWARF_ESP] = uc->uc_mcontext->__ss.__esp; state.reg[DWARF_EIP] = uc->uc_mcontext->__ss.__eip; #else state.reg[DWARF_EBP] = uc->uc_mcontext.gregs[REG_EBP]; state.reg[DWARF_ESP] = uc->uc_mcontext.gregs[REG_ESP]; state.reg[DWARF_EIP] = uc->uc_mcontext.gregs[REG_EIP]; #endif memory_t memory; init_memory(&memory, map_info_list); Loading @@ -831,6 +842,9 @@ ssize_t unwind_backtrace_signal_arch(siginfo_t* siginfo __attribute__((unused)), ssize_t unwind_backtrace_ptrace_arch(pid_t tid, const ptrace_context_t* context, backtrace_frame_t* backtrace, size_t ignore_depth, size_t max_depth) { #if defined(__APPLE__) return -1; #else pt_regs_x86_t regs; if (ptrace(PTRACE_GETREGS, tid, 0, ®s)) { return -1; Loading @@ -845,4 +859,5 @@ ssize_t unwind_backtrace_ptrace_arch(pid_t tid, const ptrace_context_t* context, init_memory_ptrace(&memory, tid); return unwind_backtrace_common(&memory, context->map_info_list, &state, backtrace, ignore_depth, max_depth); #endif } libcorkscrew/backtrace.c +20 −10 Original line number Diff line number Diff line Loading @@ -33,7 +33,6 @@ #include <unwind.h> #include <cutils/log.h> #include <cutils/atomic.h> #include <elf.h> #define __USE_GNU // For dladdr(3) in glibc. #include <dlfcn.h> Loading @@ -43,6 +42,15 @@ // Bionic implements and exports gettid but only implements tgkill. extern int tgkill(int tgid, int tid, int sig); #elif defined(__APPLE__) #include <sys/syscall.h> // Mac OS >= 10.6 has a system call equivalent to Linux's gettid(). static pid_t gettid() { return syscall(SYS_thread_selfid); } #else // glibc doesn't implement or export either gettid or tgkill. Loading Loading @@ -146,7 +154,9 @@ ssize_t unwind_backtrace_thread(pid_t tid, backtrace_frame_t* backtrace, ALOGV("Unwinding thread %d from thread %d.", tid, gettid()); #ifdef CORKSCREW_HAVE_ARCH // TODO: there's no tgkill(2) on Mac OS, so we'd either need the // mach_port_t or the pthread_t rather than the tid. #if defined(CORKSCREW_HAVE_ARCH) && !defined(__APPLE__) struct sigaction act; struct sigaction oact; memset(&act, 0, sizeof(act)); Loading Loading @@ -305,20 +315,20 @@ void format_backtrace_line(unsigned frameNumber, const backtrace_frame_t* frame const backtrace_symbol_t* symbol, char* buffer, size_t bufferSize) { const char* mapName = symbol->map_name ? symbol->map_name : "<unknown>"; const char* symbolName = symbol->demangled_name ? symbol->demangled_name : symbol->symbol_name; size_t fieldWidth = (bufferSize - 80) / 2; int fieldWidth = (bufferSize - 80) / 2; if (symbolName) { uint32_t pc_offset = symbol->relative_pc - symbol->relative_symbol_addr; if (pc_offset) { snprintf(buffer, bufferSize, "#%02d pc %08x %.*s (%.*s+%u)", frameNumber, symbol->relative_pc, fieldWidth, mapName, snprintf(buffer, bufferSize, "#%02u pc %p %.*s (%.*s+%u)", frameNumber, (void*) symbol->relative_pc, fieldWidth, mapName, fieldWidth, symbolName, pc_offset); } else { snprintf(buffer, bufferSize, "#%02d pc %08x %.*s (%.*s)", frameNumber, symbol->relative_pc, fieldWidth, mapName, snprintf(buffer, bufferSize, "#%02u pc %p %.*s (%.*s)", frameNumber, (void*) symbol->relative_pc, fieldWidth, mapName, fieldWidth, symbolName); } } else { snprintf(buffer, bufferSize, "#%02d pc %08x %.*s", frameNumber, symbol->relative_pc, fieldWidth, mapName); snprintf(buffer, bufferSize, "#%02u pc %p %.*s", frameNumber, (void*) symbol->relative_pc, fieldWidth, mapName); } } libcorkscrew/demangle.c +6 −0 Original line number Diff line number Diff line Loading @@ -25,6 +25,12 @@ extern char *__cxa_demangle (const char *mangled, char *buf, size_t *len, int *status); char* demangle_symbol_name(const char* name) { #if defined(__APPLE__) // Mac OS' __cxa_demangle demangles "f" as "float"; last tested on 10.7. if (name != NULL && name[0] != '_') { return NULL; } #endif // __cxa_demangle handles NULL by returning NULL return __cxa_demangle(name, 0, 0, 0); } Loading
include/corkscrew/map_info.h +4 −0 Original line number Diff line number Diff line Loading @@ -63,6 +63,10 @@ map_info_t* acquire_my_map_info_list(); * previous acquired using acquire_my_map_info_list(). */ void release_my_map_info_list(map_info_t* milist); /* Flushes the cached memory map so the next call to * acquire_my_map_info_list() gets fresh data. */ void flush_my_map_info_list(); #ifdef __cplusplus } #endif Loading
libcorkscrew/Android.mk +11 −8 Original line number Diff line number Diff line Loading @@ -59,23 +59,26 @@ include $(BUILD_SHARED_LIBRARY) # Build test. include $(CLEAR_VARS) LOCAL_SRC_FILES := test.c LOCAL_CFLAGS += -std=gnu99 -Werror -fno-inline-small-functions LOCAL_SRC_FILES := test.cpp LOCAL_CFLAGS += -Werror -fno-inline-small-functions LOCAL_SHARED_LIBRARIES := libcorkscrew LOCAL_MODULE := libcorkscrew_test LOCAL_MODULE_TAGS := optional include $(BUILD_EXECUTABLE) ifeq ($(HOST_OS)-$(HOST_ARCH),linux-x86) ifeq ($(HOST_ARCH),x86) # Build libcorkscrew. include $(CLEAR_VARS) LOCAL_SRC_FILES += $(generic_src_files) $(x86_src_files) LOCAL_CFLAGS += -DCORKSCREW_HAVE_ARCH LOCAL_SHARED_LIBRARIES += libgccdemangle LOCAL_STATIC_LIBRARIES += libcutils liblog LOCAL_LDLIBS += -ldl -lrt LOCAL_LDLIBS += -ldl ifeq ($(HOST_OS),linux) LOCAL_SHARED_LIBRARIES += libgccdemangle # TODO: is this even needed on Linux? LOCAL_LDLIBS += -lrt endif LOCAL_CFLAGS += -std=gnu99 -Werror LOCAL_MODULE := libcorkscrew LOCAL_MODULE_TAGS := optional Loading @@ -83,11 +86,11 @@ include $(BUILD_HOST_SHARED_LIBRARY) # Build test. include $(CLEAR_VARS) LOCAL_SRC_FILES := test.c LOCAL_CFLAGS += -std=gnu99 -Werror -fno-inline-small-functions LOCAL_SRC_FILES := test.cpp LOCAL_CFLAGS += -Werror LOCAL_SHARED_LIBRARIES := libcorkscrew LOCAL_MODULE := libcorkscrew_test LOCAL_MODULE_TAGS := optional include $(BUILD_HOST_EXECUTABLE) endif # linux-x86 endif # HOST_ARCH == x86
libcorkscrew/arch-x86/backtrace-x86.c +17 −2 Original line number Diff line number Diff line Loading @@ -75,13 +75,18 @@ typedef struct ucontext { #endif /* __BIONIC_HAVE_UCONTEXT_T */ #else /* __BIONIC__ */ #elif defined(__APPLE__) #define _XOPEN_SOURCE #include <ucontext.h> #else // glibc has its own renaming of the Linux kernel's structures. #define __USE_GNU // For REG_EBP, REG_ESP, and REG_EIP. #include <ucontext.h> #endif /* __ BIONIC__ */ #endif /* Unwind state. */ typedef struct { Loading Loading @@ -819,9 +824,15 @@ ssize_t unwind_backtrace_signal_arch(siginfo_t* siginfo __attribute__((unused)), const ucontext_t* uc = (const ucontext_t*)sigcontext; unwind_state_t state; #if defined(__APPLE__) state.reg[DWARF_EBP] = uc->uc_mcontext->__ss.__ebp; state.reg[DWARF_ESP] = uc->uc_mcontext->__ss.__esp; state.reg[DWARF_EIP] = uc->uc_mcontext->__ss.__eip; #else state.reg[DWARF_EBP] = uc->uc_mcontext.gregs[REG_EBP]; state.reg[DWARF_ESP] = uc->uc_mcontext.gregs[REG_ESP]; state.reg[DWARF_EIP] = uc->uc_mcontext.gregs[REG_EIP]; #endif memory_t memory; init_memory(&memory, map_info_list); Loading @@ -831,6 +842,9 @@ ssize_t unwind_backtrace_signal_arch(siginfo_t* siginfo __attribute__((unused)), ssize_t unwind_backtrace_ptrace_arch(pid_t tid, const ptrace_context_t* context, backtrace_frame_t* backtrace, size_t ignore_depth, size_t max_depth) { #if defined(__APPLE__) return -1; #else pt_regs_x86_t regs; if (ptrace(PTRACE_GETREGS, tid, 0, ®s)) { return -1; Loading @@ -845,4 +859,5 @@ ssize_t unwind_backtrace_ptrace_arch(pid_t tid, const ptrace_context_t* context, init_memory_ptrace(&memory, tid); return unwind_backtrace_common(&memory, context->map_info_list, &state, backtrace, ignore_depth, max_depth); #endif }
libcorkscrew/backtrace.c +20 −10 Original line number Diff line number Diff line Loading @@ -33,7 +33,6 @@ #include <unwind.h> #include <cutils/log.h> #include <cutils/atomic.h> #include <elf.h> #define __USE_GNU // For dladdr(3) in glibc. #include <dlfcn.h> Loading @@ -43,6 +42,15 @@ // Bionic implements and exports gettid but only implements tgkill. extern int tgkill(int tgid, int tid, int sig); #elif defined(__APPLE__) #include <sys/syscall.h> // Mac OS >= 10.6 has a system call equivalent to Linux's gettid(). static pid_t gettid() { return syscall(SYS_thread_selfid); } #else // glibc doesn't implement or export either gettid or tgkill. Loading Loading @@ -146,7 +154,9 @@ ssize_t unwind_backtrace_thread(pid_t tid, backtrace_frame_t* backtrace, ALOGV("Unwinding thread %d from thread %d.", tid, gettid()); #ifdef CORKSCREW_HAVE_ARCH // TODO: there's no tgkill(2) on Mac OS, so we'd either need the // mach_port_t or the pthread_t rather than the tid. #if defined(CORKSCREW_HAVE_ARCH) && !defined(__APPLE__) struct sigaction act; struct sigaction oact; memset(&act, 0, sizeof(act)); Loading Loading @@ -305,20 +315,20 @@ void format_backtrace_line(unsigned frameNumber, const backtrace_frame_t* frame const backtrace_symbol_t* symbol, char* buffer, size_t bufferSize) { const char* mapName = symbol->map_name ? symbol->map_name : "<unknown>"; const char* symbolName = symbol->demangled_name ? symbol->demangled_name : symbol->symbol_name; size_t fieldWidth = (bufferSize - 80) / 2; int fieldWidth = (bufferSize - 80) / 2; if (symbolName) { uint32_t pc_offset = symbol->relative_pc - symbol->relative_symbol_addr; if (pc_offset) { snprintf(buffer, bufferSize, "#%02d pc %08x %.*s (%.*s+%u)", frameNumber, symbol->relative_pc, fieldWidth, mapName, snprintf(buffer, bufferSize, "#%02u pc %p %.*s (%.*s+%u)", frameNumber, (void*) symbol->relative_pc, fieldWidth, mapName, fieldWidth, symbolName, pc_offset); } else { snprintf(buffer, bufferSize, "#%02d pc %08x %.*s (%.*s)", frameNumber, symbol->relative_pc, fieldWidth, mapName, snprintf(buffer, bufferSize, "#%02u pc %p %.*s (%.*s)", frameNumber, (void*) symbol->relative_pc, fieldWidth, mapName, fieldWidth, symbolName); } } else { snprintf(buffer, bufferSize, "#%02d pc %08x %.*s", frameNumber, symbol->relative_pc, fieldWidth, mapName); snprintf(buffer, bufferSize, "#%02u pc %p %.*s", frameNumber, (void*) symbol->relative_pc, fieldWidth, mapName); } }
libcorkscrew/demangle.c +6 −0 Original line number Diff line number Diff line Loading @@ -25,6 +25,12 @@ extern char *__cxa_demangle (const char *mangled, char *buf, size_t *len, int *status); char* demangle_symbol_name(const char* name) { #if defined(__APPLE__) // Mac OS' __cxa_demangle demangles "f" as "float"; last tested on 10.7. if (name != NULL && name[0] != '_') { return NULL; } #endif // __cxa_demangle handles NULL by returning NULL return __cxa_demangle(name, 0, 0, 0); }