Added nice debugging patch from Jeremy

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@21863 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Richard Frith-Macdonald 2005-10-23 15:11:19 +00:00
parent c0f48a2720
commit 964f95934c
2 changed files with 43 additions and 1 deletions

View file

@ -1,3 +1,15 @@
2005-10-23 Jeremy Bettis
* Source/NSException.m: Added a few debugging checks in the
exception handler code.
The handler struct that needs to be removed is passed to
_NSRemoveHandler. Therefore, instead of starting at
thread->_exception_handler and working your way down through
the frames, you can just use the passed in struct. This way,
if some bonehead called return in an NS_DURING block,
perhaps you can still remove the exception handler without
accessing memory that is on a freed section of the stack.
2005-10-23 Richard Frith-Macdonald <rfm@gnu.org>
* Source/NSString.m: remove test method for path handling setup,

View file

@ -365,6 +365,13 @@ _NSAddHandler (NSHandler* handler)
NSThread *thread;
thread = GSCurrentThread();
#if defined(__WIN32__) && defined(DEBUG)
if (thread->_exception_handler
&& IsBadReadPtr(thread->_exception_handler, sizeof(NSHandler)))
{
NSLog(@"ERROR: Current exception handler is bogus.");
}
#endif
handler->next = thread->_exception_handler;
thread->_exception_handler = handler;
}
@ -375,5 +382,28 @@ _NSRemoveHandler (NSHandler* handler)
NSThread *thread;
thread = GSCurrentThread();
thread->_exception_handler = thread->_exception_handler->next;
#if defined(DEBUG)
if (thread->_exception_handler != handler)
{
NSLog(@"ERROR: Removing exception handler that is not on the top "
@"of the stack. (You probably called return in an NS_DURING block.)");
}
#if defined(__WIN32__)
if (IsBadReadPtr(handler, sizeof(NSHandler)))
{
NSLog(@"ERROR: Could not remove exception handler, "
@"handler is bad pointer.");
thread->_exception_handler = 0;
return;
}
if (handler->next && IsBadReadPtr(handler->next, sizeof(NSHandler)))
{
NSLog(@"ERROR: Could not restore exception handler, "
@"handler->next is bad pointer.");
thread->_exception_handler = 0;
return;
}
#endif
#endif
thread->_exception_handler = handler->next;
}