Squid Web Cache master
Loading...
Searching...
No Matches
debug.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 1996-2025 The Squid Software Foundation and contributors
3 *
4 * Squid software is distributed under GPLv2+ license and includes
5 * contributions from numerous individuals and organizations.
6 * Please see the COPYING and CONTRIBUTORS files for details.
7 */
8
9#ifndef SQUID_COMPAT_DEBUG_H
10#define SQUID_COMPAT_DEBUG_H
11
12/*
13 * A debug method for use of external helpers and tools.
14 * It shunts the debug messages down stderr for logging by Squid
15 * or display to the user instead of corrupting the stdout data stream.
16 */
17#if HAVE_UNISTD_H
18#include <unistd.h>
19#endif
20
21/* Debugging stuff */
22
23extern int debug_enabled;
24
25/* the macro overload style is really a gcc-ism */
26#if defined(__GNUC__) || defined(__SUNPRO_CC)
27
28#define debug(X...) \
29 do { \
30 if (debug_enabled) { \
31 fprintf(stderr, "%s(%d): pid=%ld :", __FILE__, __LINE__, static_cast<long>(getpid())); \
32 fprintf(stderr, X); \
33 } \
34 } while (/*CONSTCOND*/ 0)
35
36#define ndebug(content) ndebug_(__FILE__, __LINE__, content)
37#define ndebug_(file, line, content) if (debug_enabled) { \
38 std::cerr << file << '(' << line << ')' << ": pid=" << getpid() << ':' \
39 << content << std::endl; \
40 } else (void)0
41
42#else /* __GNUC__ || __SUNPRO_CC */
43
44/* non-GCC compilers can't do the above macro define yet. */
45void debug(const char *format,...);
46#endif
47
48#endif /* SQUID_COMPAT_DEBUG_H */
49
int debug_enabled
Definition debug.cc:13
void debug(const char *format,...)
Definition debug.cc:19