From e405bf160746f0fbf20fa29bbca5b3d0d99f9d0e Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Mon, 14 Mar 2016 02:26:44 +0100 Subject: [PATCH] Initialize CONTEXT ourselves in wxMSW wxStackWalker::Walk() As we do it for MinGW now, do it also for MSVC in a similar way: this is more straightforward and less annoying than raising an exception (which can be caught by a debugger and, at least, is logged by it) and ensures we use similar code for MinGW and MSVC which should hopefully minimizing the risk of breaking one or the other without noticing in the future. Normally there should be no changes in behaviour. --- src/msw/stackwalk.cpp | 30 +++++++++--------------------- 1 file changed, 9 insertions(+), 21 deletions(-) diff --git a/src/msw/stackwalk.cpp b/src/msw/stackwalk.cpp index c96a12bdb6..4c86de102c 100644 --- a/src/msw/stackwalk.cpp +++ b/src/msw/stackwalk.cpp @@ -308,26 +308,6 @@ void wxStackWalker::WalkFromException(size_t maxDepth) void wxStackWalker::Walk(size_t skip, size_t maxDepth) { - // We use it as a proxy for SEH support here. -#if wxUSE_ON_FATAL_EXCEPTION - // to get a CONTEXT for the current location, simply force an exception and - // get EXCEPTION_POINTERS from it - // - // note: - // 1. we additionally skip RaiseException() and WalkFrom() frames - // 2. explicit cast to EXCEPTION_POINTERS is needed with VC7.1 even if it - // shouldn't have been according to the docs - __try - { - RaiseException(0x1976, 0, 0, NULL); - } - __except( WalkFrom((EXCEPTION_POINTERS *)GetExceptionInformation(), - skip + 2, maxDepth + 2), EXCEPTION_CONTINUE_EXECUTION ) - { - // never executed because the above expression always evaluates to - // EXCEPTION_CONTINUE_EXECUTION - } -#else // !wxUSE_ON_FATAL_EXCEPTION // This code is based on frames.cpp from Edd Dawson's dbg library // (https://bitbucket.org/edd/dbg/) which is distributed under Boost // Software License. @@ -351,13 +331,21 @@ void wxStackWalker::Walk(size_t skip, size_t maxDepth) ctx.Eip = regEip; ctx.Esp = regEsp; ctx.Ebp = regEbp; + #elif __VISUALC__ + __asm + { + Here: + mov [ctx.Ebp], ebp + mov [ctx.Esp], esp + mov eax, [Here] + mov [ctx.Eip], eax + } #else #error Missing implementation of RtlCaptureContext() #endif #endif // Win64/32 WalkFrom(&ctx, skip, maxDepth); -#endif // wxUSE_ON_FATAL_EXCEPTION } #endif // wxUSE_STACKWALKER