stack_walker: adapt to switch generation policies
This commit is contained in:
parent
c18027a0d2
commit
afe2d0b7c7
3 changed files with 28 additions and 7 deletions
|
@ -2,17 +2,21 @@ CXX=g++
|
||||||
CXXLIBS=-ldl
|
CXXLIBS=-ldl
|
||||||
CXXFLAGS=-O2 -fPIC -Wall -Wextra
|
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
|
OBJS=stack_walker.o
|
||||||
|
|
||||||
all: $(TARGET)
|
all: $(TARGETS)
|
||||||
|
|
||||||
$(TARGET): $(OBJS)
|
$(TARGET_BASE).%.so: $(OBJS:.o=.%.o)
|
||||||
$(CXX) $(CXXFLAGS) -shared $< $(CXXLIBS) -o $@
|
$(CXX) $(CXXFLAGS) -shared $< $(CXXLIBS) -o $@
|
||||||
|
|
||||||
%.o: %.cpp
|
%.global.o: %.cpp
|
||||||
$(CXX) $(CXXFLAGS) -c $< -o $@
|
$(CXX) $(CXXFLAGS) -DSGP_GLOBAL_SWITCH -c $< -o $@
|
||||||
|
|
||||||
|
%.per_func.o: %.cpp
|
||||||
|
$(CXX) $(CXXFLAGS) -DSGP_SWITCH_PER_FUNC -c $< -o $@
|
||||||
|
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -f $(OBJS) $(TARGET)
|
rm -f $(OBJS) $(TARGET_BASE)*.so
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <map>
|
#include <map>
|
||||||
|
|
||||||
|
#define UNUSED(x) (void)(x)
|
||||||
|
|
||||||
typedef void* dl_handle_t;
|
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
|
* symbols, depending on the state of the experiment. This is an abstraction
|
||||||
* function. */
|
* function. */
|
||||||
_fde_func_t fde_handler_for_pc(uintptr_t pc, MemoryMapEntry& mmap_entry) {
|
_fde_func_t fde_handler_for_pc(uintptr_t pc, MemoryMapEntry& mmap_entry) {
|
||||||
|
#ifdef SGP_SWITCH_PER_FUNC
|
||||||
// Get the lookup function
|
// Get the lookup function
|
||||||
_fde_func_t (*lookup)(uintptr_t) =
|
_fde_func_t (*lookup)(uintptr_t) =
|
||||||
(_fde_func_t (*)(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 nullptr;
|
||||||
|
|
||||||
return rfunc;
|
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) {
|
bool unwind_context(unwind_context_t& ctx) {
|
||||||
|
|
|
@ -2,7 +2,7 @@ CXX=g++
|
||||||
CXXFLAGS=-Wall -Wextra -O0 -g -I../stack_walker -rdynamic
|
CXXFLAGS=-Wall -Wextra -O0 -g -I../stack_walker -rdynamic
|
||||||
|
|
||||||
stack_walked.bin: stack_walked.cpp
|
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:
|
clean:
|
||||||
rm *.bin
|
rm *.bin
|
||||||
|
|
Loading…
Reference in a new issue