From: robertc <> Date: Tue, 8 Jul 2003 04:44:28 +0000 (+0000) Subject: Summary: Merge debugs logic. X-Git-Tag: SQUID_3_0_PRE1~60 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=f95fe6ed2c36e2e0eb169eda54d963763cd32650;p=thirdparty%2Fsquid.git Summary: Merge debugs logic. Keywords: Patches applied: * robertc@squid-cache.org--squid/squid--cplusplusdebug--3.0--patch-4 Add tests, change debugs syntax. * robertc@squid-cache.org--squid/squid--cplusplusdebug--3.0--patch-3 Add test case for debugs in the case it doesn't require a ; * robertc@squid-cache.org--squid/squid--cplusplusdebug--3.0--patch-2 Enforce the use of ; at the end of debugs macro calls. * robertc@squid-cache.org--squid/squid--cplusplusdebug--3.0--patch-1 String based debug and operator ::new fixes. * robertc@squid-cache.org--squid/squid--cplusplusdebug--3.0--base-0 tag of robertc@squid-cache.org--squid/squid--HEAD--3.0--patch-222 --- diff --git a/include/SquidNew.h b/include/SquidNew.h new file mode 100644 index 0000000000..7434a486cb --- /dev/null +++ b/include/SquidNew.h @@ -0,0 +1,60 @@ +/* + * $Id: SquidNew.h,v 1.1 2003/07/07 22:44:28 robertc Exp $ + * + * AUTHOR: Harvest Derived + * + * SQUID Web Proxy Cache http://www.squid-cache.org/ + * ---------------------------------------------------------- + * + * Squid is the result of efforts by numerous individuals from + * the Internet community; see the CONTRIBUTORS file for full + * details. Many organizations have provided support for Squid's + * development; see the SPONSORS file for full details. Squid is + * Copyrighted (C) 2001 by the Regents of the University of + * California; see the COPYRIGHT file for full details. Squid + * incorporates software developed and/or copyrighted by other + * sources; see the CREDITS file for full details. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA. + * + */ + +#ifndef SQUID_NEW_H +#define SQUID_NEW_H + +/* Any code using libstdc++ must have externally resolvable overloads + * for void * operator new - which means in the .o for the binary, + * or in a shared library. static libs don't propogate the symbol + * so, look in the translation unit containing main() in squid + * for the extern version in squid + */ +#include +_SQUID_EXTERNNEW_ void *operator new(size_t size) throw (std::bad_alloc) +{ + return xmalloc(size); +} +_SQUID_EXTERNNEW_ void operator delete (void *address) throw() +{ + xfree (address); +} +_SQUID_EXTERNNEW_ void *operator new[] (size_t size) throw (std::bad_alloc) +{ + return xmalloc(size); +} +_SQUID_EXTERNNEW_ void operator delete[] (void *address) throw() +{ + xfree (address); +} +#endif /* SQUID_NEW_H */ diff --git a/include/util.h b/include/util.h index 73a5be55a0..38e7418b1d 100644 --- a/include/util.h +++ b/include/util.h @@ -1,5 +1,5 @@ /* - * $Id: util.h,v 1.70 2003/03/02 22:20:31 hno Exp $ + * $Id: util.h,v 1.71 2003/07/07 22:44:28 robertc Exp $ * * AUTHOR: Harvest Derived * @@ -86,23 +86,16 @@ SQUIDCEXTERN void Tolower(char *); SQUIDCEXTERN void xfree(void *); SQUIDCEXTERN void xxfree(const void *); #ifdef __cplusplus -#include -inline void *operator new(size_t size) throw (std::bad_alloc) -{ - return xmalloc(size); -} -inline void operator delete (void *address) throw() -{ - xfree (address); -} -inline void *operator new[] (size_t size) throw (std::bad_alloc) -{ - return xmalloc(size); -} -inline void operator delete[] (void *address) throw() -{ - xfree (address); -} +/* Any code using libstdc++ must have externally resolvable overloads + * for void * operator new - which means in the .o for the binary, + * or in a shared library. static libs don't propogate the symbol + * so, look in the translation unit containing main() in squid + * for the extern version in squid + */ +#ifndef _SQUID_EXTERNNEW_ +#define _SQUID_EXTERNNEW_ extern inline +#endif +#include "SquidNew.h" #endif /* rfc1738.c */ diff --git a/src/CacheDigest.cc b/src/CacheDigest.cc index c11459638d..7ba36e4992 100644 --- a/src/CacheDigest.cc +++ b/src/CacheDigest.cc @@ -1,6 +1,6 @@ /* - * $Id: CacheDigest.cc,v 1.36 2003/02/21 22:50:04 robertc Exp $ + * $Id: CacheDigest.cc,v 1.37 2003/07/07 22:44:28 robertc Exp $ * * DEBUG: section 70 Cache Digest * AUTHOR: Alex Rousskov @@ -67,8 +67,8 @@ cacheDigestInit(CacheDigest * cd, int capacity, int bpe) cd->bits_per_entry = bpe; cd->mask_size = mask_size; cd->mask = (char *)xcalloc(cd->mask_size, 1); - debug(70, 2) ("cacheDigestInit: capacity: %d entries, bpe: %d; size: %d bytes\n", - cd->capacity, cd->bits_per_entry, cd->mask_size); + debugs(70, 2) ("cacheDigestInit: capacity: " << cd->capacity << " entries, bpe: " << cd->bits_per_entry << "; size: " + << cd->mask_size << " bytes"); } CacheDigest * diff --git a/src/Debug.h b/src/Debug.h index bf690e0f51..68168d6256 100644 --- a/src/Debug.h +++ b/src/Debug.h @@ -1,6 +1,6 @@ /* - * $Id: Debug.h,v 1.3 2003/02/21 22:50:05 robertc Exp $ + * $Id: Debug.h,v 1.4 2003/07/07 22:44:28 robertc Exp $ * * DEBUG: section 0 Debug Routines * AUTHOR: Harvest Derived @@ -36,12 +36,29 @@ #ifndef SQUID_DEBUG #define SQUID_DEBUG +#include +#include + class Debug { public: static int Levels[MAX_DEBUG_SECTIONS]; static int level; + static std::ostream &getDebugOut(); + static void finishDebug(); + +private: + static std::ostringstream *currentDebug; }; +/* Debug stream */ +#define debugs(SECTION, LEVEL, CONTENT) \ + do { \ + if ((Debug::level = (LEVEL)) <= Debug::Levels[SECTION]) { \ + Debug::getDebugOut() << CONTENT; \ + Debug::finishDebug(); \ + } \ + } while (/*CONSTCOND*/ 0) + #endif /* SQUID_DEBUG */ diff --git a/src/Makefile.am b/src/Makefile.am index 4ce1975eae..82ea21d4ef 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1,7 +1,7 @@ # # Makefile for the Squid Object Cache server # -# $Id: Makefile.am,v 1.80 2003/06/27 22:32:30 hno Exp $ +# $Id: Makefile.am,v 1.81 2003/07/07 22:44:28 robertc Exp $ # # Uncomment and customize the following to suit your needs: # @@ -381,6 +381,7 @@ squid_SOURCES = \ send-announce.cc \ $(SNMPSOURCE) \ squid.h \ + SquidNew.cc \ tunnel.cc \ $(SSL_SOURCE) \ stat.cc \ @@ -466,15 +467,16 @@ squid_LDADD = \ @EPOLL_LIBS@ squid_DEPENDENCIES = $(top_builddir)/lib/libmiscutil.a @STORE_OBJS@ -unlinkd_SOURCES = unlinkd.cc +unlinkd_SOURCES = unlinkd.cc SquidNew.cc unlinkd_CXXFLAGS = -DUNLINK_DAEMON pinger_SOURCES = \ pinger.cc \ - debug.cc + debug.cc \ + SquidNew.cc -dnsserver_SOURCES = dnsserver.cc -recv_announce_SOURCES = recv-announce.cc +dnsserver_SOURCES = dnsserver.cc SquidNew.cc +recv_announce_SOURCES = recv-announce.cc SquidNew.cc ufsdump_SOURCES = debug.cc \ int.cc \ @@ -586,6 +588,7 @@ ufsdump_SOURCES = debug.cc \ squid.h \ $(SSL_SOURCE) \ tunnel.cc \ + SquidNew.cc \ stat.cc \ StatHist.cc \ String.cc \ diff --git a/src/SquidNew.cc b/src/SquidNew.cc new file mode 100644 index 0000000000..f724435333 --- /dev/null +++ b/src/SquidNew.cc @@ -0,0 +1,37 @@ + +/* + * $Id: SquidNew.cc,v 1.1 2003/07/07 22:44:28 robertc Exp $ + * + * DEBUG: section ??? Memory Allocation + * AUTHOR: Robert Collins + * + * SQUID Web Proxy Cache http://www.squid-cache.org/ + * ---------------------------------------------------------- + * + * Squid is the result of efforts by numerous individuals from + * the Internet community; see the CONTRIBUTORS file for full + * details. Many organizations have provided support for Squid's + * development; see the SPONSORS file for full details. Squid is + * Copyrighted (C) 2001 by the Regents of the University of + * California; see the COPYRIGHT file for full details. Squid + * incorporates software developed and/or copyrighted by other + * sources; see the CREDITS file for full details. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA. + * + */ + +#define _SQUID_EXTERNNEW_ +#include "squid.h" diff --git a/src/debug.cc b/src/debug.cc index aebe8258b6..adfdbc8457 100644 --- a/src/debug.cc +++ b/src/debug.cc @@ -1,6 +1,6 @@ /* - * $Id: debug.cc,v 1.91 2003/07/06 12:12:28 hno Exp $ + * $Id: debug.cc,v 1.92 2003/07/07 22:44:28 robertc Exp $ * * DEBUG: section 0 Debug Routines * AUTHOR: Harvest Derived @@ -35,6 +35,7 @@ #include "squid.h" #include "Debug.h" +#include int Debug::Levels[MAX_DEBUG_SECTIONS]; int Debug::level; @@ -521,3 +522,20 @@ ctx_get_descr(Ctx ctx) { return Ctx_Descrs[ctx] ? Ctx_Descrs[ctx] : ""; } + +std::ostream & +Debug::getDebugOut() { + assert (currentDebug == NULL); + currentDebug = new std::ostringstream(); + return *currentDebug; +} + +void +Debug::finishDebug() { + _db_print("%s\n", currentDebug->str().c_str()); + delete currentDebug; + currentDebug = NULL; +} + +std::ostringstream *Debug::currentDebug (NULL); +# diff --git a/test-suite/Makefile.am b/test-suite/Makefile.am index 22ea95109c..5d7172e54d 100644 --- a/test-suite/Makefile.am +++ b/test-suite/Makefile.am @@ -1,7 +1,7 @@ # # Makefile for the Squid Object Cache server # -# $Id: Makefile.am,v 1.8 2003/06/24 12:31:00 robertc Exp $ +# $Id: Makefile.am,v 1.9 2003/07/07 22:44:28 robertc Exp $ # AUTOMAKE_OPTIONS = subdir-objects @@ -14,7 +14,8 @@ INCLUDES = -I. -I$(srcdir) -I$(top_builddir)/include -I$(top_srcdir)/incl EXTRA_PROGRAMS = mem_node_test membanger splay tcp-banger2 rfc1738 ## Sort by dependencies - test lowest layers first -TESTS = rfc1738 \ +TESTS = debug \ + rfc1738 \ refcount\ splay\ MemPoolTest\ @@ -23,7 +24,8 @@ TESTS = rfc1738 \ http_range_test ## Sort by alpha - any build failures are significant. -check_PROGRAMS= http_range_test \ +check_PROGRAMS= debug \ + http_range_test \ MemPoolTest\ mem_node_test\ mem_hdr_test \ @@ -32,6 +34,8 @@ check_PROGRAMS= http_range_test \ splay LDADD = -L$(top_builddir)/lib -lmiscutil +debug_SOURCES = debug.cc test_tools.cc +debug_LDADD = $(top_builddir)/lib/Array.o $(LDADD) mem_node_test_SOURCES = mem_node_test.cc mem_node_test_LDADD = $(top_builddir)/src/mem_node.o $(LDADD) mem_hdr_test_SOURCES = mem_hdr_test.cc test_tools.cc diff --git a/test-suite/debug.cc b/test-suite/debug.cc new file mode 100644 index 0000000000..29aefb12f9 --- /dev/null +++ b/test-suite/debug.cc @@ -0,0 +1,90 @@ + +/* + * $Id: debug.cc,v 1.1 2003/07/07 22:44:28 robertc Exp $ + * + * DEBUG: section 19 Store Memory Primitives + * AUTHOR: Robert Collins + * + * SQUID Web Proxy Cache http://www.squid-cache.org/ + * ---------------------------------------------------------- + * + * Squid is the result of efforts by numerous individuals from + * the Internet community; see the CONTRIBUTORS file for full + * details. Many organizations have provided support for Squid's + * development; see the SPONSORS file for full details. Squid is + * Copyrighted (C) 2001 by the Regents of the University of + * California; see the COPYRIGHT file for full details. Squid + * incorporates software developed and/or copyrighted by other + * sources; see the CREDITS file for full details. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA. + * + * Copyright (c) 2003 Robert Collins + */ + +#include "squid.h" +#include "stmem.h" +#include "mem_node.h" +#include + +class StreamTest { + public: + std::ostream &serialise(std::ostream &); + char const *getAnInt() const; + char const *getACString() const; +}; + +std::ostream &operator << (std::ostream &aStream, StreamTest &anObject) +{ + return anObject.serialise(aStream); +} + +std::ostream& +StreamTest::serialise(std::ostream &aStream) +{ + aStream << "stream test"; + return aStream; +} + +char const * +StreamTest::getAnInt() const +{ + return "5"; +} + +char const * +StreamTest::getACString() const +{ + return "ThisIsAStreamTest"; +} + +int +main (int argc, char *argv) +{ + Debug::Levels[1] = 8; + debugs (1,1,"test" << "string"); + debugs (1,9,"dont show this" << "string"); + debugs (1,1,"test" << "string"); + debugs (1,1,"test" << "string"); + if (true) + debugs(1,9,"this won't compile if the macro is broken."); + else + debugs(1,1,"bar"); + StreamTest aStreamObject; + StreamTest *streamPointer (&aStreamObject); + debugs(1,1,aStreamObject); + debugs(1,1,streamPointer->getAnInt() << " " << aStreamObject.getACString()); + return 0; +} diff --git a/test-suite/test_tools.cc b/test-suite/test_tools.cc index 76074ebc65..800d4ec10d 100644 --- a/test-suite/test_tools.cc +++ b/test-suite/test_tools.cc @@ -1,6 +1,6 @@ /* - * $Id: test_tools.cc,v 1.1 2003/06/24 12:31:02 robertc Exp $ + * $Id: test_tools.cc,v 1.2 2003/07/07 22:44:28 robertc Exp $ * * AUTHOR: Robert Collins * @@ -33,8 +33,10 @@ * Copyright (c) 2003 Robert Collins */ +#define _SQUID_EXTERNNEW_ #include "squid.h" #include +#include void xassert(const char *msg, const char *file, int line) @@ -118,3 +120,21 @@ fatal(const char *message) { debug (0,0) ("Fatal: %s",message); exit (1); } + +std::ostream & +Debug::getDebugOut() +{ + assert (currentDebug == NULL); + currentDebug = new std::ostringstream(); + return *currentDebug; +} + +void +Debug::finishDebug() +{ + _db_print("%s\n", currentDebug->str().c_str()); + delete currentDebug; + currentDebug = NULL; +} + +std::ostringstream *Debug::currentDebug (NULL);