don't try to show stack trace in assert msg box unless it's available (replaces patch 1212925, fixes bug 1212147)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@34498 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -70,6 +70,9 @@
|
|||||||
#ifdef __WXDEBUG__
|
#ifdef __WXDEBUG__
|
||||||
#ifdef wxUSE_STACKWALKER
|
#ifdef wxUSE_STACKWALKER
|
||||||
#include "wx/stackwalk.h"
|
#include "wx/stackwalk.h"
|
||||||
|
#ifdef __WXMSW__
|
||||||
|
#include "wx/msw/debughlp.h"
|
||||||
|
#endif
|
||||||
#endif // wxUSE_STACKWALKER
|
#endif // wxUSE_STACKWALKER
|
||||||
#endif // __WXDEBUG__
|
#endif // __WXDEBUG__
|
||||||
|
|
||||||
@@ -707,35 +710,14 @@ bool DoShowAssertDialog(const wxString& msg)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// show the assert modal dialog
|
static wxString GetAssertStackTrace()
|
||||||
static
|
|
||||||
void ShowAssertDialog(const wxChar *szFile,
|
|
||||||
int nLine,
|
|
||||||
const wxChar *szCond,
|
|
||||||
const wxChar *szMsg,
|
|
||||||
wxAppTraits *traits)
|
|
||||||
{
|
{
|
||||||
// this variable can be set to true to suppress "assert failure" messages
|
wxString stackTrace;
|
||||||
static bool s_bNoAsserts = false;
|
|
||||||
|
|
||||||
wxString msg;
|
// check that we can get the stack trace before trying to do it
|
||||||
msg.reserve(2048);
|
if ( !wxDbgHelpDLL::Init() )
|
||||||
|
return stackTrace;
|
||||||
|
|
||||||
// make life easier for people using VC++ IDE by using this format: like
|
|
||||||
// this, clicking on the message will take us immediately to the place of
|
|
||||||
// the failed assert
|
|
||||||
msg.Printf(wxT("%s(%d): assert \"%s\" failed"), szFile, nLine, szCond);
|
|
||||||
|
|
||||||
if ( szMsg )
|
|
||||||
{
|
|
||||||
msg << _T(": ") << szMsg;
|
|
||||||
}
|
|
||||||
else // no message given
|
|
||||||
{
|
|
||||||
msg << _T('.');
|
|
||||||
}
|
|
||||||
|
|
||||||
#if wxUSE_STACKWALKER
|
|
||||||
class StackDump : public wxStackWalker
|
class StackDump : public wxStackWalker
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@@ -779,23 +761,52 @@ void ShowAssertDialog(const wxChar *szFile,
|
|||||||
|
|
||||||
StackDump dump;
|
StackDump dump;
|
||||||
dump.Walk(5); // don't show OnAssert() call itself
|
dump.Walk(5); // don't show OnAssert() call itself
|
||||||
wxString stackTrace = dump.GetStackTrace();
|
stackTrace = dump.GetStackTrace();
|
||||||
|
|
||||||
// don't show more than maxLines or we could get a dialog too tall to be
|
// don't show more than maxLines or we could get a dialog too tall to be
|
||||||
// shown on screen: 20 should be ok everywhere as even with 15 pixel high
|
// shown on screen: 20 should be ok everywhere as even with 15 pixel high
|
||||||
// characters it is still only 300 pixels...
|
// characters it is still only 300 pixels...
|
||||||
const int maxLines = 20;
|
static const int maxLines = 20;
|
||||||
int count = stackTrace.Freq(wxT('\n'));
|
const int count = stackTrace.Freq(wxT('\n'));
|
||||||
if (count > maxLines)
|
for ( int i = 0; i < count - maxLines; i++ )
|
||||||
|
stackTrace = stackTrace.BeforeLast(wxT('\n'));
|
||||||
|
|
||||||
|
return stackTrace;
|
||||||
|
}
|
||||||
|
|
||||||
|
// show the assert modal dialog
|
||||||
|
static
|
||||||
|
void ShowAssertDialog(const wxChar *szFile,
|
||||||
|
int nLine,
|
||||||
|
const wxChar *szCond,
|
||||||
|
const wxChar *szMsg,
|
||||||
|
wxAppTraits *traits)
|
||||||
|
{
|
||||||
|
// this variable can be set to true to suppress "assert failure" messages
|
||||||
|
static bool s_bNoAsserts = false;
|
||||||
|
|
||||||
|
wxString msg;
|
||||||
|
msg.reserve(2048);
|
||||||
|
|
||||||
|
// make life easier for people using VC++ IDE by using this format: like
|
||||||
|
// this, clicking on the message will take us immediately to the place of
|
||||||
|
// the failed assert
|
||||||
|
msg.Printf(wxT("%s(%d): assert \"%s\" failed"), szFile, nLine, szCond);
|
||||||
|
|
||||||
|
if ( szMsg )
|
||||||
{
|
{
|
||||||
int i;
|
msg << _T(": ") << szMsg;
|
||||||
for (i = 0; i < count - maxLines; i++)
|
|
||||||
stackTrace = stackTrace.BeforeLast(wxT('\n'));
|
|
||||||
}
|
}
|
||||||
|
else // no message given
|
||||||
|
{
|
||||||
|
msg << _T('.');
|
||||||
|
}
|
||||||
|
|
||||||
|
#if wxUSE_STACKWALKER
|
||||||
|
const wxString stackTrace = GetAssertStackTrace();
|
||||||
if ( !stackTrace.empty() )
|
if ( !stackTrace.empty() )
|
||||||
{
|
{
|
||||||
msg << _T("\n\nCall stack:\n")
|
msg << _T("\n\nCall stack:\n") << stackTrace;
|
||||||
<< stackTrace;
|
|
||||||
}
|
}
|
||||||
#endif // wxUSE_STACKWALKER
|
#endif // wxUSE_STACKWALKER
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user