WinDBG Tutorial – Part 2
Items covered – Stack overflow – Stack trace (k) – Frame inspection (.frame n) Code used For this exercise, we will work with the following test program (Win32 C++ console project): #include “stdafx.h” int pow( int , int ); int _tmain( int argc, _TCHAR* argv[]) { int a = 2; int p = 9; int c = 0; printf( “a=” ); scanf( “%d” ,&a); printf( “p=” ); scanf( “%d” ,&p); c = pow(a,p); printf( “C=%dn” ,c); return 0; } int pow( int a, int p){ if (a > 2*p) return a-p; return pow(a*a, p + 1); } What the program does is: read two variables, a and p and afterwards call a rather unusual method named “pow”, which seems to be a finite recursion, ending when the value of the variable a is more than twice the value of variable p. The recursion seems correct, as variable a is squared every iteration whereas p is only incremented. Let’s see what the trouble actually is.
Excerpt from:
WinDBG Tutorial – Part 2


