From 26c6335afcdc93b87a92665101592ff8faaf1aa3 Mon Sep 17 00:00:00 2001 From: rousskov <> Date: Wed, 27 Feb 2008 01:44:16 +0000 Subject: [PATCH] Bug #2224 fix: reentrant debugging crashes Squid Synced with src/debug changes. TODO: Add a note that this file appears to copy debug.cc --- test-suite/test_tools.cc | 42 ++++++++++++++++++++++++++++++++++------ 1 file changed, 36 insertions(+), 6 deletions(-) diff --git a/test-suite/test_tools.cc b/test-suite/test_tools.cc index f4a62191b7..1da9f8ab90 100644 --- a/test-suite/test_tools.cc +++ b/test-suite/test_tools.cc @@ -1,6 +1,6 @@ /* - * $Id: test_tools.cc,v 1.9 2006/09/03 21:05:22 hno Exp $ + * $Id: test_tools.cc,v 1.10 2008/02/26 18:44:16 rousskov Exp $ * * AUTHOR: Robert Collins * @@ -161,18 +161,48 @@ debug_trap(const char *message) { fatal(message); } +int Debug::TheDepth = 0; + std::ostream & Debug::getDebugOut() { - assert (CurrentDebug == NULL); - CurrentDebug = new std::ostringstream(); + assert(TheDepth >= 0); + ++TheDepth; + if (TheDepth > 1) { + assert(CurrentDebug); + *CurrentDebug << std::endl << "reentrant debuging " << TheDepth << "-{"; + } else { + assert(!CurrentDebug); + CurrentDebug = new std::ostringstream(); + // set default formatting flags + CurrentDebug->setf(std::ios::fixed); + CurrentDebug->precision(2); + } return *CurrentDebug; } void Debug::finishDebug() { - _db_print("%s\n", CurrentDebug->str().c_str()); - delete CurrentDebug; - CurrentDebug = NULL; + assert(TheDepth >= 0); + assert(CurrentDebug); + if (TheDepth > 1) { + *CurrentDebug << "}-" << TheDepth << std::endl; + } else { + assert(TheDepth == 1); + _db_print("%s\n", CurrentDebug->str().c_str()); + delete CurrentDebug; + CurrentDebug = NULL; + } + --TheDepth; +} + +void +Debug::xassert(const char *msg, const char *file, int line) { + + if (CurrentDebug) { + *CurrentDebug << "assertion failed: " << file << ":" << line << + ": \"" << msg << "\""; + } + abort(); } std::ostringstream *Debug::CurrentDebug (NULL); -- 2.47.3