Skip to content

Commit

Permalink
Improve symbol lookup for backtraces when debug info not present
Browse files Browse the repository at this point in the history
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 JuliaLang#7821
  • Loading branch information
Keno committed Aug 3, 2014
1 parent 0457c7a commit b26ff92
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 12 deletions.
12 changes: 9 additions & 3 deletions Make.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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
Expand Down
6 changes: 1 addition & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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 && \
Expand Down
3 changes: 2 additions & 1 deletion base/profile.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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))
Expand Down
4 changes: 4 additions & 0 deletions src/debuginfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
11 changes: 8 additions & 3 deletions src/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@
#include <unistd.h>
#endif

#if defined(__APPLE__)
#define __need_ucontext64_t
#include <machine/_structs.h>
#endif

#include <errno.h>
#include <signal.h>

Expand Down Expand Up @@ -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;
Expand All @@ -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 &&
Expand Down

0 comments on commit b26ff92

Please sign in to comment.