diff --git a/stack_walker/Makefile b/stack_walker/Makefile index 5d0435a..f7bf13b 100644 --- a/stack_walker/Makefile +++ b/stack_walker/Makefile @@ -2,17 +2,21 @@ CXX=g++ CXXLIBS=-ldl CXXFLAGS=-O2 -fPIC -Wall -Wextra -TARGET=libstack_walker.so +TARGET_BASE=libstack_walker +TARGETS=$(TARGET_BASE).global.so $(TARGET_BASE).per_func.so OBJS=stack_walker.o -all: $(TARGET) +all: $(TARGETS) -$(TARGET): $(OBJS) +$(TARGET_BASE).%.so: $(OBJS:.o=.%.o) $(CXX) $(CXXFLAGS) -shared $< $(CXXLIBS) -o $@ -%.o: %.cpp - $(CXX) $(CXXFLAGS) -c $< -o $@ +%.global.o: %.cpp + $(CXX) $(CXXFLAGS) -DSGP_GLOBAL_SWITCH -c $< -o $@ + +%.per_func.o: %.cpp + $(CXX) $(CXXFLAGS) -DSGP_SWITCH_PER_FUNC -c $< -o $@ clean: - rm -f $(OBJS) $(TARGET) + rm -f $(OBJS) $(TARGET_BASE)*.so diff --git a/stack_walker/stack_walker.cpp b/stack_walker/stack_walker.cpp index 176e8cd..9bf96aa 100644 --- a/stack_walker/stack_walker.cpp +++ b/stack_walker/stack_walker.cpp @@ -9,6 +9,7 @@ #include #include +#define UNUSED(x) (void)(x) typedef void* dl_handle_t; @@ -173,6 +174,7 @@ MemoryMapEntry* get_mmap_entry(uintptr_t pc) { * symbols, depending on the state of the experiment. This is an abstraction * function. */ _fde_func_t fde_handler_for_pc(uintptr_t pc, MemoryMapEntry& mmap_entry) { +#ifdef SGP_SWITCH_PER_FUNC // Get the lookup function _fde_func_t (*lookup)(uintptr_t) = (_fde_func_t (*)(uintptr_t)) ( @@ -191,6 +193,21 @@ _fde_func_t fde_handler_for_pc(uintptr_t pc, MemoryMapEntry& mmap_entry) { return nullptr; return rfunc; +#elif SGP_GLOBAL_SWITCH + UNUSED(pc); + _fde_func_t global_switch = + (_fde_func_t) (dlsym(mmap_entry.eh_dl_handle, "_eh_elf")); + + if(global_switch == nullptr) + return nullptr; + + return global_switch; +#else + UNUSED(pc); + UNUSED(mmap_entry); + assert(false); // Please compile with either -DSCP_SWITCH_PER_FUNC or + // -DSCP_GLOBAL_SWITCH +#endif } bool unwind_context(unwind_context_t& ctx) { diff --git a/tests/Makefile b/tests/Makefile index c409edc..cde4086 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -2,7 +2,7 @@ CXX=g++ CXXFLAGS=-Wall -Wextra -O0 -g -I../stack_walker -rdynamic stack_walked.bin: stack_walked.cpp - $(CXX) $(CXXFLAGS) -o $@ $^ -L../stack_walker -ldl -lstack_walker + $(CXX) $(CXXFLAGS) -o $@ $^ -L../stack_walker -ldl -lstack_walker.global clean: rm *.bin