1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
|
//Sous GCC...
#define intel_asm(x...) asm ( ".intel_syntax noprefix\n" #x ".att_syntax \n" )
//Sous VC++
#define intel_asm(x...) asm { x }
#if ATL_ARCHITECTURE == X86
//Drop stack to the global stacktrace var
std::cout << "Try to read stack..." << std::endl;
intel_asm (
push edi\n // Push data in stack for next code
push esi\n //
push edx\n //
push ecx\n //
push ebx\n //
//Initialisation
xor ecx, ecx\n //ecx = 0
mov edi, _st_head\n //edi = &stacktrace[0]
#if ATL_OS == WINNT
push esi\n
//Thanks to Neitsa =========================================
mov esi, fs:[0x18]\n// linear pointer to NT_TIB
mov eax, [esi+4]\n // get stack base in eax
sub eax, 4\n //the base of stack is non inclusive
//==========================================================
pop esi\n
#else
mov DWORD PTR _stack_size, 0\n
jmp non_implemented_yet\n
#endif
//==========================================================
unstack: \n //while(true) {
mov ebx, ebp \n // if(ebp+ecx == ebp) {
add ebx, ecx \n //
cmp ebx, eax \n //
je end_unstack\n // break;
// } else {
mov edx, [ebx]\n //
mov [edi], edx\n // stack_trace[n] = *(ebp+ecx);
add edi, 4 \n // n ++;
add ecx, 4 \n // ecx += 4;
// }
jmp unstack \n //}
end_unstack:\n
sub edi, _st_head\n // stack_size = 4 * n
mov _stack_size, edi\n //
shr DWORD PTR _stack_size, 2\n //stack_size >>= 2
non_implemented_yet:\n
pop ebx\n //
pop ecx\n //
pop edx\n // Get back stack data!
pop esi\n //
pop edi\n //
);
std::cout << std::dec << "* Stack size: " << stack_size << std::endl;
//Display the stack
for(unsigned int i = 0; i < stack_size; i++)
std::cout << (void*)stacktrace[i] << std::endl;
#endif |
Partager