Project

General

Profile

Statistics
| Branch: | Tag: | Revision:

gdp / ep / ep_dbg.h @ master

History | View | Annotate | Download (3.2 KB)

1 a901db09 Eric Allman
/* vim: set ai sw=8 sts=8 ts=8 :*/
2 47c6ea64 Eric Allman
3
/***********************************************************************
4 055d3009 Eric Allman
**  ----- BEGIN LICENSE BLOCK -----
5
**        LIBEP: Enhanced Portability Library (Reduced Edition)
6
**
7 c87dd166 Eric Allman
**        Copyright (c) 2008-2019, Eric P. Allman.  All rights reserved.
8
**        Copyright (c) 2015-2019, Regents of the University of California.
9 6bd5476b Eric Allman
**        All rights reserved.
10 055d3009 Eric Allman
**
11 6bd5476b Eric Allman
**        Permission is hereby granted, without written agreement and without
12
**        license or royalty fees, to use, copy, modify, and distribute this
13
**        software and its documentation for any purpose, provided that the above
14
**        copyright notice and the following two paragraphs appear in all copies
15
**        of this software.
16 055d3009 Eric Allman
**
17 6bd5476b Eric Allman
**        IN NO EVENT SHALL REGENTS BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT,
18
**        SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST
19
**        PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION,
20
**        EVEN IF REGENTS HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
21 055d3009 Eric Allman
**
22 6bd5476b Eric Allman
**        REGENTS SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT
23 055d3009 Eric Allman
**        LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24 6bd5476b Eric Allman
**        FOR A PARTICULAR PURPOSE. THE SOFTWARE AND ACCOMPANYING DOCUMENTATION,
25
**        IF ANY, PROVIDED HEREUNDER IS PROVIDED "AS IS". REGENTS HAS NO
26
**        OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS,
27
**        OR MODIFICATIONS.
28 055d3009 Eric Allman
**  ----- END LICENSE BLOCK -----
29 47c6ea64 Eric Allman
***********************************************************************/
30
31
#ifndef _EP_DEBUG_H_
32
#define _EP_DEBUG_H_
33
34 07926cd3 Eric Allman
# include <ep/ep.h>
35 47c6ea64 Eric Allman
# include <stdarg.h>
36
37 e844af35 Eric Allman
__BEGIN_DECLS
38
39 47c6ea64 Eric Allman
/**************************  BEGIN PRIVATE  **************************/
40
41
// if the current generation is greater than that in the flag then some
42
// debug flag has been changed and the whole thing should be re-inited.
43
44
typedef struct EP_DBG        EP_DBG;
45
46
struct EP_DBG
47
{
48
        const char        *name;        // debug flag name
49
        int                level;        // current debug level
50
        const char        *desc;        // description
51
        int                gen;        // flag initialization generation
52
        EP_DBG                *next;        // initted flags, in case values change
53
};
54
55 77a024b0 Eric Allman
extern int        __EpDbgCurGen;                // current generation
56 47c6ea64 Eric Allman
57
/***************************  END PRIVATE  ***************************/
58
59
// macros for use in applications
60 3143b747 Eric Allman
#define ep_dbg_level(f)                ((f).gen == __EpDbgCurGen ?                \
61
                                 (f).level :                                \
62
                                 ep_dbg_flaglevel(&f))
63 47c6ea64 Eric Allman
#define ep_dbg_test(f, l)        (ep_dbg_level(f) >= (l))
64
65
// support functions
66
extern int        ep_dbg_flaglevel(EP_DBG *f);
67
68
// creating a flag
69
#define EP_DBG_INIT(name, desc)                                                \
70 3143b747 Eric Allman
                { name, -1, "@(#)$Debug: " name " = " desc " $", -1, NULL }
71 47c6ea64 Eric Allman
72
// initialization
73
extern void        ep_dbg_init(void);
74
75 3143b747 Eric Allman
// setting/fetching debug output file
76
extern void        ep_dbg_setfile(FILE *fp);
77
extern FILE        *ep_dbg_getfile(void);
78 47c6ea64 Eric Allman
79
// setting debug flags
80
extern void        ep_dbg_set(const char *s);
81
extern void        ep_dbg_setto(const char *pat, int lev);
82
83
// printing debug output (uses stddbg)
84
extern void EP_TYPE_PRINTFLIKE(1, 2)
85
                ep_dbg_printf(const char *fmt, ...);
86 3defe741 Eric Allman
extern void        ep_dbg_vprintf(const char *fmt, va_list av);
87 47c6ea64 Eric Allman
88
// print only if flag set
89 3143b747 Eric Allman
#define ep_dbg_cprintf(f, l, ...)        {if (ep_dbg_test(f, l)) \
90
                                                ep_dbg_printf(__VA_ARGS__);}
91 47c6ea64 Eric Allman
92 a44e9415 Eric Allman
// stack backtrace to debug output
93 4a8ff91d Eric Allman
extern void        ep_dbg_backtrace(FILE *fp);
94 a44e9415 Eric Allman
95 47c6ea64 Eric Allman
// crackarg parsing
96
extern EP_STAT        epCavDebug(const char *vp, void *rp);
97
98 e844af35 Eric Allman
__END_DECLS
99 47c6ea64 Eric Allman
100
#endif /*_EP_DEBUG_H_*/