Testing different stack pointers

This commit is contained in:
Victor Olin 2023-02-16 15:22:26 +01:00
parent b168438c14
commit 5ac9b665a1
4 changed files with 70 additions and 12 deletions

View file

@ -1,6 +1,6 @@
CC = clang++ CC = clang++
PWD = /home/virre/dev/systemF/org/language/src/GC/include PWD = /home/virre/dev/systemF/org/language/src/GC/include
CFLAGS = -Wall -Wextra -v -std=gnu++20 -stdlib=libc++ -I CFLAGS = -Wall -Wextra -v -g -std=gnu++20 -stdlib=libc++ -I
heap: heap:
$(CC) $(CFLAGS)$(PWD) lib/heap.cpp $(CC) $(CFLAGS)$(PWD) lib/heap.cpp
@ -9,14 +9,6 @@ h_test:
rm -f tests/h_test.out rm -f tests/h_test.out
$(CC) $(CFLAGS)$(PWD) tests/h_test.cpp lib/heap.cpp -o tests/h_test.out $(CC) $(CFLAGS)$(PWD) tests/h_test.cpp lib/heap.cpp -o tests/h_test.out
h_test_vg:
rm -f tests/h_test.out
$(CC) $(CFLAGS)$(PWD) -g tests/h_test.cpp lib/heap.cpp -o tests/h_test.out
linker: linker:
rm -f tests/linker.out rm -f tests/linker.out
$(CC) $(CFLAGS)$(PWD) tests/linker.cpp lib/heap.cpp -o tests/linker.out $(CC) $(CFLAGS)$(PWD) tests/linker.cpp lib/heap.cpp -o tests/linker.out
linker_vg:
rm -f tests/linker.out
$(CC) $(CFLAGS)$(PWD) -g tests/linker.cpp lib/heap.cpp -o tests/linker.out

View file

@ -65,7 +65,10 @@ namespace GC {
// get the frame adress, whwere local variables and saved registers are located // get the frame adress, whwere local variables and saved registers are located
auto stack_start = reinterpret_cast<uintptr_t *>(__builtin_frame_address(0)); auto stack_start = reinterpret_cast<uintptr_t *>(__builtin_frame_address(0));
// looking at 10 stack frames back // looking at 10 stack frames back
const uintptr_t *stack_end = (uintptr_t *)0; //reinterpret_cast<const uintptr_t *>(__builtin_frame_address(10)); const uintptr_t *stack_end = (uintptr_t *)0;
// denna segfaultar om arg för __b_f_a är > 2
// reinterpret_cast<const uintptr_t *>(__builtin_frame_address(10));
auto work_list = m_allocated_chunks; auto work_list = m_allocated_chunks;
mark(stack_start, stack_end, work_list); mark(stack_start, stack_end, work_list);

View file

@ -3,13 +3,32 @@
#include <iostream> #include <iostream>
#include <vector> #include <vector>
/*
* Stack.cpp
* - Tests stack scanning and stack pointers
*
* Goal: Find the values of the following variables
* and their position on the stack
* - unsigned long a
* - unsigned long b
* - unsigned long global_1
* - unsigned long global_2
*
* Result: Passed
*/
std::vector<uintptr_t *> iv; std::vector<uintptr_t *> iv;
void collect() { void collect() {
std::cout << "in collect" << std::endl; std::cout << "in collect" << std::endl;
uintptr_t *stack_start = reinterpret_cast<uintptr_t *>(__builtin_frame_address(0)); uintptr_t *stack_start = reinterpret_cast<uintptr_t *>(__builtin_frame_address(0));
// uintptr_t *stack_end = reinterpret_cast<uintptr_t *>(__builtin_frame_address(100));
// denna orsakar segfault om man ger __b_f_a ett värde större än 2
// uintptr_t *stack_end = reinterpret_cast<uintptr_t *>(__builtin_frame_address(100));
std::cout << "SP1:\t" << stack_start << "\nSP2:\t" << (stack_start - 1*sizeof(int)) << std::endl; std::cout << "SP1:\t" << stack_start << "\nSP2:\t" << (stack_start - 1*sizeof(int)) << std::endl;
std::cout << "SP-:\t" << --stack_start << std::endl; std::cout << "SP-:\t" << --stack_start << std::endl;

44
src/GC/tests/stack2.cpp Normal file
View file

@ -0,0 +1,44 @@
#include <cstring>
#include <iostream>
void dummy1();
void dummy2();
int main() {
uintptr_t *prev1 = reinterpret_cast<uintptr_t *>(__builtin_frame_address(0));
uintptr_t *prev2 = static_cast<uintptr_t *>(__builtin_frame_address(0));
std::cout << "reinterpret:\t" << prev1 << "\nstatic:\t\t" << prev2 << std::endl;
std::cout << "Start:\t\t" << prev1 << std::endl;
#pragma clang diagnostic ignored "-Wframe-address"
uintptr_t *tmp = reinterpret_cast<uintptr_t *>(__builtin_frame_address(1));
std::cout << "Frame 1:\t" << tmp << "\t\tDiff:\t" << std::hex << "0x"<< prev1 - tmp << std::endl;
prev1 = tmp;
#pragma clang diagnostic ignored "-Wframe-address"
tmp = reinterpret_cast<uintptr_t *>(__builtin_frame_address(2));
std::cout << "Frame 2:\t" << tmp << "\tDiff:\t" << std::hex << "0x" << prev1 - tmp << std::endl;
dummy1();
return 0;
}
void dummy1() {
std::cout << "Frame:\t\t" << __builtin_frame_address(0);
#pragma clang diagnostic ignored "-Wframe-address"
std::cout << "\t\tPrev:\t" << __builtin_frame_address(1) << std::endl;
dummy2();
std::cout << "D1 RA:\t\t" << std::hex << __builtin_return_address(0) << std::endl;
}
void dummy2() {
std::cout << "Frame:\t\t" << __builtin_frame_address(0);
#pragma clang diagnostic ignored "-Wframe-address"
std::cout << "\t\tPrev:\t" << __builtin_frame_address(1) << std::endl;
void *ra = __builtin_return_address(0);
std::cout << "D2 RA:\t\t" << std::hex << ra << std::endl;
std::cout << "D2 ERA:\t\t" << std::hex << __builtin_extract_return_addr(ra) << std::endl;
}