From b26ff929d347aaf53d239dd20620e53823940634 Mon Sep 17 00:00:00 2001 From: Keno Fischer Date: Sun, 3 Aug 2014 15:18:36 -0400 Subject: [PATCH] Improve symbol lookup for backtraces when debug info not present We had all the info we were just not using it. Also adjusts the OS X sigdie_handler to the same thing as the linux one (i.e. look at the state of the thread before the signal handler rather than including the signal handler in the backtrace. Fixes #7821 --- Make.inc | 12 +++++++++--- Makefile | 6 +----- base/profile.jl | 3 ++- src/Makefile | 2 ++ src/debuginfo.cpp | 4 ++++ src/init.c | 11 ++++++++--- 6 files changed, 26 insertions(+), 12 deletions(-) diff --git a/Make.inc b/Make.inc index c932355fd66f4..2cf18fb10e854 100644 --- a/Make.inc +++ b/Make.inc @@ -250,7 +250,7 @@ JCFLAGS = -std=gnu99 -pipe $(fPIC) -fno-strict-aliasing -D_FILE_OFFSET_BITS=64 JCPPFLAGS = JCXXFLAGS = -pipe $(fPIC) -fno-rtti DEBUGFLAGS = -O0 -ggdb3 -DJL_DEBUG_BUILD -fstack-protector-all -SHIPFLAGS = -O3 -falign-functions +SHIPFLAGS = -O3 -ggdb3 -falign-functions endif ifeq ($(USECLANG),1) @@ -260,7 +260,7 @@ JCFLAGS = -pipe $(fPIC) -fno-strict-aliasing -D_FILE_OFFSET_BITS=64 JCPPFLAGS = JCXXFLAGS = -pipe $(fPIC) -fno-rtti DEBUGFLAGS = -O0 -g -DJL_DEBUG_BUILD -fstack-protector-all -SHIPFLAGS = -O3 +SHIPFLAGS = -O3 -g ifeq ($(OS), Darwin) ifeq ($(USE_LIBCPP), 1) CC += -stdlib=libc++ -mmacosx-version-min=10.7 @@ -287,7 +287,7 @@ JCFLAGS = -std=gnu99 -pipe $(fPIC) -fno-strict-aliasing -D_FILE_OFFSET_BITS=64 - JCPPFLAGS = JCXXFLAGS = -pipe $(fPIC) -fno-rtti DEBUGFLAGS = -O0 -ggdb3 -DJL_DEBUG_BUILD -fstack-protector-all -SHIPFLAGS = -O3 -falign-functions +SHIPFLAGS = -O3 -g -falign-functions endif ifeq ($(LLVM_VER),svn) @@ -545,10 +545,16 @@ ifeq ($(OS), Darwin) INSTALL_NAME_ID_DIR = @rpath/ INSTALL_NAME_CMD = install_name_tool -id $(INSTALL_NAME_ID_DIR) INSTALL_NAME_CHANGE_CMD = install_name_tool -change +ifeq ($(shell test `dsymutil -v | cut -d\- -f2 | cut -d. -f1` -gt 102 && echo yes), yes) + DSYMUTIL = dsymutil +else + true -ignore +endif else INSTALL_NAME_ID_DIR = INSTALL_NAME_CMD = true -ignore INSTALL_NAME_CHANGE_CMD = true -ignore + DSYMUTIL = true -ignore endif # shared library runtime paths diff --git a/Makefile b/Makefile index 0c3a56c694e3d..a95ce962cad32 100644 --- a/Makefile +++ b/Makefile @@ -78,11 +78,7 @@ $(build_private_libdir)/sys%$(SHLIB_EXT): $(build_private_libdir)/sys%o $(CXX) -shared -fPIC -L$(build_private_libdir) -L$(build_libdir) -L$(build_shlibdir) -o $@ $< \ $$([ $(OS) = Darwin ] && echo -Wl,-undefined,dynamic_lookup || echo -Wl,--unresolved-symbols,ignore-all ) \ $$([ $(OS) = WINNT ] && echo -ljulia -lssp) -ifeq ($(OS), Darwin) -ifeq ($(shell test `dsymutil -v | cut -d\- -f2 | cut -d. -f1` -gt 102 && echo yes), yes) - dsymutil $@ -endif -endif + $(DSYMUTIL) $@ $(build_private_libdir)/sys0.o: @$(QUIET_JULIA) cd base && \ diff --git a/base/profile.jl b/base/profile.jl index 6a2af4895bf7e..92d82a7cb6428 100644 --- a/base/profile.jl +++ b/base/profile.jl @@ -274,7 +274,8 @@ function tree_format(lilist::Vector{LineInfo}, counts::Vector{Int}, level::Int, "; ", truncto(string(li.func), widthfunc), "; ") - strs[i] = string(base, "line: ", li.line) + strs[i] = li.line == -1 ? string(base,"(unknown line)") : + string(base, "line: ", li.line) else strs[i] = "" end diff --git a/src/Makefile b/src/Makefile index 0cc292b6088b1..52419a2f0189a 100644 --- a/src/Makefile +++ b/src/Makefile @@ -90,6 +90,7 @@ endif $(build_shlibdir)/libjulia-debug.$(SHLIB_EXT): julia.expmap $(DOBJS) flisp/libflisp-debug.a support/libsupport-debug.a $(LIBUV) @$(call PRINT_LINK, $(CXXLD) $(DEBUGFLAGS) $(DOBJS) $(RPATH_ORIGIN) -o $@ $(LDFLAGS) $(DEBUG_LIBS)) $(INSTALL_NAME_CMD)libjulia-debug.$(SHLIB_EXT) $@ + $(DSYMUTIL) $@ libjulia-debug.a: julia.expmap $(DOBJS) flisp/libflisp-debug.a support/libsupport-debug.a rm -f $@ @$(call PRINT_LINK, ar -rcs $@ $(DOBJS)) @@ -104,6 +105,7 @@ endif $(build_shlibdir)/libjulia.$(SHLIB_EXT): julia.expmap $(OBJS) flisp/libflisp.a support/libsupport.a $(LIBUV) @$(call PRINT_LINK, $(CXXLD) $(SHIPFLAGS) $(OBJS) $(RPATH_ORIGIN) -o $@ $(LDFLAGS) $(RELEASE_LIBS) $(SONAME)) $(INSTALL_NAME_CMD)libjulia.$(SHLIB_EXT) $@ + $(DSYMUTIL) $@ libjulia.a: julia.expmap $(OBJS) flisp/libflisp.a support/libsupport.a rm -f $@ @$(call PRINT_LINK, ar -rcs $@ $(OBJS)) diff --git a/src/debuginfo.cpp b/src/debuginfo.cpp index 2f4de63a960b0..aec83e2329b8a 100644 --- a/src/debuginfo.cpp +++ b/src/debuginfo.cpp @@ -268,6 +268,10 @@ void jl_getDylibFunctionInfo(const char **name, int *line, const char **filename Dl_info dlinfo; const char *fname = 0; if ((dladdr((void*)pointer, &dlinfo) != 0) && dlinfo.dli_fname) { + // In case we fail with the debug info lookup, we at least still + // have the function name, even if we don't have line numbers + *name = dlinfo.dli_sname; + *filename = dlinfo.dli_fname; if (skipC && !jl_is_sysimg(dlinfo.dli_fname)) return; uint64_t fbase = (uint64_t)dlinfo.dli_fbase; diff --git a/src/init.c b/src/init.c index 01576665a462a..38936e6d7001d 100644 --- a/src/init.c +++ b/src/init.c @@ -17,6 +17,11 @@ #include #endif +#if defined(__APPLE__) +#define __need_ucontext64_t +#include +#endif + #include #include @@ -144,7 +149,7 @@ static int is_addr_on_stack(void *addr) #define SIGINFO SIGUSR1 #endif -void sigdie_handler(int sig, siginfo_t *info, void *context) +void sigdie_handler(int sig, siginfo_t *info, ucontext64_t *context) { if (sig != SIGINFO) { sigset_t sset; @@ -155,11 +160,11 @@ void sigdie_handler(int sig, siginfo_t *info, void *context) } ios_printf(ios_stderr,"\nsignal (%d): %s\n", sig, strsignal(sig)); #ifdef __APPLE__ - gdbbacktrace(); + bt_size = rec_backtrace_ctx(bt_data, MAX_BT_SIZE, (bt_context_t)&((ucontext64_t*)context)->uc_mcontext64->__ss); #else bt_size = rec_backtrace_ctx(bt_data, MAX_BT_SIZE, (ucontext_t*)context); - jlbacktrace(); #endif + jlbacktrace(); if (sig != SIGSEGV && sig != SIGBUS && sig != SIGILL &&