freebsd-5-update-20030213
[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(TRANSARC_DEBUG_H)
15 #define TRANSARC_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] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
73
74 /*
75  * AFSLOG
76  *
77  * Compare the given debugging level against the setting of the particular
78  * index into the afsdebug char array.  If there are bits in common, or else
79  * if if the level is DEBUG_FORCE_PRINT, then produce debugging output with
80  * the rest of the arguments provided.
81  *
82  * NOTE: This should become a macro!
83  */
84 AFSLOG(index,level,a,b,c,d,e,f,g,h,i,j,k,l,m,n)
85     char index,level,*a,*b,*c,*d,*e,*f,*g,*h,*i,*j,*k,*l,*m,*n;
86 {
87     if ((afsdebug[index] & level) || !level) 
88         osi_dp(a,b,c,d,e,f,g,h,i,j,k,l,m,n);
89 }
90 #else
91 extern char afsdebug[20];
92 #endif /* AFSDEBUG_DECLARE */
93
94 #else /* KERNEL */
95 #define assert(x) \
96 if(!(x)) { fprintf(stderr, "assertion failed: line %d, file %s\n",\
97                    __LINE__,__FILE__); fflush(stderr); abort(); }
98 #endif /* KERNEL */
99
100 #else /* AFS_DEBUG */
101
102 #define assert(x)
103
104 #endif /* AFS_DEBUG */
105
106 /*
107  * Debugging macro package.  The actual variables should be declared in
108  * debug.c
109  */
110
111 #if defined(AFS_DEBUG)
112 #if defined(lint)
113 #define dprintf(flag, str) printf str
114 #define dlprintf(flag, level, str) printf str
115 #define dmprintf(flag, bit, str) printf str
116 #else /* lint */
117 #define dprintf(flag, str) \
118       (void)((flag) ? \
119              ( osi_dp str, osi_dp("\t%s, %d\n", __FILE__, __LINE__)):0)
120 #define dlprintf(flag, level, str) dprintf(((flag) >= (level)), str)
121 #define dmprintf(flag, bit, str) dprintf(((flag)&(1<<((bit)-1))), str)
122
123 #endif /* lint */
124           
125 #else /* AFS_DEBUG */
126
127 #define dprintf(flag, str)
128 #define dlprintf(flag, level,str)
129 #define dmprintf(flag, bit, str)
130
131 #endif /* AFS_DEBUG */
132
133 #endif /* TRANSARC_DEBUG_H */
134