diff --git a/shared/context_struct.h b/shared/context_struct.h new file mode 100644 index 0000000..1946274 --- /dev/null +++ b/shared/context_struct.h @@ -0,0 +1,5 @@ +#include + +typedef struct { + uintptr_t rip, rsp, rbp; +} unwind_context_t; diff --git a/src/.gitignore b/src/.gitignore index 2311db3..39b608a 100644 --- a/src/.gitignore +++ b/src/.gitignore @@ -1 +1,2 @@ dwarf-assembly +gen_*.hpp diff --git a/src/CodeGenerator.cpp b/src/CodeGenerator.cpp index e3f3039..8c58a30 100644 --- a/src/CodeGenerator.cpp +++ b/src/CodeGenerator.cpp @@ -1,4 +1,5 @@ #include "CodeGenerator.hpp" +#include "gen_context_struct.hpp" using namespace std; @@ -6,10 +7,6 @@ static const char* PRELUDE = "#include \n" "#include \n" "\n" -"typedef struct {\n" -" uintptr_t rip, rsp, rbp;\n" -"} unwind_context_t;\n" -"\n" "typedef unwind_context_t (*_fde_func_t)(unwind_context_t, uintptr_t);\n" ; @@ -25,7 +22,8 @@ void CodeGenerator::generate() { } void CodeGenerator::gen_of_dwarf() { - os << PRELUDE << '\n' << endl; + os << CONTEXT_STRUCT_STR << '\n' + << PRELUDE << '\n' << endl; vector lookup_entries; diff --git a/src/Makefile b/src/Makefile index b663749..0f130df 100644 --- a/src/Makefile +++ b/src/Makefile @@ -10,13 +10,18 @@ OBJS=DwarfReader.o SimpleDwarf.o CodeGenerator.o main.o all: $(TARGET) -$(TARGET): $(OBJS) +$(TARGET): gen_context_struct.hpp $(OBJS) $(CXX) -o $@ $(CXXFLAGS) $^ $(CXXLIBS) +gen_context_struct.hpp: ../shared/context_struct.h + echo "static const char* CONTEXT_STRUCT_STR =" > $@ + sed 's/"/\\"/g' $< | sed 's/^\(.*\)$$/"\1\\n"/g' >> $@ + echo ";" >> $@ + %.o: %.cpp $(CXX) -o $@ $(CXXFLAGS) -c $< .PHONY: clean clean: - rm -f $(TARGET) *.o + rm -f $(TARGET) *.o gen_*.hpp