From 0bd5a40bce453709ab58938c95672bf89ecf6e3d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9ophile=20Bastian?= Date: Wed, 4 Apr 2018 14:47:54 +0200 Subject: [PATCH] Add some test files --- test/.gitignore | 1 + test/Makefile | 20 ++++++++++++++++++++ test/dump_my_stack.cpp | 41 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 62 insertions(+) create mode 100644 test/.gitignore create mode 100644 test/Makefile create mode 100644 test/dump_my_stack.cpp diff --git a/test/.gitignore b/test/.gitignore new file mode 100644 index 0000000..a8a0dce --- /dev/null +++ b/test/.gitignore @@ -0,0 +1 @@ +*.bin diff --git a/test/Makefile b/test/Makefile new file mode 100644 index 0000000..290edf9 --- /dev/null +++ b/test/Makefile @@ -0,0 +1,20 @@ +CXX=g++ +CXXFLAGS=-Wall -Wextra -O1 -g --std=c++14 +CXXLIBS=-ldwarfpp -ldwarf -lelf -lc++fileno -ldwarfinterpret +CXXDIRS=-I../include -L../lib + + +OBJS = $(SRC:.cpp=.o) + +############################################################################### + +all: $(TARGET) + +%.bin: %.o + $(CXX) $(CXXFLAGS) $(CXXDIRS) $(CXXLIBS) $< -o "$@" + +%.o: %.cpp + $(CXX) $(CXXFLAGS) $(CXXDIRS) -c "$<" -o "$@" + +clean: + rm -f $(OBJS) $(TARGET) diff --git a/test/dump_my_stack.cpp b/test/dump_my_stack.cpp new file mode 100644 index 0000000..2415613 --- /dev/null +++ b/test/dump_my_stack.cpp @@ -0,0 +1,41 @@ +#include +#include + +using namespace std; + +volatile int optim_stopper = 0; + +void dump_my_stack() { + DwarfInterpret& dw = DwarfInterpret::acquire(); + + uintptr_t pc = dw.get_current_pc(); + while(true) { + printf(">> PC = %p <<\n", pc); + fflush(stdout); + pc = dw.get_return_address(pc); + } +} + +void fill_my_stack(int stack_depth) { + if(stack_depth == 0) + dump_my_stack(); + + optim_stopper++; + fill_my_stack(stack_depth - 1); +} + +int main(int argc, char** argv) { + MemoryMap mmap; + cout << "Dumping memory map… (" << mmap.size() << " entries)" << endl; + for(const auto& entry: mmap) { + entry.dump(cout); + } + cout << "End memory map" << endl; + int stack_depth = 5; + if(argc >= 2) + stack_depth = atoi(argv[1]); + + fill_my_stack(stack_depth); + + return 0; +}