Add libroken as its own library
[openafs.git] / src / config / debug.h
1 /*
2  * Copyright 2000, International Business Machines Corporation and others.
3  * All Rights Reserved.
4  *
5  * This software has been released under the terms of the IBM Public
6  * License.  For details, see the LICENSE file in the top-level source
7  * directory or online at http://www.openafs.org/dl/license10.html
8  */
9
10 /*
11  * All Rights Reserved
12  */
13
14 #if !defined(OPENAFS_DEBUG_H)
15 #define OPENAFS_DEBUG_H
16
17 /*
18  * Define debugging levels, from 1 being lowest priority and 7 being
19  * highest priority.  DEBUG_LEVEL_0 and DEBUG_FORCE_PRINT mean to
20  * print the message regardless of the current setting.
21  */
22 #define DEBUG_LEVEL_0           0
23 #define DEBUG_LEVEL_1           01
24 #define DEBUG_LEVEL_2           03
25 #define DEBUG_LEVEL_3           07
26 #define DEBUG_LEVEL_4           017
27 #define DEBUG_LEVEL_5           037
28 #define DEBUG_LEVEL_6           077
29 #define DEBUG_LEVEL_7           0177
30
31 #define DEBUG_FORCE_PRINT       DEBUG_LEVEL_0
32
33 #if defined(AFS_DEBUG)
34
35 /*
36  * Assert macro
37  *
38  * In kernel, panic.
39  * In user space call abort();
40  */
41
42 #if defined(KERNEL)
43 #define assert(x) \
44 if(!(x)) { printf("assertion failed: line %d, file %s\n",\
45                   __LINE__,__FILE__); osi_Panic("assert"); }
46
47 /*
48  * Debug modules
49  */
50 #define CM_DEBUG        0       /* Cache Manager */
51 #define EX_DEBUG        1       /* Protocol Exporter */
52 #define HS_DEBUG        2       /* Host Module */
53 #define VL_DEBUG        3       /* Volume Module */
54
55 #define AG_DEBUG        4       /* Aggregate Module */
56 #define VR_DEBUG        5       /* Volume Registry Module */
57 #define RX_DEBUG        6       /* RPC/Rx Module */
58 #define XVFS_DEBUG      7       /* Xvnode Module */
59
60 #define NFSTR_DEBUG     8       /* NFS/AFS Translator Module */
61 #define XCRED_DEBUG     9       /* Extended Credential Module */
62 #define FP_DEBUG        10      /* Free Pool Module */
63 #define ACL_DEBUG       11      /* ACL Module */
64 #define FSHS_DEBUG      12      /* File server host module */
65
66 #define MAXMODS_DEBUG   20
67
68 #ifdef  AFSDEBUG_DECLARE
69 /*
70  *  Should get here only once per kernel instance!
71  */
72 char afsdebug[MAXMODS_DEBUG] =
73     { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
74
75 /*
76  * AFSLOG
77  *
78  * Compare the given debugging level against the setting of the particular
79  * index into the afsdebug char array.  If there are bits in common, or else
80  * if if the level is DEBUG_FORCE_PRINT, then produce debugging output with
81  * the rest of the arguments provided.
82  *
83  * NOTE: This should become a macro!
84  */
85 AFSLOG(index, level, a, b, c, d, e, f, g, h, i, j, k, l, m, n)
86      char index, level, *a, *b, *c, *d, *e, *f, *g, *h, *i, *j, *k, *l, *m,
87          *n;
88 {
89     if ((afsdebug[index] & level) || !level)
90         osi_dp(a, b, c, d, e, f, g, h, i, j, k, l, m, n);
91 }
92 #else
93 extern char afsdebug[20];
94 #endif /* AFSDEBUG_DECLARE */
95
96 #else /* KERNEL */
97 #define assert(x) \
98 if(!(x)) { fprintf(stderr, "assertion failed: line %d, file %s\n",\
99                    __LINE__,__FILE__); fflush(stderr); abort(); }
100 #endif /* KERNEL */
101
102 #else /* AFS_DEBUG */
103
104 #define assert(x)
105
106 #endif /* AFS_DEBUG */
107
108 /*
109  * Debugging macro package.  The actual variables should be declared in
110  * debug.c
111  */
112
113 #if defined(AFS_DEBUG)
114 #if defined(lint)
115 #define afs_dprintf(flag, str) printf str
116 #define dlprintf(flag, level, str) printf str
117 #define dmprintf(flag, bit, str) printf str
118 #else /* lint */
119 #define afs_dprintf(flag, str) \
120       (void)((flag) ? \
121              ( osi_dp str, osi_dp("\t%s, %d\n", __FILE__, __LINE__)):0)
122 #define dlprintf(flag, level, str) afs_dprintf(((flag) >= (level)), str)
123 #define dmprintf(flag, bit, str) afs_dprintf(((flag)&(1<<((bit)-1))), str)
124
125 #endif /* lint */
126
127 #else /* AFS_DEBUG */
128
129 #define afs_dprintf(flag, str)
130 #define dlprintf(flag, level,str)
131 #define dmprintf(flag, bit, str)
132
133 #endif /* AFS_DEBUG */
134
135 #endif /* OPENAFS_DEBUG_H */