]>
Commit | Line | Data |
---|---|---|
c772f001 | 1 | /* |
262a0e14 | 2 | * $Id$ |
c772f001 | 3 | * |
4 | * DEBUG: section 0 Debug Routines | |
5 | * AUTHOR: Harvest Derived | |
6 | * | |
7 | * SQUID Web Proxy Cache http://www.squid-cache.org/ | |
8 | * ---------------------------------------------------------- | |
9 | * | |
10 | * Squid is the result of efforts by numerous individuals from | |
11 | * the Internet community; see the CONTRIBUTORS file for full | |
12 | * details. Many organizations have provided support for Squid's | |
13 | * development; see the SPONSORS file for full details. Squid is | |
14 | * Copyrighted (C) 2001 by the Regents of the University of | |
15 | * California; see the COPYRIGHT file for full details. Squid | |
16 | * incorporates software developed and/or copyrighted by other | |
17 | * sources; see the CREDITS file for full details. | |
18 | * | |
19 | * This program is free software; you can redistribute it and/or modify | |
20 | * it under the terms of the GNU General Public License as published by | |
21 | * the Free Software Foundation; either version 2 of the License, or | |
22 | * (at your option) any later version. | |
26ac0430 | 23 | * |
c772f001 | 24 | * This program is distributed in the hope that it will be useful, |
25 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
26 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
27 | * GNU General Public License for more details. | |
26ac0430 | 28 | * |
c772f001 | 29 | * You should have received a copy of the GNU General Public License |
30 | * along with this program; if not, write to the Free Software | |
31 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA. | |
32 | * | |
33 | */ | |
e1f7507e AJ |
34 | #ifndef SQUID_DEBUG_H |
35 | #define SQUID_DEBUG_H | |
c772f001 | 36 | |
f95fe6ed | 37 | #include <iostream> |
a8d99c60 | 38 | #undef assert |
f95fe6ed | 39 | #include <sstream> |
bf8fe701 | 40 | #include <iomanip> |
a8d99c60 | 41 | #if defined assert |
42 | #undef assert | |
43 | #endif | |
44 | #if PURIFY | |
45 | #define assert(EX) ((void)0) | |
46 | #elif defined(NODEBUG) | |
47 | #define assert(EX) ((void)0) | |
48 | #elif STDC_HEADERS | |
49 | #define assert(EX) ((EX)?((void)0):xassert( # EX , __FILE__, __LINE__)) | |
50 | #else | |
51 | #define assert(EX) ((EX)?((void)0):xassert("EX", __FILE__, __LINE__)) | |
52 | #endif | |
f95fe6ed | 53 | |
e1f7507e AJ |
54 | /* defined debug section limits */ |
55 | #define MAX_DEBUG_SECTIONS 100 | |
56 | ||
feefade1 | 57 | /* defined names for Debug Levels */ |
58 | #define DBG_CRITICAL 0 /**< critical messages always shown when they occur */ | |
59 | #define DBG_IMPORTANT 1 /**< important messages always shown when their section is being checked */ | |
60 | /* levels 2-8 are still being discussed amongst the developers */ | |
61 | #define DBG_DATA 9 /**< output is a large data dump only necessary for advanced debugging */ | |
62 | ||
62e76326 | 63 | class Debug |
c772f001 | 64 | { |
62e76326 | 65 | |
c772f001 | 66 | public: |
62e76326 | 67 | static int Levels[MAX_DEBUG_SECTIONS]; |
68 | static int level; | |
f95fe6ed | 69 | static std::ostream &getDebugOut(); |
70 | static void finishDebug(); | |
d9e04dc7 | 71 | static void parseOptions(char const *); |
f95fe6ed | 72 | |
73 | private: | |
9eab365d | 74 | // Hack: replaces global ::xassert() to debug debugging assertions |
75 | static void xassert(const char *msg, const char *file, int line); | |
26ac0430 | 76 | |
4ecaa0f0 | 77 | static std::ostringstream *CurrentDebug; |
9eab365d | 78 | static int TheDepth; // level of nested debugging calls |
c772f001 | 79 | }; |
80 | ||
f76d2f97 AJ |
81 | extern FILE *debug_log; |
82 | ||
af28bfbd AJ |
83 | const size_t BuildPrefixInit(); |
84 | const char * SkipBuildPrefix(const char* path); | |
85 | ||
5b6f3fe5 | 86 | |
f95fe6ed | 87 | /* Debug stream */ |
88 | #define debugs(SECTION, LEVEL, CONTENT) \ | |
89 | do { \ | |
90 | if ((Debug::level = (LEVEL)) <= Debug::Levels[SECTION]) { \ | |
91 | Debug::getDebugOut() << CONTENT; \ | |
92 | Debug::finishDebug(); \ | |
93 | } \ | |
94 | } while (/*CONSTCOND*/ 0) | |
95 | ||
def17b6a | 96 | /* |
97 | * HERE is a macro that you can use like this: | |
98 | * | |
23d6095a | 99 | * debugs(1,2, HERE << "some message"); |
def17b6a | 100 | */ |
5b6f3fe5 | 101 | #define HERE SkipBuildPrefix(__FILE__)<<"("<<__LINE__<<") "<<__FUNCTION__<<": " |
def17b6a | 102 | |
23d6095a AJ |
103 | /* |
104 | * MYNAME is for use at debug levels 0 and 1 where HERE is too messy. | |
105 | * | |
106 | * debugs(1,1, MYNAME << "WARNING: some message"); | |
107 | */ | |
108 | #ifdef __PRETTY_FUNCTION__ | |
109 | #define MYNAME __PRETTY_FUNCTION__ << " " | |
110 | #else | |
111 | #define MYNAME __FUNCTION__ << " " | |
112 | #endif | |
113 | ||
cc192b50 | 114 | /* some uint8_t do not like streaming control-chars (values 0-31, 127+) */ |
26ac0430 AJ |
115 | inline std::ostream& operator <<(std::ostream &os, const uint8_t d) |
116 | { | |
066c9540 | 117 | return (os << (int)d); |
118 | } | |
119 | ||
e1f7507e | 120 | #endif /* SQUID_DEBUG_H */ |