]>
Commit | Line | Data |
---|---|---|
55abb092 BB |
1 | /*****************************************************************************\ |
2 | * Copyright (C) 2007-2010 Lawrence Livermore National Security, LLC. | |
3 | * Copyright (C) 2007 The Regents of the University of California. | |
4 | * Produced at Lawrence Livermore National Laboratory (cf, DISCLAIMER). | |
5 | * Written by Brian Behlendorf <behlendorf1@llnl.gov>. | |
6 | * UCRL-CODE-235197 | |
7 | * | |
8 | * This file is part of the SPL, Solaris Porting Layer. | |
9 | * For details, see <http://github.com/behlendorf/spl/>. | |
10 | * | |
11 | * The SPL is free software; you can redistribute it and/or modify it | |
12 | * under the terms of the GNU General Public License as published by the | |
13 | * Free Software Foundation; either version 2 of the License, or (at your | |
14 | * option) any later version. | |
15 | * | |
16 | * The SPL is distributed in the hope that it will be useful, but WITHOUT | |
17 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
18 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
19 | * for more details. | |
20 | * | |
21 | * You should have received a copy of the GNU General Public License along | |
22 | * with the SPL. If not, see <http://www.gnu.org/licenses/>. | |
23 | \*****************************************************************************/ | |
24 | ||
25 | /* | |
26 | * Available debug functions. These function should be used by any | |
27 | * package which needs to integrate with the SPL log infrastructure. | |
28 | * | |
b17edc10 BB |
29 | * SDEBUG() - Log debug message with specified mask. |
30 | * SDEBUG_LIMIT() - Log just 1 debug message with specified mask. | |
31 | * SWARN() - Log a warning message. | |
32 | * SERROR() - Log an error message. | |
33 | * SEMERG() - Log an emergency error message. | |
34 | * SCONSOLE() - Log a generic message to the console. | |
55abb092 | 35 | * |
b17edc10 BB |
36 | * SENTRY - Log entry point to a function. |
37 | * SEXIT - Log exit point from a function. | |
38 | * SRETURN(x) - Log return from a function. | |
39 | * SGOTO(x, y) - Log goto within a function. | |
55abb092 BB |
40 | */ |
41 | ||
42 | #ifndef _SPL_DEBUG_INTERNAL_H | |
43 | #define _SPL_DEBUG_INTERNAL_H | |
44 | ||
45 | #include <linux/limits.h> | |
46 | ||
b17edc10 BB |
47 | #define SS_UNDEFINED 0x00000001 |
48 | #define SS_ATOMIC 0x00000002 | |
49 | #define SS_KOBJ 0x00000004 | |
50 | #define SS_VNODE 0x00000008 | |
51 | #define SS_TIME 0x00000010 | |
52 | #define SS_RWLOCK 0x00000020 | |
53 | #define SS_THREAD 0x00000040 | |
54 | #define SS_CONDVAR 0x00000080 | |
55 | #define SS_MUTEX 0x00000100 | |
56 | #define SS_RNG 0x00000200 | |
57 | #define SS_TASKQ 0x00000400 | |
58 | #define SS_KMEM 0x00000800 | |
59 | #define SS_DEBUG 0x00001000 | |
60 | #define SS_GENERIC 0x00002000 | |
61 | #define SS_PROC 0x00004000 | |
62 | #define SS_MODULE 0x00008000 | |
63 | #define SS_CRED 0x00010000 | |
64 | #define SS_KSTAT 0x00020000 | |
65 | #define SS_XDR 0x00040000 | |
9fe45dc1 | 66 | #define SS_TSD 0x00080000 |
5c1967eb | 67 | #define SS_ZLIB 0x00100000 |
b17edc10 BB |
68 | #define SS_USER1 0x01000000 |
69 | #define SS_USER2 0x02000000 | |
70 | #define SS_USER3 0x04000000 | |
71 | #define SS_USER4 0x08000000 | |
72 | #define SS_USER5 0x10000000 | |
73 | #define SS_USER6 0x20000000 | |
74 | #define SS_USER7 0x40000000 | |
75 | #define SS_USER8 0x80000000 | |
76 | #define SS_DEBUG_SUBSYS SS_UNDEFINED | |
77 | ||
78 | #define SD_TRACE 0x00000001 | |
79 | #define SD_INFO 0x00000002 | |
80 | #define SD_WARNING 0x00000004 | |
81 | #define SD_ERROR 0x00000008 | |
82 | #define SD_EMERG 0x00000010 | |
83 | #define SD_CONSOLE 0x00000020 | |
84 | #define SD_IOCTL 0x00000040 | |
85 | #define SD_DPRINTF 0x00000080 | |
86 | #define SD_OTHER 0x00000100 | |
87 | #define SD_CANTMASK (SD_ERROR | SD_EMERG | SD_WARNING | SD_CONSOLE) | |
55abb092 BB |
88 | |
89 | #ifdef NDEBUG /* Debugging Disabled */ | |
90 | ||
b17edc10 BB |
91 | #define SDEBUG(mask, fmt, a...) ((void)0) |
92 | #define SDEBUG_LIMIT(x, y, fmt, a...) ((void)0) | |
93 | #define SWARN(fmt, a...) ((void)0) | |
94 | #define SERROR(fmt, a...) ((void)0) | |
95 | #define SEMERG(fmt, a...) ((void)0) | |
96 | #define SCONSOLE(mask, fmt, a...) ((void)0) | |
55abb092 | 97 | |
b17edc10 BB |
98 | #define SENTRY ((void)0) |
99 | #define SEXIT ((void)0) | |
100 | #define SRETURN(x) return (x) | |
101 | #define SGOTO(x, y) { ((void)(y)); goto x; } | |
55abb092 BB |
102 | |
103 | #else /* Debugging Enabled */ | |
104 | ||
b17edc10 | 105 | #define __SDEBUG(cdls, subsys, mask, format, a...) \ |
55abb092 | 106 | do { \ |
b17edc10 | 107 | if (((mask) & SD_CANTMASK) != 0 || \ |
55abb092 BB |
108 | ((spl_debug_mask & (mask)) != 0 && \ |
109 | (spl_debug_subsys & (subsys)) != 0)) \ | |
110 | spl_debug_msg(cdls, subsys, mask, __FILE__, \ | |
111 | __FUNCTION__, __LINE__, format, ## a); \ | |
112 | } while (0) | |
113 | ||
b17edc10 BB |
114 | #define SDEBUG(mask, format, a...) \ |
115 | __SDEBUG(NULL, SS_DEBUG_SUBSYS, mask, format, ## a) | |
55abb092 | 116 | |
b17edc10 | 117 | #define __SDEBUG_LIMIT(subsys, mask, format, a...) \ |
55abb092 BB |
118 | do { \ |
119 | static spl_debug_limit_state_t cdls; \ | |
120 | \ | |
b17edc10 | 121 | __SDEBUG(&cdls, subsys, mask, format, ## a); \ |
55abb092 BB |
122 | } while (0) |
123 | ||
b17edc10 BB |
124 | #define SDEBUG_LIMIT(mask, format, a...) \ |
125 | __SDEBUG_LIMIT(SS_DEBUG_SUBSYS, mask, format, ## a) | |
55abb092 | 126 | |
b17edc10 BB |
127 | #define SWARN(fmt, a...) SDEBUG_LIMIT(SD_WARNING, fmt, ## a) |
128 | #define SERROR(fmt, a...) SDEBUG_LIMIT(SD_ERROR, fmt, ## a) | |
129 | #define SEMERG(fmt, a...) SDEBUG_LIMIT(SD_EMERG, fmt, ## a) | |
130 | #define SCONSOLE(mask, fmt, a...) SDEBUG(SD_CONSOLE | (mask), fmt, ## a) | |
55abb092 | 131 | |
b17edc10 BB |
132 | #define SENTRY SDEBUG(SD_TRACE, "Process entered\n") |
133 | #define SEXIT SDEBUG(SD_TRACE, "Process leaving\n") | |
55abb092 | 134 | |
b17edc10 | 135 | #define SRETURN(rc) \ |
55abb092 BB |
136 | do { \ |
137 | typeof(rc) RETURN__ret = (rc); \ | |
b17edc10 | 138 | SDEBUG(SD_TRACE, "Process leaving (rc=%lu : %ld : %lx)\n", \ |
55abb092 BB |
139 | (long)RETURN__ret, (long)RETURN__ret, (long)RETURN__ret); \ |
140 | return RETURN__ret; \ | |
141 | } while (0) | |
142 | ||
b17edc10 | 143 | #define SGOTO(label, rc) \ |
55abb092 BB |
144 | do { \ |
145 | long GOTO__ret = (long)(rc); \ | |
b17edc10 | 146 | SDEBUG(SD_TRACE,"Process leaving via %s (rc=%lu : %ld : %lx)\n",\ |
55abb092 BB |
147 | #label, (unsigned long)GOTO__ret, (signed long)GOTO__ret, \ |
148 | (signed long)GOTO__ret); \ | |
149 | goto label; \ | |
150 | } while (0) | |
151 | ||
152 | #endif /* NDEBUG */ | |
153 | ||
154 | typedef struct { | |
155 | unsigned long cdls_next; | |
156 | int cdls_count; | |
157 | long cdls_delay; | |
158 | } spl_debug_limit_state_t; | |
159 | ||
160 | /* Global debug variables */ | |
161 | extern unsigned long spl_debug_subsys; | |
162 | extern unsigned long spl_debug_mask; | |
163 | extern unsigned long spl_debug_printk; | |
164 | extern int spl_debug_mb; | |
165 | extern unsigned int spl_debug_binary; | |
166 | extern unsigned int spl_debug_catastrophe; | |
167 | extern unsigned int spl_debug_panic_on_bug; | |
168 | extern char spl_debug_file_path[PATH_MAX]; | |
169 | extern unsigned int spl_console_ratelimit; | |
170 | extern long spl_console_max_delay; | |
171 | extern long spl_console_min_delay; | |
172 | extern unsigned int spl_console_backoff; | |
173 | extern unsigned int spl_debug_stack; | |
174 | ||
175 | /* Exported debug functions */ | |
176 | extern int spl_debug_mask2str(char *str, int size, unsigned long mask, int ss); | |
177 | extern int spl_debug_str2mask(unsigned long *mask, const char *str, int ss); | |
178 | extern unsigned long spl_debug_set_mask(unsigned long mask); | |
179 | extern unsigned long spl_debug_get_mask(void); | |
180 | extern unsigned long spl_debug_set_subsys(unsigned long mask); | |
181 | extern unsigned long spl_debug_get_subsys(void); | |
182 | extern int spl_debug_set_mb(int mb); | |
183 | extern int spl_debug_get_mb(void); | |
184 | extern int spl_debug_dumplog(int flags); | |
185 | extern void spl_debug_dumpstack(struct task_struct *tsk); | |
186 | extern int spl_debug_clear_buffer(void); | |
187 | extern int spl_debug_mark_buffer(char *text); | |
188 | ||
1114ae6a BB |
189 | int spl_debug_init(void); |
190 | void spl_debug_fini(void); | |
55abb092 BB |
191 | |
192 | #endif /* SPL_DEBUG_INTERNAL_H */ |