X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/3103e8a97e834e9793f0eb149aa82a99fd64ef9a..29fac1f6b1533ac2053c9785b87c3434af3998ae:/src/msw/stackwalk.cpp diff --git a/src/msw/stackwalk.cpp b/src/msw/stackwalk.cpp index 90a07b745c..c620eae669 100644 --- a/src/msw/stackwalk.cpp +++ b/src/msw/stackwalk.cpp @@ -56,7 +56,7 @@ void wxStackFrame::OnGetName() wxZeroMemory(symbolBuffer); PSYMBOL_INFO pSymbol = (PSYMBOL_INFO)symbolBuffer; - pSymbol->SizeOfStruct = sizeof(symbolBuffer); + pSymbol->SizeOfStruct = sizeof(SYMBOL_INFO); pSymbol->MaxNameLen = MAX_NAME_LEN; DWORD64 symDisplacement = 0; @@ -214,12 +214,16 @@ void wxStackFrame::OnGetParam() // wxStackWalker // ---------------------------------------------------------------------------- -void wxStackWalker::WalkFrom(const CONTEXT *pCtx, size_t skip) +void wxStackWalker::WalkFrom(const CONTEXT *pCtx, size_t skip, size_t maxDepth) { if ( !wxDbgHelpDLL::Init() ) { - wxLogError(_("Failed to get stack backtrace:\n%s"), + // don't log a user-visible error message here because the stack trace + // is only needed for debugging/diagnostics anyhow and we shouldn't + // confuse the user by complaining that we couldn't generate it + wxLogDebug(_T("Failed to get stack backtrace: %s"), wxDbgHelpDLL::GetErrorMessage().c_str()); + return; } // according to MSDN, the first parameter should be just a unique value and @@ -263,7 +267,7 @@ void wxStackWalker::WalkFrom(const CONTEXT *pCtx, size_t skip) #endif // _M_IX86 // iterate over all stack frames - for ( size_t nLevel = 0; ; nLevel++ ) + for ( size_t nLevel = 0; nLevel < maxDepth; nLevel++ ) { // get the next stack frame if ( !wxDbgHelpDLL::StackWalk @@ -289,7 +293,7 @@ void wxStackWalker::WalkFrom(const CONTEXT *pCtx, size_t skip) if ( nLevel >= skip ) { wxStackFrame frame(nLevel - skip, - (void *)sf.AddrPC.Offset, + wxUIntToPtr(sf.AddrPC.Offset), sf.AddrFrame.Offset); OnStackFrame(frame); @@ -306,12 +310,14 @@ void wxStackWalker::WalkFrom(const CONTEXT *pCtx, size_t skip) #endif } -void wxStackWalker::WalkFrom(const _EXCEPTION_POINTERS *ep, size_t skip) +void wxStackWalker::WalkFrom(const _EXCEPTION_POINTERS *ep, size_t skip, size_t maxDepth) { - WalkFrom(ep->ContextRecord, skip); + WalkFrom(ep->ContextRecord, skip, maxDepth); } -void wxStackWalker::WalkFromException() +#if wxUSE_ON_FATAL_EXCEPTION + +void wxStackWalker::WalkFromException(size_t maxDepth) { extern EXCEPTION_POINTERS *wxGlobalSEInformation; @@ -319,16 +325,18 @@ void wxStackWalker::WalkFromException() _T("wxStackWalker::WalkFromException() can only be called from wxApp::OnFatalException()") ); // don't skip any frames, the first one is where we crashed - WalkFrom(wxGlobalSEInformation, 0); + WalkFrom(wxGlobalSEInformation, 0, maxDepth); } -void wxStackWalker::Walk(size_t skip) +#endif // wxUSE_ON_FATAL_EXCEPTION + +void wxStackWalker::Walk(size_t skip, size_t WXUNUSED(maxDepth)) { // 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 WalkFromException() frames + // 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 @@ -338,7 +346,8 @@ void wxStackWalker::Walk(size_t skip) __except( WalkFrom((EXCEPTION_POINTERS *)GetExceptionInformation(), skip + 2), EXCEPTION_CONTINUE_EXECUTION ) { - // never executed because of WalkFromException() return value + // never executed because the above expression always evaluates to + // EXCEPTION_CONTINUE_EXECUTION } } @@ -382,21 +391,26 @@ void wxStackFrame::OnGetParam() // ---------------------------------------------------------------------------- void -wxStackWalker::WalkFrom(const CONTEXT * WXUNUSED(pCtx), size_t WXUNUSED(skip)) +wxStackWalker::WalkFrom(const CONTEXT * WXUNUSED(pCtx), + size_t WXUNUSED(skip), + size_t WXUNUSED(maxDepth)) { } void wxStackWalker::WalkFrom(const _EXCEPTION_POINTERS * WXUNUSED(ep), - size_t WXUNUSED(skip)) + size_t WXUNUSED(skip), + size_t WXUNUSED(maxDepth)) { } -void wxStackWalker::WalkFromException() +#if wxUSE_ON_FATAL_EXCEPTION +void wxStackWalker::WalkFromException(size_t WXUNUSED(maxDepth)) { } +#endif // wxUSE_ON_FATAL_EXCEPTION -void wxStackWalker::Walk(size_t WXUNUSED(skip)) +void wxStackWalker::Walk(size_t WXUNUSED(skip), size_t WXUNUSED(maxDepth)) { }