A bit more fine-tuning to BReferenceable debugging.
- Rework quick stack range check as suggested by Ingo. - If the ref count is > 1 we invoke the debugger unconditionally. - If equal to 1, we first perform a quick heuristic check to see if the var might be on the stack. If we can't conclusively determine that is, we make certain by comparing to the thread's actual stack range.
This commit is contained in:
parent
cb44a2a6ef
commit
a34020ba21
@ -27,7 +27,8 @@ BReferenceable::BReferenceable()
|
||||
BReferenceable::~BReferenceable()
|
||||
{
|
||||
#ifdef DEBUG
|
||||
if (fReferenceCount != 0) {
|
||||
bool enterDebugger = false;
|
||||
if (fReferenceCount == 1) {
|
||||
// Simple heuristic to test if this object was allocated
|
||||
// on the stack: check if this is within 1KB in either
|
||||
// direction of the current stack address, and the reference
|
||||
@ -35,10 +36,22 @@ BReferenceable::~BReferenceable()
|
||||
// imply the object was allocated/destroyed on the stack
|
||||
// without any references being acquired or released.
|
||||
char test;
|
||||
int64 testOffset = (int64)this - (int64)&test;
|
||||
if (testOffset < -1024 || testOffset > 1024 || fReferenceCount != 1)
|
||||
debugger("Deleted referenceable object with non-zero ref count.");
|
||||
}
|
||||
size_t testOffset = (addr_t)this - (addr_t)&test;
|
||||
if (testOffset > 1024 || -testOffset > 1024) {
|
||||
// might still be a stack object, check the thread's
|
||||
// stack range to be sure.
|
||||
thread_info info;
|
||||
status_t result = get_thread_info(find_thread(NULL), &info);
|
||||
if (result != B_OK || this < info.stack_base
|
||||
|| this > info.stack_end) {
|
||||
enterDebugger = true;
|
||||
}
|
||||
}
|
||||
} else if (fReferenceCount != 0)
|
||||
enterDebugger = true;
|
||||
|
||||
if (enterDebugger)
|
||||
debugger("Deleted referenceable object with non-zero ref count.");
|
||||
#endif
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user