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