Testing different stack pointers
This commit is contained in:
parent
b168438c14
commit
5ac9b665a1
4 changed files with 70 additions and 12 deletions
|
|
@ -3,13 +3,32 @@
|
|||
#include <iostream>
|
||||
#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;
|
||||
|
||||
void collect() {
|
||||
std::cout << "in collect" << std::endl;
|
||||
|
||||
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 << "SP-:\t" << --stack_start << std::endl;
|
||||
|
|
|
|||
44
src/GC/tests/stack2.cpp
Normal file
44
src/GC/tests/stack2.cpp
Normal 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;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue