Open debugger at the location of failing assert, if possible.
Break into the debugger in the function containing the assert that failed instead of inside wxWidgets assert handler which is several (~8) levels below the last line of the user code. This is much more useful in practice and also less confusing. Currently this only works for MSVC as the other compilers don't have any __debugbreak intrinsice equivalent. Also update the except sample to test wxTrap() directly too. Closes #11184. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@73124 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -1019,6 +1019,8 @@ void wxAbort()
|
||||
#if wxDEBUG_LEVEL
|
||||
|
||||
// break into the debugger
|
||||
#ifndef wxTrap
|
||||
|
||||
void wxTrap()
|
||||
{
|
||||
#if defined(__WINDOWS__) && !defined(__WXMICROWIN__)
|
||||
@@ -1032,6 +1034,8 @@ void wxTrap()
|
||||
#endif // Win/Unix
|
||||
}
|
||||
|
||||
#endif // wxTrap already defined as a macro
|
||||
|
||||
// default assert handler
|
||||
static void
|
||||
wxDefaultAssertHandler(const wxString& file,
|
||||
@@ -1181,6 +1185,8 @@ static void LINKAGEMODE SetTraceMasks()
|
||||
|
||||
#if wxDEBUG_LEVEL
|
||||
|
||||
bool wxTrapInAssert = false;
|
||||
|
||||
static
|
||||
bool DoShowAssertDialog(const wxString& msg)
|
||||
{
|
||||
@@ -1199,7 +1205,14 @@ bool DoShowAssertDialog(const wxString& msg)
|
||||
MB_YESNOCANCEL | MB_ICONSTOP ) )
|
||||
{
|
||||
case IDYES:
|
||||
wxTrap();
|
||||
// If we called wxTrap() directly from here, the programmer would
|
||||
// see this function and a few more calls between his own code and
|
||||
// it in the stack trace which would be perfectly useless and often
|
||||
// confusing. So instead just set the flag here and let the macros
|
||||
// defined in wx/debug.h call wxTrap() themselves, this ensures
|
||||
// that the debugger will show the line in the user code containing
|
||||
// the failing assert.
|
||||
wxTrapInAssert = true;
|
||||
break;
|
||||
|
||||
case IDCANCEL:
|
||||
|
||||
Reference in New Issue
Block a user