From 58a2847a128a44839be10451a26851c650e4fa42 Mon Sep 17 00:00:00 2001 From: Rene Gollent Date: Sun, 14 Apr 2013 15:52:47 -0400 Subject: [PATCH] Improve debug output. Should make it easier to determine the exact reason the debugger call is triggered. --- src/kits/support/Referenceable.cpp | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/kits/support/Referenceable.cpp b/src/kits/support/Referenceable.cpp index 1aaedec5d9..58a33a6d17 100644 --- a/src/kits/support/Referenceable.cpp +++ b/src/kits/support/Referenceable.cpp @@ -6,6 +6,10 @@ #include +#ifdef DEBUG +#include +#endif + #include //#define TRACE_REFERENCEABLE @@ -28,6 +32,7 @@ BReferenceable::~BReferenceable() { #ifdef DEBUG bool enterDebugger = false; + char message[256]; if (fReferenceCount == 1) { // Simple heuristic to test if this object was allocated // 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); if (result != B_OK || this < info.stack_base || 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; } } - } 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; + } if (enterDebugger) - debugger("Deleted referenceable object with non-zero ref count."); + debugger(message); #endif }