]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Summary: Merge debugs logic.
authorrobertc <>
Tue, 8 Jul 2003 04:44:28 +0000 (04:44 +0000)
committerrobertc <>
Tue, 8 Jul 2003 04:44:28 +0000 (04:44 +0000)
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

include/SquidNew.h [new file with mode: 0644]
include/util.h
src/CacheDigest.cc
src/Debug.h
src/Makefile.am
src/SquidNew.cc [new file with mode: 0644]
src/debug.cc
test-suite/Makefile.am
test-suite/debug.cc [new file with mode: 0644]
test-suite/test_tools.cc

diff --git a/include/SquidNew.h b/include/SquidNew.h
new file mode 100644 (file)
index 0000000..7434a48
--- /dev/null
@@ -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 <new>
+_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 */
index 73a5be55a075c6758ac9b1f98d4e25ca43bec634..38e7418b1d533326655a6ccced4be5fc92053faf 100644 (file)
@@ -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 <new>
-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 */
index c11459638dbf0b564d377e9ca61c064065bf7bb1..7ba36e4992f32d85b9da5f41e1b9293ab80b66b2 100644 (file)
@@ -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 *
index bf690e0f5161e74160574cc0fdffe6a09f316dcc..68168d625630ae4a8ed62793492baa345e824597 100644 (file)
@@ -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
 #ifndef SQUID_DEBUG
 #define SQUID_DEBUG
 
+#include <iostream>
+#include <sstream>
+
 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 */
index 4ce1975eae36bcc398773d51c4342e95fa84c413..82ea21d4efdade330726f7673bca1a6b29b6cdc0 100644 (file)
@@ -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 (file)
index 0000000..f724435
--- /dev/null
@@ -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"
index aebe8258b61f262a824d4bc25ecde55a7dad40c9..adfdbc84571a24df27ab076c09b4207acdefe0e4 100644 (file)
@@ -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 <sstream>
 
 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] : "<null>";
 }
+
+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);
+#
index 22ea95109c57b5b128755cd380764cf9f9944223..5d7172e54de48db33c1081197bff32286bf0ff81 100644 (file)
@@ -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 (file)
index 0000000..29aefb1
--- /dev/null
@@ -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 <robertc@squid-cache.org>
+ */
+
+#include "squid.h"
+#include "stmem.h"
+#include "mem_node.h"
+#include <iostream>
+
+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;
+}
index 76074ebc6506f9a7d46d72b079797f620d886b41..800d4ec10d3d23eb6548024fce3614928c5cba9a 100644 (file)
@@ -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
  *
  * Copyright (c) 2003 Robert Collins <robertc@squid-cache.org>
  */
 
+#define _SQUID_EXTERNNEW_
 #include "squid.h"
 #include <iostream>
+#include <sstream>
 
 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);