For c ++ x86 32-bit response
CONTEXT ctx; ctx.Flags = CONTEXT_CONTROL; if (GetThreadContext(GetCurrentThread(),&ctx)) { int * stack = (int*) ctx.Esp; // получили массив стека, в котором можно увидеть значения локальных переменных // тут можно смотреть стек printf("%x", stack[0]); }
For some versions with ++ you can get a pointer easier
int * stack = (int*)_ESP; // borland c++ int * stack; // для тех версий что поддерживают asm, этот вариант так же не все поддерживают asm { mov eax; esp; mov dword ptr stack, eax; }
Many environments support dump memory and the cpu window — you can visually examine the stack there.
And lastly, the barbaric way. Stack that is. You can take it and get an approximate stack address - by taking the address of a local variable (it is not equal to esp, but you can already analyze the stack):
int a = 1; int b = 2; int * stack = (int*)&a;
And see stack [0]; stack [1] and stack [-1];
I liked the organization of the stack: https://rsdn.ru/article/cpp/ObjectsAndPointers.xml with pictures.