| .. | .. |
|---|
| 47 | 47 | } __attribute__((aligned(8))); |
|---|
| 48 | 48 | |
|---|
| 49 | 49 | |
|---|
| 50 | + |
|---|
| 51 | +#if defined(CONFIG_DYNAMIC_DEBUG_CORE) |
|---|
| 52 | + |
|---|
| 50 | 53 | int ddebug_add_module(struct _ddebug *tab, unsigned int n, |
|---|
| 51 | 54 | const char *modname); |
|---|
| 52 | | - |
|---|
| 53 | | -#if defined(CONFIG_DYNAMIC_DEBUG) |
|---|
| 54 | 55 | extern int ddebug_remove_module(const char *mod_name); |
|---|
| 55 | 56 | extern __printf(2, 3) |
|---|
| 56 | 57 | void __dynamic_pr_debug(struct _ddebug *descriptor, const char *fmt, ...); |
|---|
| .. | .. |
|---|
| 71 | 72 | const struct net_device *dev, |
|---|
| 72 | 73 | const char *fmt, ...); |
|---|
| 73 | 74 | |
|---|
| 74 | | -#define DEFINE_DYNAMIC_DEBUG_METADATA_KEY(name, fmt, key, init) \ |
|---|
| 75 | +struct ib_device; |
|---|
| 76 | + |
|---|
| 77 | +extern __printf(3, 4) |
|---|
| 78 | +void __dynamic_ibdev_dbg(struct _ddebug *descriptor, |
|---|
| 79 | + const struct ib_device *ibdev, |
|---|
| 80 | + const char *fmt, ...); |
|---|
| 81 | + |
|---|
| 82 | +#define DEFINE_DYNAMIC_DEBUG_METADATA(name, fmt) \ |
|---|
| 75 | 83 | static struct _ddebug __aligned(8) \ |
|---|
| 76 | | - __attribute__((section("__verbose"))) name = { \ |
|---|
| 84 | + __section("__dyndbg") name = { \ |
|---|
| 77 | 85 | .modname = KBUILD_MODNAME, \ |
|---|
| 78 | 86 | .function = __func__, \ |
|---|
| 79 | 87 | .filename = __FILE__, \ |
|---|
| 80 | 88 | .format = (fmt), \ |
|---|
| 81 | 89 | .lineno = __LINE__, \ |
|---|
| 82 | 90 | .flags = _DPRINTK_FLAGS_DEFAULT, \ |
|---|
| 83 | | - dd_key_init(key, init) \ |
|---|
| 91 | + _DPRINTK_KEY_INIT \ |
|---|
| 84 | 92 | } |
|---|
| 85 | 93 | |
|---|
| 86 | 94 | #ifdef CONFIG_JUMP_LABEL |
|---|
| 87 | 95 | |
|---|
| 88 | | -#define dd_key_init(key, init) key = (init) |
|---|
| 89 | | - |
|---|
| 90 | 96 | #ifdef DEBUG |
|---|
| 91 | | -#define DEFINE_DYNAMIC_DEBUG_METADATA(name, fmt) \ |
|---|
| 92 | | - DEFINE_DYNAMIC_DEBUG_METADATA_KEY(name, fmt, .key.dd_key_true, \ |
|---|
| 93 | | - (STATIC_KEY_TRUE_INIT)) |
|---|
| 97 | + |
|---|
| 98 | +#define _DPRINTK_KEY_INIT .key.dd_key_true = (STATIC_KEY_TRUE_INIT) |
|---|
| 94 | 99 | |
|---|
| 95 | 100 | #define DYNAMIC_DEBUG_BRANCH(descriptor) \ |
|---|
| 96 | 101 | static_branch_likely(&descriptor.key.dd_key_true) |
|---|
| 97 | 102 | #else |
|---|
| 98 | | -#define DEFINE_DYNAMIC_DEBUG_METADATA(name, fmt) \ |
|---|
| 99 | | - DEFINE_DYNAMIC_DEBUG_METADATA_KEY(name, fmt, .key.dd_key_false, \ |
|---|
| 100 | | - (STATIC_KEY_FALSE_INIT)) |
|---|
| 103 | +#define _DPRINTK_KEY_INIT .key.dd_key_false = (STATIC_KEY_FALSE_INIT) |
|---|
| 101 | 104 | |
|---|
| 102 | 105 | #define DYNAMIC_DEBUG_BRANCH(descriptor) \ |
|---|
| 103 | 106 | static_branch_unlikely(&descriptor.key.dd_key_false) |
|---|
| 104 | 107 | #endif |
|---|
| 105 | 108 | |
|---|
| 106 | | -#else |
|---|
| 109 | +#else /* !CONFIG_JUMP_LABEL */ |
|---|
| 107 | 110 | |
|---|
| 108 | | -#define dd_key_init(key, init) |
|---|
| 109 | | - |
|---|
| 110 | | -#define DEFINE_DYNAMIC_DEBUG_METADATA(name, fmt) \ |
|---|
| 111 | | - DEFINE_DYNAMIC_DEBUG_METADATA_KEY(name, fmt, 0, 0) |
|---|
| 111 | +#define _DPRINTK_KEY_INIT |
|---|
| 112 | 112 | |
|---|
| 113 | 113 | #ifdef DEBUG |
|---|
| 114 | 114 | #define DYNAMIC_DEBUG_BRANCH(descriptor) \ |
|---|
| .. | .. |
|---|
| 118 | 118 | unlikely(descriptor.flags & _DPRINTK_FLAGS_PRINT) |
|---|
| 119 | 119 | #endif |
|---|
| 120 | 120 | |
|---|
| 121 | | -#endif |
|---|
| 121 | +#endif /* CONFIG_JUMP_LABEL */ |
|---|
| 122 | + |
|---|
| 123 | +#define __dynamic_func_call(id, fmt, func, ...) do { \ |
|---|
| 124 | + DEFINE_DYNAMIC_DEBUG_METADATA(id, fmt); \ |
|---|
| 125 | + if (DYNAMIC_DEBUG_BRANCH(id)) \ |
|---|
| 126 | + func(&id, ##__VA_ARGS__); \ |
|---|
| 127 | +} while (0) |
|---|
| 128 | + |
|---|
| 129 | +#define __dynamic_func_call_no_desc(id, fmt, func, ...) do { \ |
|---|
| 130 | + DEFINE_DYNAMIC_DEBUG_METADATA(id, fmt); \ |
|---|
| 131 | + if (DYNAMIC_DEBUG_BRANCH(id)) \ |
|---|
| 132 | + func(__VA_ARGS__); \ |
|---|
| 133 | +} while (0) |
|---|
| 134 | + |
|---|
| 135 | +/* |
|---|
| 136 | + * "Factory macro" for generating a call to func, guarded by a |
|---|
| 137 | + * DYNAMIC_DEBUG_BRANCH. The dynamic debug descriptor will be |
|---|
| 138 | + * initialized using the fmt argument. The function will be called with |
|---|
| 139 | + * the address of the descriptor as first argument, followed by all |
|---|
| 140 | + * the varargs. Note that fmt is repeated in invocations of this |
|---|
| 141 | + * macro. |
|---|
| 142 | + */ |
|---|
| 143 | +#define _dynamic_func_call(fmt, func, ...) \ |
|---|
| 144 | + __dynamic_func_call(__UNIQUE_ID(ddebug), fmt, func, ##__VA_ARGS__) |
|---|
| 145 | +/* |
|---|
| 146 | + * A variant that does the same, except that the descriptor is not |
|---|
| 147 | + * passed as the first argument to the function; it is only called |
|---|
| 148 | + * with precisely the macro's varargs. |
|---|
| 149 | + */ |
|---|
| 150 | +#define _dynamic_func_call_no_desc(fmt, func, ...) \ |
|---|
| 151 | + __dynamic_func_call_no_desc(__UNIQUE_ID(ddebug), fmt, func, ##__VA_ARGS__) |
|---|
| 122 | 152 | |
|---|
| 123 | 153 | #define dynamic_pr_debug(fmt, ...) \ |
|---|
| 124 | | -do { \ |
|---|
| 125 | | - DEFINE_DYNAMIC_DEBUG_METADATA(descriptor, fmt); \ |
|---|
| 126 | | - if (DYNAMIC_DEBUG_BRANCH(descriptor)) \ |
|---|
| 127 | | - __dynamic_pr_debug(&descriptor, pr_fmt(fmt), \ |
|---|
| 128 | | - ##__VA_ARGS__); \ |
|---|
| 129 | | -} while (0) |
|---|
| 154 | + _dynamic_func_call(fmt, __dynamic_pr_debug, \ |
|---|
| 155 | + pr_fmt(fmt), ##__VA_ARGS__) |
|---|
| 130 | 156 | |
|---|
| 131 | 157 | #define dynamic_dev_dbg(dev, fmt, ...) \ |
|---|
| 132 | | -do { \ |
|---|
| 133 | | - DEFINE_DYNAMIC_DEBUG_METADATA(descriptor, fmt); \ |
|---|
| 134 | | - if (DYNAMIC_DEBUG_BRANCH(descriptor)) \ |
|---|
| 135 | | - __dynamic_dev_dbg(&descriptor, dev, fmt, \ |
|---|
| 136 | | - ##__VA_ARGS__); \ |
|---|
| 137 | | -} while (0) |
|---|
| 158 | + _dynamic_func_call(fmt,__dynamic_dev_dbg, \ |
|---|
| 159 | + dev, fmt, ##__VA_ARGS__) |
|---|
| 138 | 160 | |
|---|
| 139 | 161 | #define dynamic_netdev_dbg(dev, fmt, ...) \ |
|---|
| 140 | | -do { \ |
|---|
| 141 | | - DEFINE_DYNAMIC_DEBUG_METADATA(descriptor, fmt); \ |
|---|
| 142 | | - if (DYNAMIC_DEBUG_BRANCH(descriptor)) \ |
|---|
| 143 | | - __dynamic_netdev_dbg(&descriptor, dev, fmt, \ |
|---|
| 144 | | - ##__VA_ARGS__); \ |
|---|
| 145 | | -} while (0) |
|---|
| 162 | + _dynamic_func_call(fmt, __dynamic_netdev_dbg, \ |
|---|
| 163 | + dev, fmt, ##__VA_ARGS__) |
|---|
| 146 | 164 | |
|---|
| 147 | | -#define dynamic_hex_dump(prefix_str, prefix_type, rowsize, \ |
|---|
| 148 | | - groupsize, buf, len, ascii) \ |
|---|
| 149 | | -do { \ |
|---|
| 150 | | - DEFINE_DYNAMIC_DEBUG_METADATA(descriptor, \ |
|---|
| 151 | | - __builtin_constant_p(prefix_str) ? prefix_str : "hexdump");\ |
|---|
| 152 | | - if (DYNAMIC_DEBUG_BRANCH(descriptor)) \ |
|---|
| 153 | | - print_hex_dump(KERN_DEBUG, prefix_str, \ |
|---|
| 154 | | - prefix_type, rowsize, groupsize, \ |
|---|
| 155 | | - buf, len, ascii); \ |
|---|
| 156 | | -} while (0) |
|---|
| 165 | +#define dynamic_ibdev_dbg(dev, fmt, ...) \ |
|---|
| 166 | + _dynamic_func_call(fmt, __dynamic_ibdev_dbg, \ |
|---|
| 167 | + dev, fmt, ##__VA_ARGS__) |
|---|
| 157 | 168 | |
|---|
| 158 | | -#else |
|---|
| 169 | +#define dynamic_hex_dump(prefix_str, prefix_type, rowsize, \ |
|---|
| 170 | + groupsize, buf, len, ascii) \ |
|---|
| 171 | + _dynamic_func_call_no_desc(__builtin_constant_p(prefix_str) ? prefix_str : "hexdump", \ |
|---|
| 172 | + print_hex_dump, \ |
|---|
| 173 | + KERN_DEBUG, prefix_str, prefix_type, \ |
|---|
| 174 | + rowsize, groupsize, buf, len, ascii) |
|---|
| 175 | + |
|---|
| 176 | +#else /* !CONFIG_DYNAMIC_DEBUG_CORE */ |
|---|
| 159 | 177 | |
|---|
| 160 | 178 | #include <linux/string.h> |
|---|
| 161 | 179 | #include <linux/errno.h> |
|---|
| 180 | +#include <linux/printk.h> |
|---|
| 181 | + |
|---|
| 182 | +static inline int ddebug_add_module(struct _ddebug *tab, unsigned int n, |
|---|
| 183 | + const char *modname) |
|---|
| 184 | +{ |
|---|
| 185 | + return 0; |
|---|
| 186 | +} |
|---|
| 162 | 187 | |
|---|
| 163 | 188 | static inline int ddebug_remove_module(const char *mod) |
|---|
| 164 | 189 | { |
|---|
| .. | .. |
|---|
| 168 | 193 | static inline int ddebug_dyndbg_module_param_cb(char *param, char *val, |
|---|
| 169 | 194 | const char *modname) |
|---|
| 170 | 195 | { |
|---|
| 171 | | - if (strstr(param, "dyndbg")) { |
|---|
| 196 | + if (!strcmp(param, "dyndbg")) { |
|---|
| 172 | 197 | /* avoid pr_warn(), which wants pr_fmt() fully defined */ |
|---|
| 173 | 198 | printk(KERN_WARNING "dyndbg param is supported only in " |
|---|
| 174 | 199 | "CONFIG_DYNAMIC_DEBUG builds\n"); |
|---|
| .. | .. |
|---|
| 181 | 206 | do { if (0) printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__); } while (0) |
|---|
| 182 | 207 | #define dynamic_dev_dbg(dev, fmt, ...) \ |
|---|
| 183 | 208 | do { if (0) dev_printk(KERN_DEBUG, dev, fmt, ##__VA_ARGS__); } while (0) |
|---|
| 184 | | -#endif |
|---|
| 209 | +#define dynamic_hex_dump(prefix_str, prefix_type, rowsize, \ |
|---|
| 210 | + groupsize, buf, len, ascii) \ |
|---|
| 211 | + do { if (0) \ |
|---|
| 212 | + print_hex_dump(KERN_DEBUG, prefix_str, prefix_type, \ |
|---|
| 213 | + rowsize, groupsize, buf, len, ascii); \ |
|---|
| 214 | + } while (0) |
|---|
| 215 | + |
|---|
| 216 | +#endif /* !CONFIG_DYNAMIC_DEBUG_CORE */ |
|---|
| 185 | 217 | |
|---|
| 186 | 218 | #endif |
|---|