Add some test files

This commit is contained in:
Théophile Bastian 2018-04-04 14:47:54 +02:00
parent cd7c1635aa
commit 0bd5a40bce
3 changed files with 62 additions and 0 deletions

1
test/.gitignore vendored Normal file
View file

@ -0,0 +1 @@
*.bin

20
test/Makefile Normal file
View file

@ -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)

41
test/dump_my_stack.cpp Normal file
View file

@ -0,0 +1,41 @@
#include <cstdio>
#include <DwarfInterpret.hpp>
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;
}