-
Notifications
You must be signed in to change notification settings - Fork 2
/
pretty_printk.h
138 lines (123 loc) · 4.2 KB
/
pretty_printk.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
/*
* pretty-printk::Macro collection
* <https://github.com/tpiekarski/pretty-printk>
* ---
* Copyright 2020 Thomas Piekarski <[email protected]>
*
* This file is part of pretty-printk - a pretty way to print to
* the Linux Kernel Ring Buffer
*
* pretty-printk is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* pretty-printk is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with pretty-printk. If not, see <https://www.gnu.org/licenses/>.
*
*/
#ifndef _LINUX_PRETTY_PRINTK_H
#define _LINUX_PRETTY_PRINTK_H
#include <linux/kern_levels.h>
#include <linux/printk.h>
void pp_dump(char *types, ...);
#undef _pp
#undef pp_emerg
#undef pp_alert
#undef pp_crit
#undef pp_err
#undef pp_warn
#undef pp_note
#undef pp_info
#define _pp(severity, format, args...) \
printk(severity "%s: " format "\n", THIS_MODULE->name, ##args)
#define pp_emerg(args...) _pp(KERN_EMERG, args)
#define pp_alert(args...) _pp(KERN_ALERT, args)
#define pp_crit(args...) _pp(KERN_CRIT, args)
#define pp_err(args...) _pp(KERN_ERR, args)
#define pp_warn(args...) _pp(KERN_WARNING, args)
#define pp_note(args...) _pp(KERN_NOTICE, args)
#define pp_info(args...) _pp(KERN_INFO, args)
#undef pp_debug
#undef pp_walker
#undef pp_true
#undef pp_false
#ifdef PP_DEBUG
#undef __FILENAME__
#undef _pp_debug
#undef _pp_condition
#define __FILENAME__ \
(strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILE__)
#define _pp_debug(format, args...) \
printk(KERN_DEBUG "%s (%s @ %s, %i): " format "\n", THIS_MODULE->name, \
__FUNCTION__, __FILENAME__, __LINE__, ##args)
#define _pp_condition(condition, result) \
printk(KERN_DEBUG "%s (%s @ %s, %i): %s is %s\n", THIS_MODULE->name, \
__FUNCTION__, __FILENAME__, __LINE__, condition, result)
#define pp_debug(args...) _pp_debug(args)
#define pp_walker() _pp_debug("It worked up to this line")
#define pp_true(condition) _pp_condition(condition, "true")
#define pp_false(condition) _pp_condition(condition, "false")
#else
#define pp_debug(...) // no debug output
#define pp_walker() // not walking code
#define pp_true(...) // no debug output
#define pp_false(...) // no debug output
#endif
#undef pp_black
#undef pp_blue_light
#undef pp_blue
#undef pp_cyan_light
#undef pp_cyan
#undef pp_gray_light
#undef pp_gray
#undef pp_green_light
#undef pp_green
#undef pp_magenta_light
#undef pp_magenta
#undef pp_red_light
#undef pp_red
#undef pp_white
#undef pp_yellow_light
#undef pp_yellow
#ifdef PP_COLORS
#define pp_black(arg) "\e[30m" arg "\e[0m"
#define pp_blue_light(arg) "\e[94m" arg "\e[0m"
#define pp_blue(arg) "\e[34m" arg "\e[0m"
#define pp_cyan_light(arg) "\e[96m" arg "\e[0m"
#define pp_cyan(arg) "\e[36m" arg "\e[0m"
#define pp_gray_light(arg) "\e[37m" arg "\e[0m"
#define pp_gray(arg) "\e[90m" arg "\e[0m"
#define pp_green_light(arg) "\e[92m" arg "\e[0m"
#define pp_green(arg) "\e[32m" arg "\e[0m"
#define pp_magenta_light(arg) "\e[95m" arg "\e[0m"
#define pp_magenta(arg) "\e[35m" arg "\e[0m"
#define pp_red_light(arg) "\e[91m" arg "\e[0m"
#define pp_red(arg) "\e[31m" arg "\e[0m"
#define pp_white(arg) "\e[97m" arg "\e[0m"
#define pp_yellow_light(arg) "\e[93m" arg "\e[0m"
#define pp_yellow(arg) "\e[33m" arg "\e[0m"
#else
#define pp_black(arg) arg
#define pp_blue_light(arg) arg
#define pp_blue(arg) arg
#define pp_cyan_light(arg) arg
#define pp_cyan(arg) arg
#define pp_gray_light(arg) arg
#define pp_gray(arg) arg
#define pp_green_light(arg) arg
#define pp_green(arg) arg
#define pp_magenta_light(arg) arg
#define pp_magenta(arg) arg
#define pp_red_light(arg) arg
#define pp_red(arg) arg
#define pp_white(arg) arg
#define pp_yellow_light(arg) arg
#define pp_yellow(arg) arg
#endif
#endif