Refactor code generation: use shared/context_struct.h

This allows #include'ing `context_struct.h` in the stack walker
implementation as well
This commit is contained in:
Théophile Bastian 2018-04-25 18:11:59 +02:00
parent 771aec2621
commit 353a97c49d
4 changed files with 16 additions and 7 deletions

5
shared/context_struct.h Normal file
View file

@ -0,0 +1,5 @@
#include <stdint.h>
typedef struct {
uintptr_t rip, rsp, rbp;
} unwind_context_t;

1
src/.gitignore vendored
View file

@ -1 +1,2 @@
dwarf-assembly dwarf-assembly
gen_*.hpp

View file

@ -1,4 +1,5 @@
#include "CodeGenerator.hpp" #include "CodeGenerator.hpp"
#include "gen_context_struct.hpp"
using namespace std; using namespace std;
@ -6,10 +7,6 @@ static const char* PRELUDE =
"#include <stdint.h>\n" "#include <stdint.h>\n"
"#include <assert.h>\n" "#include <assert.h>\n"
"\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" "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() { void CodeGenerator::gen_of_dwarf() {
os << PRELUDE << '\n' << endl; os << CONTEXT_STRUCT_STR << '\n'
<< PRELUDE << '\n' << endl;
vector<LookupEntry> lookup_entries; vector<LookupEntry> lookup_entries;

View file

@ -10,13 +10,18 @@ OBJS=DwarfReader.o SimpleDwarf.o CodeGenerator.o main.o
all: $(TARGET) all: $(TARGET)
$(TARGET): $(OBJS) $(TARGET): gen_context_struct.hpp $(OBJS)
$(CXX) -o $@ $(CXXFLAGS) $^ $(CXXLIBS) $(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 %.o: %.cpp
$(CXX) -o $@ $(CXXFLAGS) -c $< $(CXX) -o $@ $(CXXFLAGS) -c $<
.PHONY: clean .PHONY: clean
clean: clean:
rm -f $(TARGET) *.o rm -f $(TARGET) *.o gen_*.hpp