Improve debug output.

Should make it easier to determine the exact reason the debugger
call is triggered.
This commit is contained in:
Rene Gollent 2013-04-14 15:52:47 -04:00
parent eab9d5b444
commit 58a2847a12
1 changed files with 14 additions and 2 deletions

View File

@ -6,6 +6,10 @@
#include <Referenceable.h> #include <Referenceable.h>
#ifdef DEBUG
#include <stdio.h>
#endif
#include <debugger.h> #include <debugger.h>
//#define TRACE_REFERENCEABLE //#define TRACE_REFERENCEABLE
@ -28,6 +32,7 @@ BReferenceable::~BReferenceable()
{ {
#ifdef DEBUG #ifdef DEBUG
bool enterDebugger = false; bool enterDebugger = false;
char message[256];
if (fReferenceCount == 1) { if (fReferenceCount == 1) {
// Simple heuristic to test if this object was allocated // Simple heuristic to test if this object was allocated
// on the stack: check if this is within 1KB in either // on the stack: check if this is within 1KB in either
@ -44,14 +49,21 @@ BReferenceable::~BReferenceable()
status_t result = get_thread_info(find_thread(NULL), &info); status_t result = get_thread_info(find_thread(NULL), &info);
if (result != B_OK || this < info.stack_base if (result != B_OK || this < info.stack_base
|| this > info.stack_end) { || this > info.stack_end) {
snprintf(message, sizeof(message), "Deleted referenceable "
"object that's not on the stack (this: %p, stack_base: %p,"
" stack_end: %p)\n", this, info.stack_base,
info.stack_end);
enterDebugger = true; enterDebugger = true;
} }
} }
} else if (fReferenceCount != 0) } else if (fReferenceCount != 0) {
snprintf(message, sizeof(message), "Deleted referenceable object with "
"non-zero reference count (%" B_PRId32 ")\n", fReferenceCount);
enterDebugger = true; enterDebugger = true;
}
if (enterDebugger) if (enterDebugger)
debugger("Deleted referenceable object with non-zero ref count."); debugger(message);
#endif #endif
} }