gdp / ep / ep_dbg.h @ master
History | View | Annotate | Download (3.2 KB)
1 |
/* vim: set ai sw=8 sts=8 ts=8 :*/
|
---|---|
2 |
|
3 |
/***********************************************************************
|
4 |
** ----- BEGIN LICENSE BLOCK -----
|
5 |
** LIBEP: Enhanced Portability Library (Reduced Edition)
|
6 |
**
|
7 |
** Copyright (c) 2008-2019, Eric P. Allman. All rights reserved.
|
8 |
** Copyright (c) 2015-2019, Regents of the University of California.
|
9 |
** All rights reserved.
|
10 |
**
|
11 |
** 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 |
**
|
17 |
** 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 |
**
|
22 |
** REGENTS SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT
|
23 |
** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
24 |
** 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 |
** ----- END LICENSE BLOCK -----
|
29 |
***********************************************************************/
|
30 |
|
31 |
#ifndef _EP_DEBUG_H_
|
32 |
#define _EP_DEBUG_H_
|
33 |
|
34 |
# include <ep/ep.h> |
35 |
# include <stdarg.h> |
36 |
|
37 |
__BEGIN_DECLS |
38 |
|
39 |
/************************** 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 |
extern int __EpDbgCurGen; // current generation |
56 |
|
57 |
/*************************** END PRIVATE ***************************/
|
58 |
|
59 |
// macros for use in applications
|
60 |
#define ep_dbg_level(f) ((f).gen == __EpDbgCurGen ? \
|
61 |
(f).level : \ |
62 |
ep_dbg_flaglevel(&f)) |
63 |
#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 |
{ name, -1, "@(#)$Debug: " name " = " desc " $", -1, NULL } |
71 |
|
72 |
// initialization
|
73 |
extern void ep_dbg_init(void); |
74 |
|
75 |
// setting/fetching debug output file
|
76 |
extern void ep_dbg_setfile(FILE *fp); |
77 |
extern FILE *ep_dbg_getfile(void); |
78 |
|
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 |
extern void ep_dbg_vprintf(const char *fmt, va_list av); |
87 |
|
88 |
// print only if flag set
|
89 |
#define ep_dbg_cprintf(f, l, ...) {if (ep_dbg_test(f, l)) \ |
90 |
ep_dbg_printf(__VA_ARGS__);} |
91 |
|
92 |
// stack backtrace to debug output
|
93 |
extern void ep_dbg_backtrace(FILE *fp); |
94 |
|
95 |
// crackarg parsing
|
96 |
extern EP_STAT epCavDebug(const char *vp, void *rp); |
97 |
|
98 |
__END_DECLS |
99 |
|
100 |
#endif /*_EP_DEBUG_H_*/ |