/
print.h
249 lines (221 loc) · 8.71 KB
/
print.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
/* SPDX-License-Identifier: BSD-3-Clause */
/*
* Debug printing routines
*
* Authors: Simon Kuenzer <simon.kuenzer@neclab.eu>
*
*
* Copyright (c) 2017, NEC Europe Ltd., NEC Corporation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef __UKDEBUG_PRINT_H__
#define __UKDEBUG_PRINT_H__
#include <stdarg.h>
#include <uk/libid.h>
#include <uk/arch/lcpu.h>
#include <uk/essentials.h>
#include <uk/config.h>
#ifdef __cplusplus
extern "C" {
#endif
#ifdef __BASENAME__
#define __STR_BASENAME__ STRINGIFY(__BASENAME__)
#else
#define __STR_BASENAME__ (NULL)
#endif
/*
* DEBUG PRINTING
*/
/* Internal debug print functions that are sometimes used
* by other libraries with an own debug print switch
* (e.g., hexdump, syscall_shim)
*/
void _uk_vprintd(__u16 libid, const char *srcname,
unsigned int srcline, const char *fmt, va_list ap);
void _uk_printd(__u16 libid, const char *srcname,
unsigned int srcline, const char *fmt, ...) __printf(4, 5);
#ifdef __IN_LIBUKDEBUG__
/*
* This redefinition of CONFIG_LIBUKDEBUG_PRINTD is doing the trick to avoid
* multiple declarations of uk_{v}printd() when we are compiling this library
* and have the global debug switch CONFIG_LIBUKDEBUG_PRINTD not enabled.
*/
#if !defined CONFIG_LIBUKDEBUG_PRINTD || !CONFIG_LIBUKDEBUG_PRINTD
#undef CONFIG_LIBUKDEBUG_PRINTD
#define CONFIG_LIBUKDEBUG_PRINTD 1
#endif
#endif /* __IN_LIBUKDEBUG__ */
#if defined UK_DEBUG || CONFIG_LIBUKDEBUG_PRINTD
#define uk_vprintd(fmt, ap) \
do { \
_uk_vprintd(uk_libid_self(), __STR_BASENAME__, \
__LINE__, (fmt), ap); \
} while (0)
#define uk_vprintd_once(fmt, ap) \
do { \
static int __x; \
if (unlikely(!__x)) { \
_uk_vprintd(uk_libid_self(), __STR_BASENAME__, \
__LINE__, (fmt), ap); \
__x = 1; \
} \
} while (0)
#define uk_printd(fmt, ...) \
do { \
_uk_printd(uk_libid_self(), __STR_BASENAME__, \
__LINE__, (fmt), ##__VA_ARGS__); \
} while (0)
#define uk_printd_once(fmt, ...) \
do { \
static int __x; \
if (unlikely(!__x)) { \
_uk_printd(uk_libid_self(), __STR_BASENAME__, \
__LINE__, (fmt), ##__VA_ARGS__); \
__x = 1; \
} \
} while (0)
#else
static inline void uk_vprintd(const char *fmt __unused, va_list ap __unused)
{}
static inline void uk_printd(const char *fmt, ...) __printf(1, 2);
static inline void uk_printd(const char *fmt __unused, ...)
{}
static inline void uk_vprintd_once(const char *fmt __unused,
va_list ap __unused)
{}
static inline void uk_printd_once(const char *fmt, ...) __printf(1, 2);
static inline void uk_printd_once(const char *fmt __unused, ...)
{}
#endif
/*
* KERNEL CONSOLE
*/
#define KLVL_INFO (3)
#define KLVL_WARN (2)
#define KLVL_ERR (1)
#define KLVL_CRIT (0)
#if CONFIG_LIBUKDEBUG_PRINTK_CRIT
#define KLVL_MAX KLVL_CRIT
#elif CONFIG_LIBUKDEBUG_PRINTK_ERR
#define KLVL_MAX KLVL_ERR
#elif CONFIG_LIBUKDEBUG_PRINTK_WARN
#define KLVL_MAX KLVL_WARN
#elif CONFIG_LIBUKDEBUG_PRINTK_INFO
#define KLVL_MAX KLVL_INFO
#else
#define KLVL_MAX KLVL_ERR /* default level */
#endif
#if CONFIG_LIBUKDEBUG_PRINTK
/* please use the uk_printd(), uk_vprintd() macros because
* they compile in the function calls only if the configured
* debug level requires it
*/
void _uk_vprintk(int lvl, __u16 libid, const char *srcname,
unsigned int srcline, const char *fmt, va_list ap);
void _uk_printk(int lvl, __u16 libid, const char *srcname,
unsigned int srcline, const char *fmt, ...) __printf(5, 6);
#define uk_vprintk(lvl, fmt, ap) \
do { \
if ((lvl) <= KLVL_MAX) \
_uk_vprintk((lvl), uk_libid_self(), __STR_BASENAME__, \
__LINE__, (fmt), ap); \
} while (0)
#define uk_vprintk_once(lvl, fmt, ap) \
do { \
if ((lvl) <= KLVL_MAX) { \
static int __x; \
if (unlikely(!__x)) { \
_uk_vprintk((lvl), uk_libid_self(), \
__STR_BASENAME__, \
__LINE__, (fmt), ap); \
__x = 1; \
} \
} \
} while (0)
#define uk_printk(lvl, fmt, ...) \
do { \
if ((lvl) <= KLVL_MAX) \
_uk_printk((lvl), uk_libid_self(), __STR_BASENAME__, \
__LINE__, (fmt), ##__VA_ARGS__); \
} while (0)
#define uk_printk_once(lvl, fmt, ...) \
do { \
if ((lvl) <= KLVL_MAX) { \
static int __x; \
if (unlikely(!__x)) { \
_uk_printk((lvl), uk_libid_self(), \
__STR_BASENAME__, \
__LINE__, (fmt), ##__VA_ARGS__); \
__x = 1; \
} \
} \
} while (0)
#else
static inline void uk_vprintk(int lvl __unused, const char *fmt __unused,
va_list ap __unused)
{}
static inline void uk_printk(int lvl, const char *fmt, ...) __printf(2, 3);
static inline void uk_printk(int lvl __unused, const char *fmt __unused, ...)
{}
static inline void uk_vprintk_once(int lvl __unused, const char *fmt __unused,
va_list ap __unused)
{}
static inline void uk_printk_once(int lvl, const char *fmt, ...) __printf(2, 3);
static inline void uk_printk_once(int lvl __unused,
const char *fmt __unused, ...)
{}
#endif /* CONFIG_LIBUKDEBUG_PRINTK */
/*
* Convenience wrapper for uk_printk() and uk_printd()
* This is similar to the pr_* variants that you find in the Linux kernel
*/
#define uk_pr_debug(fmt, ...) uk_printd((fmt), ##__VA_ARGS__)
#define uk_pr_debug_once(fmt, ...) uk_printd_once((fmt), ##__VA_ARGS__)
#define uk_pr_info(fmt, ...) uk_printk(KLVL_INFO, (fmt), ##__VA_ARGS__)
#define uk_pr_info_once(fmt, ...) uk_printk_once(KLVL_INFO, (fmt), \
##__VA_ARGS__)
#define uk_pr_warn(fmt, ...) uk_printk(KLVL_WARN, (fmt), ##__VA_ARGS__)
#define uk_pr_warn_once(fmt, ...) uk_printk_once(KLVL_WARN, (fmt), \
##__VA_ARGS__)
#define uk_pr_err(fmt, ...) uk_printk(KLVL_ERR, (fmt), ##__VA_ARGS__)
#define uk_pr_err_once(fmt, ...) uk_printk_once(KLVL_ERR, (fmt), \
##__VA_ARGS__)
#define uk_pr_crit(fmt, ...) uk_printk(KLVL_CRIT, (fmt), ##__VA_ARGS__)
#define uk_pr_crit_once(fmt, ...) uk_printk_once(KLVL_CRIT, (fmt), \
##__VA_ARGS__)
/* Warning for stubbed functions */
#define UK_WARN_STUBBED() \
uk_pr_warn_once("%s() stubbed\n", __func__)
/* DEPRECATED: Please use UK_WARN_STUBBED instead */
#ifndef WARN_STUBBED
#define WARN_STUBBED() \
UK_WARN_STUBBED()
#endif
#ifdef __cplusplus
}
#endif
#endif /* __UKDEBUG_PRINT_H__ */