Skip to content

Commit

Permalink
Merge branch 'stacktrace' of github.com:JuliaLang/julia
Browse files Browse the repository at this point in the history
  • Loading branch information
GeorgeXing committed Jul 1, 2011
2 parents fa3afc5 + 6b77c1f commit f233863
Show file tree
Hide file tree
Showing 5 changed files with 187 additions and 8 deletions.
34 changes: 32 additions & 2 deletions external/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ LAPACK_VER = 3.3.1
ARPACK_VER = 96
FFTW_VER = 3.3-beta1
MONGOOSE_VER = 3.0

UNWIND_VER = 0.99
## high-level setup ##

JULIAHOME = $(shell pwd)/..
include ../Make.inc

OS = $(shell uname)
ARCH = $(shell uname -m)
LIBS = llvm readline pcre fdlibm dsfmt openblas lapack arpack fftw mongoose
LIBS = llvm readline pcre fdlibm dsfmt openblas lapack arpack fftw mongoose unwind

default: install
compile: $(addprefix compile-, $(LIBS))
Expand Down Expand Up @@ -304,6 +304,36 @@ mongoose-$(MONGOOSE_VER)/Makefile: mongoose-$(MONGOOSE_VER).tgz
clean-mongoose:
distclean-mongoose:
rm -rf mongoose-$(MONGOOSE_VER).tgz mongoose
## UNWIND ##

LIBUNWIND_TARGET_OBJ = $(EXTROOTLIB)/libunwind.a
LIBUNWIND_TARGET_SOURCE = $(JULIAHOME)/external/libunwind-$(UNWIND_VER)/Makefile

compile-unwind: $(LIBUNWIND_TARGET_SOURCE)
install-unwind: $(LIBUNWIND_TARGET_OBJ)

$(LIBUNWIND_TARGET_OBJ): $(LIBUNWIND_TARGET_SOURCE)
cd libunwind-$(UNWIND_VER) && make && make install



libunwind-$(UNWIND_VER).tar.gz:
$(DOWNLOAD) http:https://savannah.spinellicreations.com/libunwind/libunwind-$(UNWIND_VER).tar.gz

open-unwind: libunwind-$(UNWIND_VER).tar.gz
tar xvfz $<
touch $@

$(LIBUNWIND_TARGET_SOURCE): open-unwind
cd libunwind-$(UNWIND_VER) && ./configure CFLAGS="-U_FORTIFY_SOURCE -fPIC" --prefix=$(EXTROOT)

clean-unwind:
make -C libunwind-$(UNWIND_VER) clean
rm -rf $(LIBUNWIND_TARGET_OBJ) $(LIBUNWIND_TARGET_SOURCE)

distclean-unwind:
rm -rf libunwind-$(UWIND_VER).tar.gz libunwind-$(UNWIND_VER)


## phony targets ##

Expand Down
7 changes: 4 additions & 3 deletions src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,14 @@ LLT = $(LLTDIR)/libllt.a
FLISP = $(FLISPDIR)/libflisp.a

FLAGS = -falign-functions -Wall -Wno-strict-aliasing \
-fno-omit-frame-pointer \
-I$(FLISPDIR) -I$(LLTDIR) $(HFILEDIRS:%=-I%) $(LIBDIRS:%=-L%) \
-I$(shell $(LLVMROOT)/bin/llvm-config --includedir) -fvisibility=hidden
-I$(shell $(LLVMROOT)/bin/llvm-config --includedir)
DEBUGFLAGS = -ggdb3 -DDEBUG $(FLAGS)
SHIPFLAGS = -O3 -DNDEBUG $(FLAGS)

LIBFILES = $(FLISP) $(LLT)
LIBS = $(LIBFILES) -L$(EXTROOT)/lib -lutil -ldl -lm $(OSLIBS) \
LIBS = $(LIBFILES) -L$(EXTROOTLIB) -lutil -ldl -lm $(EXTROOTLIB)/libunwind-generic.a $(EXTROOTLIB)/libunwind.a $(OSLIBS) \
$(shell $(LLVMROOT)/bin/llvm-config --ldflags --libs engine) -lpthread

ifeq ($(JULIAGC),MARKSWEEP)
Expand Down Expand Up @@ -51,7 +52,7 @@ julia_flisp.boot: julia-parser.scm julia-syntax.scm \
boot.j.inc: boot.j preparse.scm julia_flisp.boot
$(FLISPDIR)/flisp ./preparse.scm < $< | $(FLISPDIR)/flisp ./bin2hex.scm > $@

codegen.o codegen.do: intrinsics.cpp
codegen.o codegen.do: intrinsics.cpp debuginfo.cpp
builtins.o builtins.do: table.c

$(LLT): $(LLTDIR)/*.h $(LLTDIR)/*.c
Expand Down
13 changes: 11 additions & 2 deletions src/codegen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include <sstream>
#include <map>
#include <vector>
#include "debuginfo.cpp"
#ifdef DEBUG
#undef NDEBUG
#endif
Expand Down Expand Up @@ -86,6 +87,7 @@ static GlobalVariable *jlsysmod_var;
static GlobalVariable *jlpgcstack_var;
#endif
static GlobalVariable *jlexc_var;
JuliaJITEventListener *jl_jit_events;

// important functions
static Function *jlnew_func;
Expand Down Expand Up @@ -198,6 +200,7 @@ extern "C" void jl_generate_fptr(jl_function_t *f)
Function *llvmf = (Function*)li->functionObject;
if (li->fptr == NULL)
li->fptr = (jl_fptr_t)jl_ExecutionEngine->getPointerToFunction(llvmf);
// should create a map, of fucntion names, and list of pointers so i can back trace.
assert(li->fptr != NULL);
f->fptr = li->fptr;
llvmf->deleteBody();
Expand Down Expand Up @@ -1918,9 +1921,12 @@ static void init_julia_llvm_env(Module *m)

extern "C" void jl_init_codegen()
{
#ifdef DEBUG
//printf ("you reached codegen");
//puts("lala codegen");
llvm::JITEmitDebugInfo = true;
#endif
llvm::NoFramePointerElim = true;
llvm::NoFramePointerElimNonLeaf = true;

InitializeNativeTarget();
jl_Module = new Module("julia", jl_LLVMContext);
jl_ExecutionEngine =
Expand All @@ -1930,4 +1936,7 @@ extern "C" void jl_init_codegen()
init_julia_llvm_env(jl_Module);

jl_init_intrinsic_functions();
jl_jit_events = new JuliaJITEventListener();
jl_ExecutionEngine->RegisterJITEventListener(jl_jit_events);
//JIT::RegisterJITEventListener(jl_jit_events);
}
89 changes: 89 additions & 0 deletions src/debuginfo.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
#include <llvm/ExecutionEngine/JITEventListener.h>
#include "llvm/Function.h"
#include <map>

using namespace std;
using namespace llvm;

struct FuncInfo{
const Function* func;
size_t lengthAdr;
};


class __attribute__ ((visibility("default"))) JuliaJITEventListener: public JITEventListener {
map<size_t, FuncInfo> info;

public:
virtual void NotifyFunctionEmitted(const Function &F,
void *Code, size_t Size, const EmittedFunctionDetails &Details) {
// Here i should write down the information into the map i want to know. Important Code name, location of code start, length (and or end),
FuncInfo tmp = {&F, Size};
//tmp.func = &F;
//tmp.lengthAdr = Size;
info[(size_t)(Code)] = tmp;
}
JuliaJITEventListener(){}
virtual ~JuliaJITEventListener() {}
public:

map<size_t, FuncInfo> getMap() {
return info;

}



};

extern JuliaJITEventListener *jl_jit_events;

extern "C" const char* getFunctionInfo(size_t pointer);

///*
const char* getFunctionInfo(size_t pointer) {
//printf("entered getfunc ");
map<size_t, FuncInfo> info = jl_jit_events->getMap();
const char* toReturn = NULL;
for (map<size_t, FuncInfo>::iterator it= info.begin(); it!= info.end(); it++) {
//printf("looking at pointer %lx ", (*it).first);
if ((*it).first <= pointer) {
//printf("start %lx. end %lx \n", (*it).first, (*it).first+(*it).second.lengthAdr);
if ( (size_t)(*it).first + (*it).second.lengthAdr >= pointer) {

//toReturn = strdup((*(*it).second.func).getName().data());
toReturn = (*(*it).second.func).getName().data();
break;
}
}/*else {
toReturn = "not found";
break;
}*/

}
//printf("exiting getfuncinfo ");
return toReturn;
}


/*
char* getFunctionInfo(size_t pointer) {
return "Debug Version of function";
}
*/



//return jl_jit_events->findFunc(pointer).getName().convertFromString();










52 changes: 51 additions & 1 deletion src/task.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
#include <unistd.h>
#include "llt.h"
#include "julia.h"

// This gives unwind only local unwinding options ==> faster code
#define UNW_LOCAL_ONLY
#include <libunwind.h>
/* This probing code is derived from Douglas Jones' user thread library */

/* the list of offsets in jmp_buf to be adjusted */
Expand Down Expand Up @@ -426,9 +428,55 @@ static void init_task(jl_task_t *t)
}
#endif

char* getFunctionInfo(size_t pointer);



void show_backtrace (void) {
unw_cursor_t cursor; unw_context_t uc;
unw_word_t ip, sp;

unw_getcontext(&uc);
unw_init_local(&cursor, &uc);
int index = unw_step(&cursor);
//printf("index %d\n", index);
while (index > 0) {
unw_get_reg(&cursor, UNW_REG_IP, &ip);
unw_get_reg(&cursor, UNW_REG_SP, &sp);
//printf("pre getFunc \n");
printf ("Function Name = %s, ip = %lx \n", getFunctionInfo(ip), (long) ip);
//printf("post getFunc \n");
index = unw_step(&cursor);
//printf("index %d\n", index);
}
printf("exiting backtrace");
}

void backtrace () {

int i = 0;
intptr_t rbp;
asm(" movq %%rbp, %0;"
: "=r" (rbp));
while (rbp != 0 && i<100) {
//printf(" rbp value %lx, value of i %d\n",rbp, i);
void **fp = ((void**)rbp)[0];
void *ip = ((void**)rbp)[1];
const char* info = getFunctionInfo(ip);
if(info != NULL) {
printf ("Function Name = %s, ip = %lx \n", info, (long) ip);
}
rbp = fp;
i++;
}


}

// yield to exception handler
void jl_raise(jl_value_t *e)
{
backtrace();
jl_task_t *eh = jl_current_task->state.eh_task;
eh->state.err = 1;
jl_exception_in_transit = e;
Expand All @@ -446,6 +494,8 @@ void jl_raise(jl_value_t *e)
ctx_switch(eh, eh->state.eh_ctx);
// TODO: continued exception
}
printf("exiting jl_raise");

}

jl_task_t *jl_new_task(jl_function_t *start, size_t ssize)
Expand Down

0 comments on commit f233863

Please sign in to comment.