Print this page
Test of DTrace assert probes
| Split |
Close |
| Expand all |
| Collapse all |
--- old/usr/src/uts/common/sys/debug.h
+++ new/usr/src/uts/common/sys/debug.h
1 1 /*
2 2 * CDDL HEADER START
3 3 *
4 4 * The contents of this file are subject to the terms of the
5 5 * Common Development and Distribution License (the "License").
6 6 * You may not use this file except in compliance with the License.
7 7 *
8 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 9 * or http://www.opensolaris.org/os/licensing.
10 10 * See the License for the specific language governing permissions
11 11 * and limitations under the License.
12 12 *
13 13 * When distributing Covered Code, include this CDDL HEADER in each
14 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 15 * If applicable, add the following below this CDDL HEADER, with the
16 16 * fields enclosed by brackets "[]" replaced with your own identifying
17 17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 18 *
19 19 * CDDL HEADER END
20 20 */
21 21 /*
22 22 * Copyright 2014 Garrett D'Amore <garrett@damore.org>
23 23 *
24 24 * Copyright 2010 Sun Microsystems, Inc. All rights reserved.
25 25 * Use is subject to license terms.
26 26 */
27 27
28 28 /*
29 29 * Copyright (c) 2012 by Delphix. All rights reserved.
30 30 * Copyright 2013 Saso Kiselkov. All rights reserved.
31 31 */
32 32
|
↓ open down ↓ |
32 lines elided |
↑ open up ↑ |
33 33 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
34 34 /* All Rights Reserved */
35 35
36 36 #ifndef _SYS_DEBUG_H
37 37 #define _SYS_DEBUG_H
38 38
39 39 #include <sys/isa_defs.h>
40 40 #include <sys/types.h>
41 41 #include <sys/note.h>
42 42
43 +#ifdef KEBE
44 +#include <sys/sdt.h>
45 +#endif /* KEBE */
46 +
43 47 #ifdef __cplusplus
44 48 extern "C" {
45 49 #endif
46 50
47 51 /*
48 52 * ASSERT(ex) causes a panic or debugger entry if expression ex is not
49 53 * true. ASSERT() is included only for debugging, and is a no-op in
50 54 * production kernels. VERIFY(ex), on the other hand, behaves like
51 55 * ASSERT and is evaluated on both debug and non-debug kernels.
56 + *
57 + * KEBE SAYS if "KEBE" is defined on a non-DEBUG kernel, the ASSERT() will
58 + * form an SDT probe of the form sdt:module:function:assert-<lineno>, with
59 + * probe arguments:
60 + *
61 + * arg0 -> file name
62 + * arg1 -> line number
63 + * arg2 -> EX
52 64 */
53 65
66 +#ifdef KEBE
67 +/* XXX KEBE HOPES that __LINE__ evaluates the same, but isn't sure. */
68 +#define ASSERTDTSTRBASE(x, y) x ## y
69 +#define ASSERTDTSTR(x, y) ASSERTDTSTRBASE(x, y)
70 +#define ASSERTDT(EX) do { \
71 + extern void ASSERTDTSTR(__dtrace_probe_assert__, __LINE__)(uintptr_t, \
72 + uintptr_t, uintptr_t); \
73 + if (!(EX)) \
74 + ASSERTDTSTR(__dtrace_probe_assert__, __LINE__) \
75 + ((uintptr_t)__FILE__, \
76 + (uintptr_t)__LINE__, (uintptr_t)#EX); \
77 +_NOTE(CONSTCOND) } while (0)
78 +#endif /* KEBE */
79 +
80 +
54 81 extern int assfail(const char *, const char *, int);
55 82 #define VERIFY(EX) ((void)((EX) || assfail(#EX, __FILE__, __LINE__)))
56 83 #if DEBUG
57 84 #define ASSERT(EX) ((void)((EX) || assfail(#EX, __FILE__, __LINE__)))
58 85 #else
86 +#ifdef KEBE
87 +#define ASSERT(EX) ASSERTDT(EX)
88 +#else
59 89 #define ASSERT(x) ((void)0)
60 -#endif
90 +#endif /* KEBE */
91 +#endif /* DEBUG */
61 92
62 93 /*
63 94 * Assertion variants sensitive to the compilation data model
64 95 */
65 96 #if defined(_LP64)
66 97 #define ASSERT64(x) ASSERT(x)
67 98 #define ASSERT32(x)
68 99 #else
69 100 #define ASSERT64(x)
70 101 #define ASSERT32(x) ASSERT(x)
71 102 #endif
72 103
73 104 /*
74 105 * IMPLY and EQUIV are assertions of the form:
75 106 *
76 107 * if (a) then (b)
77 108 * and
78 109 * if (a) then (b) *AND* if (b) then (a)
79 110 */
80 111 #if DEBUG
81 112 #define IMPLY(A, B) \
82 113 ((void)(((!(A)) || (B)) || \
83 114 assfail("(" #A ") implies (" #B ")", __FILE__, __LINE__)))
84 115 #define EQUIV(A, B) \
85 116 ((void)((!!(A) == !!(B)) || \
86 117 assfail("(" #A ") is equivalent to (" #B ")", __FILE__, __LINE__)))
87 118 #else
88 119 #define IMPLY(A, B) ((void)0)
89 120 #define EQUIV(A, B) ((void)0)
90 121 #endif
91 122
|
↓ open down ↓ |
21 lines elided |
↑ open up ↑ |
92 123 /*
93 124 * ASSERT3() behaves like ASSERT() except that it is an explicit conditional,
94 125 * and prints out the values of the left and right hand expressions as part of
95 126 * the panic message to ease debugging. The three variants imply the type
96 127 * of their arguments. ASSERT3S() is for signed data types, ASSERT3U() is
97 128 * for unsigned, and ASSERT3P() is for pointers. The VERIFY3*() macros
98 129 * have the same relationship as above.
99 130 */
100 131 extern void assfail3(const char *, uintmax_t, const char *, uintmax_t,
101 132 const char *, int);
133 +
134 +#ifdef KEBE
135 +/*
136 + * KEBE SAYS, for the sdt:module:function:assert3-<lineno> will have more
137 + * probe arguments:
138 + *
139 + * arg0 -> file name
140 + * arg1 -> line number
141 + * arg2 -> EX
142 + * arg3 -> "left" boolean
143 + * arg4 -> "OP" string
144 + * arg5 -> "right" boolean
145 + */
146 +#define KEBE3_IMPL(LEFT, OP, RIGHT, TYPE) do { \
147 + extern void ASSERTDTSTR(__dtrace_probe_assert3__, __LINE__)( \
148 + uintptr_t, uintptr_t, uintptr_t, uintptr_t, uintptr_t, \
149 + uintptr_t); \
150 + const TYPE __left = (TYPE)(LEFT); \
151 + const TYPE __right = (TYPE)(RIGHT); \
152 + if (!(__left OP __right)) \
153 + ASSERTDTSTR(__dtrace_probe_assert3__, __LINE__) \
154 + ((uintptr_t)__FILE__, \
155 + (uintptr_t)__LINE__, \
156 + (uintptr_t)(#LEFT " " #OP " " #RIGHT), \
157 + (uintptr_t)__left, (uintptr_t)#OP, \
158 + (uintptr_t)__right); \
159 +_NOTE(CONSTCOND) } while (0)
160 +#endif /* KEBE */
161 +
102 162 #define VERIFY3_IMPL(LEFT, OP, RIGHT, TYPE) do { \
103 163 const TYPE __left = (TYPE)(LEFT); \
104 164 const TYPE __right = (TYPE)(RIGHT); \
105 165 if (!(__left OP __right)) \
106 166 assfail3(#LEFT " " #OP " " #RIGHT, \
107 167 (uintmax_t)__left, #OP, (uintmax_t)__right, \
108 168 __FILE__, __LINE__); \
109 169 _NOTE(CONSTCOND) } while (0)
110 170
111 171 #define VERIFY3S(x, y, z) VERIFY3_IMPL(x, y, z, int64_t)
112 172 #define VERIFY3U(x, y, z) VERIFY3_IMPL(x, y, z, uint64_t)
113 173 #define VERIFY3P(x, y, z) VERIFY3_IMPL(x, y, z, uintptr_t)
114 174 #define VERIFY0(x) VERIFY3_IMPL(x, ==, 0, uintmax_t)
115 175
116 176 #if DEBUG
117 177 #define ASSERT3S(x, y, z) VERIFY3_IMPL(x, y, z, int64_t)
118 178 #define ASSERT3U(x, y, z) VERIFY3_IMPL(x, y, z, uint64_t)
119 179 #define ASSERT3P(x, y, z) VERIFY3_IMPL(x, y, z, uintptr_t)
120 180 #define ASSERT0(x) VERIFY3_IMPL(x, ==, 0, uintmax_t)
121 181 #else
182 +#ifdef KEBE
183 +#define ASSERT3S(x, y, z) KEBE3_IMPL(x, y, z, int64_t)
184 +#define ASSERT3U(x, y, z) KEBE3_IMPL(x, y, z, uint64_t)
185 +#define ASSERT3P(x, y, z) KEBE3_IMPL(x, y, z, uintptr_t)
186 +#define ASSERT0(x) KEBE3_IMPL(x, ==, 0, uintmax_t)
187 +#else
122 188 #define ASSERT3S(x, y, z) ((void)0)
123 189 #define ASSERT3U(x, y, z) ((void)0)
124 190 #define ASSERT3P(x, y, z) ((void)0)
125 191 #define ASSERT0(x) ((void)0)
192 +#endif /* KEBE */
126 193 #endif
127 194
128 195 /*
129 196 * Compile-time assertion. The condition 'x' must be constant.
130 197 */
131 198 #define CTASSERT(x) _CTASSERT(x, __LINE__)
132 199 #define _CTASSERT(x, y) __CTASSERT(x, y)
133 200 #define __CTASSERT(x, y) \
134 201 typedef char __compile_time_assertion__ ## y [(x) ? 1 : -1]
135 202
136 203 #ifdef _KERNEL
137 204
138 205 extern void abort_sequence_enter(char *);
139 206 extern void debug_enter(char *);
140 207
141 208 #endif /* _KERNEL */
142 209
143 210 #if defined(DEBUG) && !defined(__sun)
144 211 /* CSTYLED */
145 212 #define STATIC
146 213 #else
147 214 /* CSTYLED */
148 215 #define STATIC static
149 216 #endif
150 217
151 218 #ifdef __cplusplus
152 219 }
153 220 #endif
154 221
155 222 #endif /* _SYS_DEBUG_H */
|
↓ open down ↓ |
20 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX