I'm facing a stack corruption that breakpoints right before at the return of the
wWinMain function.. can anyone suggest me a way, or some tips of how to debug a stack corruption? (preferably in winDbg)
I know the corruption occurs in a procedure that I wrote in masm for my program, but the stack seems to be fine during the whole procedure.
rsp register has all it needs during the whole time..
Perform these in order:
- Compile with high level warning, and fix most warnings
- Run Code Analysis on project, and fix the warnings - specially the one that says word about buffer/array/stack etc.
- If the corruption is still is not fixed, reduce the function size (comment out the upper or lower part of function). Don't just
return- the corrupting stack buffer may still be allocated - commenting out will omit the bad-stack from program code.
- Refactor the
wWinMain- divide into sub tasks (functions). One of the function will fail because of stack, and you'll locate the real issue.
Ok, I've managed to trace the bug! I've overwritten a variables content by mistake by moving a value to qword ptr[rsp+20h], the 20h(offset) was too far and it overwritten my HINSTANCE variable. :) the stack corruption occurred around the 'instance' variable. managed to trace with the help of WinDbg good practice.
thanks to all the responders.