xref: /Universal-ctags/main/debug.h (revision aa629efca32cc4e8930ec9727c8338dc5040f6a0)
1 /*
2 *   Copyright (c) 1998-2002, Darren Hiebert
3 *
4 *   This source code is released for free distribution under the terms of the
5 *   GNU General Public License version 2 or (at your option) any later version.
6 *
7 *   External interface to debug.c
8 */
9 #ifndef CTAGS_MAIN_DEBUG_H
10 #define CTAGS_MAIN_DEBUG_H
11 
12 /*
13 *   Include files
14 */
15 #include "general.h"  /* must always come first */
16 
17 #include "gvars.h"
18 #include "types.h"
19 #ifdef DEBUG
20 # include <assert.h>
21 #endif
22 
23 /*
24 *   Macros
25 */
26 
27 #ifdef DEBUG
28 # define debug(level)      ((ctags_debugLevel & (long)(level)) != 0)
29 # define DebugStatement(x) x
30 # define PrintStatus(x)    if (debug(DEBUG_STATUS)) printf x;
31 # ifdef NDEBUG
32 #  define Assert(c) do {} while(0)
33 #  define AssertNotReached() do {} while(0)
34 # else
35    /* We expect cc supports c99 standard. */
36 #  if defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L
37 #   define ASSERT_FUNCTION __func__
38 #  else
39 #   define ASSERT_FUNCTION ((const char*)0)
40 #  endif
41 #  define Assert(c) ((c) ? ((void)0) : debugAssert(#c, __FILE__, __LINE__, ASSERT_FUNCTION))
42 #  define AssertNotReached() Assert(!"The control reaches unexpected place")
43 # endif
44 #else
45 # define DebugStatement(x)
46 # define PrintStatus(x)
47 # define Assert(c) do {} while(0)
48 # define AssertNotReached() do {} while(0)
49 # ifndef NDEBUG
50 #  define NDEBUG
51 # endif
52 #endif
53 
54 #ifdef DEBUG
55 /* This makes valgrind report an error earlier. */
56 #define DISABLE_OBJPOOL
57 #endif
58 /*
59 *   Data declarations
60 */
61 
62 /*  Defines the debugging levels.
63  */
64 enum eDebugLevels {
65 	DEBUG_READ   = 0x01,  /* echo raw (filtered) characters */
66 	DEBUG_PARSE  = 0x02,  /* echo parsing results */
67 	DEBUG_STATUS = 0x04,  /* echo file status information */
68 	DEBUG_OPTION = 0x08,  /* echo option parsing */
69 	DEBUG_CPP    = 0x10,  /* echo characters out of pre-processor */
70 	DEBUG_RAW    = 0x20   /* echo raw (filtered) characters */
71 };
72 
73 /*
74 *   Function prototypes
75 */
76 extern void lineBreak (void);
77 extern void debugPrintf (const enum eDebugLevels level, const char *const format, ...) CTAGS_ATTR_PRINTF (2, 3);
78 extern void debugPutc (const int level, const int c);
79 extern void debugParseNest (const bool increase, const unsigned int level);
80 extern void debugCppNest (const bool begin, const unsigned int level);
81 extern void debugCppIgnore (const bool ignore);
82 extern void debugEntry (const tagEntryInfo *const tag);
83 extern void debugAssert (const char *assertion, const char *file, unsigned int line, const char *function) attr__noreturn;
84 
85 #ifdef DEBUG
86 #define DEBUG_INIT() debugInit()
87 extern void debugInit (void);
88 extern void debugIndent(void);
89 extern void debugInc(void);
90 extern void debugDec(void);
91 
92 struct circularRefChecker;
93 extern struct circularRefChecker * circularRefCheckerNew (void);
94 extern void circularRefCheckerDestroy (struct circularRefChecker * checker);
95 extern int circularRefCheckerCheck (struct circularRefChecker *c, void *ptr);
96 extern int circularRefCheckerGetCurrent (struct circularRefChecker *c);
97 extern void circularRefCheckClear (struct circularRefChecker *c);
98 
99 #else
100 #define DEBUG_INIT() do { } while(0)
101 #endif	/* DEBUG */
102 #endif  /* CTAGS_MAIN_DEBUG_H */
103