Jason Baron | e9d376f | 2009-02-05 11:51:38 -0500 | [diff] [blame] | 1 | /* |
| 2 | * lib/dynamic_debug.c |
| 3 | * |
| 4 | * make pr_debug()/dev_dbg() calls runtime configurable based upon their |
| 5 | * source module. |
| 6 | * |
| 7 | * Copyright (C) 2008 Jason Baron <jbaron@redhat.com> |
| 8 | * By Greg Banks <gnb@melbourne.sgi.com> |
| 9 | * Copyright (c) 2008 Silicon Graphics Inc. All Rights Reserved. |
Bart Van Assche | 8ba6ebf5 | 2011-01-23 17:17:24 +0100 | [diff] [blame] | 10 | * Copyright (C) 2011 Bart Van Assche. All Rights Reserved. |
Jason Baron | e9d376f | 2009-02-05 11:51:38 -0500 | [diff] [blame] | 11 | */ |
| 12 | |
Joe Perches | 4ad275e | 2011-08-11 14:36:33 -0400 | [diff] [blame] | 13 | #define pr_fmt(fmt) KBUILD_MODNAME ":%s: " fmt, __func__ |
| 14 | |
Jason Baron | e9d376f | 2009-02-05 11:51:38 -0500 | [diff] [blame] | 15 | #include <linux/kernel.h> |
| 16 | #include <linux/module.h> |
| 17 | #include <linux/moduleparam.h> |
| 18 | #include <linux/kallsyms.h> |
Jason Baron | e9d376f | 2009-02-05 11:51:38 -0500 | [diff] [blame] | 19 | #include <linux/types.h> |
| 20 | #include <linux/mutex.h> |
| 21 | #include <linux/proc_fs.h> |
| 22 | #include <linux/seq_file.h> |
| 23 | #include <linux/list.h> |
| 24 | #include <linux/sysctl.h> |
| 25 | #include <linux/ctype.h> |
André Goddard Rosa | e7d2860 | 2009-12-14 18:01:06 -0800 | [diff] [blame] | 26 | #include <linux/string.h> |
Jason Baron | e9d376f | 2009-02-05 11:51:38 -0500 | [diff] [blame] | 27 | #include <linux/uaccess.h> |
| 28 | #include <linux/dynamic_debug.h> |
| 29 | #include <linux/debugfs.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 30 | #include <linux/slab.h> |
Jason Baron | 52159d9 | 2010-09-17 11:09:17 -0400 | [diff] [blame] | 31 | #include <linux/jump_label.h> |
Bart Van Assche | 8ba6ebf5 | 2011-01-23 17:17:24 +0100 | [diff] [blame] | 32 | #include <linux/hardirq.h> |
Greg Kroah-Hartman | e8d9792 | 2011-02-03 15:59:58 -0800 | [diff] [blame] | 33 | #include <linux/sched.h> |
Joe Perches | cbc4663 | 2011-08-11 14:36:21 -0400 | [diff] [blame] | 34 | #include <linux/device.h> |
Jason Baron | ffa10cb | 2011-08-11 14:36:48 -0400 | [diff] [blame] | 35 | #include <linux/netdevice.h> |
Jason Baron | e9d376f | 2009-02-05 11:51:38 -0500 | [diff] [blame] | 36 | |
| 37 | extern struct _ddebug __start___verbose[]; |
| 38 | extern struct _ddebug __stop___verbose[]; |
| 39 | |
Jason Baron | e9d376f | 2009-02-05 11:51:38 -0500 | [diff] [blame] | 40 | struct ddebug_table { |
| 41 | struct list_head link; |
| 42 | char *mod_name; |
| 43 | unsigned int num_ddebugs; |
Jason Baron | e9d376f | 2009-02-05 11:51:38 -0500 | [diff] [blame] | 44 | struct _ddebug *ddebugs; |
| 45 | }; |
| 46 | |
| 47 | struct ddebug_query { |
| 48 | const char *filename; |
| 49 | const char *module; |
| 50 | const char *function; |
| 51 | const char *format; |
| 52 | unsigned int first_lineno, last_lineno; |
| 53 | }; |
| 54 | |
| 55 | struct ddebug_iter { |
| 56 | struct ddebug_table *table; |
| 57 | unsigned int idx; |
| 58 | }; |
| 59 | |
| 60 | static DEFINE_MUTEX(ddebug_lock); |
| 61 | static LIST_HEAD(ddebug_tables); |
| 62 | static int verbose = 0; |
Jim Cromie | 74df138 | 2011-12-19 17:12:24 -0500 | [diff] [blame] | 63 | module_param(verbose, int, 0644); |
Jason Baron | e9d376f | 2009-02-05 11:51:38 -0500 | [diff] [blame] | 64 | |
| 65 | /* Return the last part of a pathname */ |
| 66 | static inline const char *basename(const char *path) |
| 67 | { |
| 68 | const char *tail = strrchr(path, '/'); |
| 69 | return tail ? tail+1 : path; |
| 70 | } |
| 71 | |
Bart Van Assche | 8ba6ebf5 | 2011-01-23 17:17:24 +0100 | [diff] [blame] | 72 | static struct { unsigned flag:8; char opt_char; } opt_array[] = { |
| 73 | { _DPRINTK_FLAGS_PRINT, 'p' }, |
| 74 | { _DPRINTK_FLAGS_INCL_MODNAME, 'm' }, |
| 75 | { _DPRINTK_FLAGS_INCL_FUNCNAME, 'f' }, |
| 76 | { _DPRINTK_FLAGS_INCL_LINENO, 'l' }, |
| 77 | { _DPRINTK_FLAGS_INCL_TID, 't' }, |
| 78 | }; |
| 79 | |
Jason Baron | e9d376f | 2009-02-05 11:51:38 -0500 | [diff] [blame] | 80 | /* format a string into buf[] which describes the _ddebug's flags */ |
| 81 | static char *ddebug_describe_flags(struct _ddebug *dp, char *buf, |
| 82 | size_t maxlen) |
| 83 | { |
| 84 | char *p = buf; |
Bart Van Assche | 8ba6ebf5 | 2011-01-23 17:17:24 +0100 | [diff] [blame] | 85 | int i; |
Jason Baron | e9d376f | 2009-02-05 11:51:38 -0500 | [diff] [blame] | 86 | |
| 87 | BUG_ON(maxlen < 4); |
Bart Van Assche | 8ba6ebf5 | 2011-01-23 17:17:24 +0100 | [diff] [blame] | 88 | for (i = 0; i < ARRAY_SIZE(opt_array); ++i) |
| 89 | if (dp->flags & opt_array[i].flag) |
| 90 | *p++ = opt_array[i].opt_char; |
Jason Baron | e9d376f | 2009-02-05 11:51:38 -0500 | [diff] [blame] | 91 | if (p == buf) |
| 92 | *p++ = '-'; |
| 93 | *p = '\0'; |
| 94 | |
| 95 | return buf; |
| 96 | } |
| 97 | |
| 98 | /* |
Jason Baron | e9d376f | 2009-02-05 11:51:38 -0500 | [diff] [blame] | 99 | * Search the tables for _ddebug's which match the given |
| 100 | * `query' and apply the `flags' and `mask' to them. Tells |
| 101 | * the user which ddebug's were changed, or whether none |
| 102 | * were matched. |
| 103 | */ |
| 104 | static void ddebug_change(const struct ddebug_query *query, |
| 105 | unsigned int flags, unsigned int mask) |
| 106 | { |
| 107 | int i; |
| 108 | struct ddebug_table *dt; |
| 109 | unsigned int newflags; |
| 110 | unsigned int nfound = 0; |
| 111 | char flagbuf[8]; |
| 112 | |
| 113 | /* search for matching ddebugs */ |
| 114 | mutex_lock(&ddebug_lock); |
| 115 | list_for_each_entry(dt, &ddebug_tables, link) { |
| 116 | |
| 117 | /* match against the module name */ |
Jim Cromie | d6a238d | 2011-12-19 17:12:39 -0500 | [diff] [blame^] | 118 | if (query->module && strcmp(query->module, dt->mod_name)) |
Jason Baron | e9d376f | 2009-02-05 11:51:38 -0500 | [diff] [blame] | 119 | continue; |
| 120 | |
| 121 | for (i = 0 ; i < dt->num_ddebugs ; i++) { |
| 122 | struct _ddebug *dp = &dt->ddebugs[i]; |
| 123 | |
| 124 | /* match against the source filename */ |
Jim Cromie | d6a238d | 2011-12-19 17:12:39 -0500 | [diff] [blame^] | 125 | if (query->filename && |
Jason Baron | e9d376f | 2009-02-05 11:51:38 -0500 | [diff] [blame] | 126 | strcmp(query->filename, dp->filename) && |
| 127 | strcmp(query->filename, basename(dp->filename))) |
| 128 | continue; |
| 129 | |
| 130 | /* match against the function */ |
Jim Cromie | d6a238d | 2011-12-19 17:12:39 -0500 | [diff] [blame^] | 131 | if (query->function && |
Jason Baron | e9d376f | 2009-02-05 11:51:38 -0500 | [diff] [blame] | 132 | strcmp(query->function, dp->function)) |
| 133 | continue; |
| 134 | |
| 135 | /* match against the format */ |
Jim Cromie | d6a238d | 2011-12-19 17:12:39 -0500 | [diff] [blame^] | 136 | if (query->format && |
| 137 | !strstr(dp->format, query->format)) |
Jason Baron | e9d376f | 2009-02-05 11:51:38 -0500 | [diff] [blame] | 138 | continue; |
| 139 | |
| 140 | /* match against the line number range */ |
| 141 | if (query->first_lineno && |
| 142 | dp->lineno < query->first_lineno) |
| 143 | continue; |
| 144 | if (query->last_lineno && |
| 145 | dp->lineno > query->last_lineno) |
| 146 | continue; |
| 147 | |
| 148 | nfound++; |
| 149 | |
| 150 | newflags = (dp->flags & mask) | flags; |
| 151 | if (newflags == dp->flags) |
| 152 | continue; |
Jason Baron | e9d376f | 2009-02-05 11:51:38 -0500 | [diff] [blame] | 153 | dp->flags = newflags; |
Jason Baron | e9d376f | 2009-02-05 11:51:38 -0500 | [diff] [blame] | 154 | if (verbose) |
Joe Perches | 4ad275e | 2011-08-11 14:36:33 -0400 | [diff] [blame] | 155 | pr_info("changed %s:%d [%s]%s %s\n", |
Jason Baron | e9d376f | 2009-02-05 11:51:38 -0500 | [diff] [blame] | 156 | dp->filename, dp->lineno, |
| 157 | dt->mod_name, dp->function, |
| 158 | ddebug_describe_flags(dp, flagbuf, |
| 159 | sizeof(flagbuf))); |
| 160 | } |
| 161 | } |
| 162 | mutex_unlock(&ddebug_lock); |
| 163 | |
| 164 | if (!nfound && verbose) |
Joe Perches | 4ad275e | 2011-08-11 14:36:33 -0400 | [diff] [blame] | 165 | pr_info("no matches for query\n"); |
Jason Baron | e9d376f | 2009-02-05 11:51:38 -0500 | [diff] [blame] | 166 | } |
| 167 | |
| 168 | /* |
Jason Baron | e9d376f | 2009-02-05 11:51:38 -0500 | [diff] [blame] | 169 | * Split the buffer `buf' into space-separated words. |
Greg Banks | 9898abb | 2009-02-06 12:54:26 +1100 | [diff] [blame] | 170 | * Handles simple " and ' quoting, i.e. without nested, |
| 171 | * embedded or escaped \". Return the number of words |
| 172 | * or <0 on error. |
Jason Baron | e9d376f | 2009-02-05 11:51:38 -0500 | [diff] [blame] | 173 | */ |
| 174 | static int ddebug_tokenize(char *buf, char *words[], int maxwords) |
| 175 | { |
| 176 | int nwords = 0; |
| 177 | |
Greg Banks | 9898abb | 2009-02-06 12:54:26 +1100 | [diff] [blame] | 178 | while (*buf) { |
| 179 | char *end; |
| 180 | |
| 181 | /* Skip leading whitespace */ |
André Goddard Rosa | e7d2860 | 2009-12-14 18:01:06 -0800 | [diff] [blame] | 182 | buf = skip_spaces(buf); |
Greg Banks | 9898abb | 2009-02-06 12:54:26 +1100 | [diff] [blame] | 183 | if (!*buf) |
| 184 | break; /* oh, it was trailing whitespace */ |
| 185 | |
Jim Cromie | 07100be | 2011-12-19 17:11:09 -0500 | [diff] [blame] | 186 | /* find `end' of word, whitespace separated or quoted */ |
Greg Banks | 9898abb | 2009-02-06 12:54:26 +1100 | [diff] [blame] | 187 | if (*buf == '"' || *buf == '\'') { |
| 188 | int quote = *buf++; |
| 189 | for (end = buf ; *end && *end != quote ; end++) |
| 190 | ; |
| 191 | if (!*end) |
| 192 | return -EINVAL; /* unclosed quote */ |
| 193 | } else { |
| 194 | for (end = buf ; *end && !isspace(*end) ; end++) |
| 195 | ; |
| 196 | BUG_ON(end == buf); |
| 197 | } |
Greg Banks | 9898abb | 2009-02-06 12:54:26 +1100 | [diff] [blame] | 198 | |
Jim Cromie | 07100be | 2011-12-19 17:11:09 -0500 | [diff] [blame] | 199 | /* `buf' is start of word, `end' is one past its end */ |
Greg Banks | 9898abb | 2009-02-06 12:54:26 +1100 | [diff] [blame] | 200 | if (nwords == maxwords) |
| 201 | return -EINVAL; /* ran out of words[] before bytes */ |
| 202 | if (*end) |
| 203 | *end++ = '\0'; /* terminate the word */ |
| 204 | words[nwords++] = buf; |
| 205 | buf = end; |
| 206 | } |
Jason Baron | e9d376f | 2009-02-05 11:51:38 -0500 | [diff] [blame] | 207 | |
| 208 | if (verbose) { |
| 209 | int i; |
Joe Perches | 4ad275e | 2011-08-11 14:36:33 -0400 | [diff] [blame] | 210 | pr_info("split into words:"); |
Jason Baron | e9d376f | 2009-02-05 11:51:38 -0500 | [diff] [blame] | 211 | for (i = 0 ; i < nwords ; i++) |
Joe Perches | 4ad275e | 2011-08-11 14:36:33 -0400 | [diff] [blame] | 212 | pr_cont(" \"%s\"", words[i]); |
| 213 | pr_cont("\n"); |
Jason Baron | e9d376f | 2009-02-05 11:51:38 -0500 | [diff] [blame] | 214 | } |
| 215 | |
| 216 | return nwords; |
| 217 | } |
| 218 | |
| 219 | /* |
| 220 | * Parse a single line number. Note that the empty string "" |
| 221 | * is treated as a special case and converted to zero, which |
| 222 | * is later treated as a "don't care" value. |
| 223 | */ |
| 224 | static inline int parse_lineno(const char *str, unsigned int *val) |
| 225 | { |
| 226 | char *end = NULL; |
| 227 | BUG_ON(str == NULL); |
| 228 | if (*str == '\0') { |
| 229 | *val = 0; |
| 230 | return 0; |
| 231 | } |
| 232 | *val = simple_strtoul(str, &end, 10); |
| 233 | return end == NULL || end == str || *end != '\0' ? -EINVAL : 0; |
| 234 | } |
| 235 | |
| 236 | /* |
| 237 | * Undo octal escaping in a string, inplace. This is useful to |
| 238 | * allow the user to express a query which matches a format |
| 239 | * containing embedded spaces. |
| 240 | */ |
| 241 | #define isodigit(c) ((c) >= '0' && (c) <= '7') |
| 242 | static char *unescape(char *str) |
| 243 | { |
| 244 | char *in = str; |
| 245 | char *out = str; |
| 246 | |
| 247 | while (*in) { |
| 248 | if (*in == '\\') { |
| 249 | if (in[1] == '\\') { |
| 250 | *out++ = '\\'; |
| 251 | in += 2; |
| 252 | continue; |
| 253 | } else if (in[1] == 't') { |
| 254 | *out++ = '\t'; |
| 255 | in += 2; |
| 256 | continue; |
| 257 | } else if (in[1] == 'n') { |
| 258 | *out++ = '\n'; |
| 259 | in += 2; |
| 260 | continue; |
| 261 | } else if (isodigit(in[1]) && |
| 262 | isodigit(in[2]) && |
| 263 | isodigit(in[3])) { |
| 264 | *out++ = ((in[1] - '0')<<6) | |
| 265 | ((in[2] - '0')<<3) | |
| 266 | (in[3] - '0'); |
| 267 | in += 4; |
| 268 | continue; |
| 269 | } |
| 270 | } |
| 271 | *out++ = *in++; |
| 272 | } |
| 273 | *out = '\0'; |
| 274 | |
| 275 | return str; |
| 276 | } |
| 277 | |
| 278 | /* |
| 279 | * Parse words[] as a ddebug query specification, which is a series |
| 280 | * of (keyword, value) pairs chosen from these possibilities: |
| 281 | * |
| 282 | * func <function-name> |
| 283 | * file <full-pathname> |
| 284 | * file <base-filename> |
| 285 | * module <module-name> |
| 286 | * format <escaped-string-to-find-in-format> |
| 287 | * line <lineno> |
| 288 | * line <first-lineno>-<last-lineno> // where either may be empty |
| 289 | */ |
| 290 | static int ddebug_parse_query(char *words[], int nwords, |
| 291 | struct ddebug_query *query) |
| 292 | { |
| 293 | unsigned int i; |
| 294 | |
| 295 | /* check we have an even number of words */ |
| 296 | if (nwords % 2 != 0) |
| 297 | return -EINVAL; |
| 298 | memset(query, 0, sizeof(*query)); |
| 299 | |
| 300 | for (i = 0 ; i < nwords ; i += 2) { |
| 301 | if (!strcmp(words[i], "func")) |
| 302 | query->function = words[i+1]; |
| 303 | else if (!strcmp(words[i], "file")) |
| 304 | query->filename = words[i+1]; |
| 305 | else if (!strcmp(words[i], "module")) |
| 306 | query->module = words[i+1]; |
| 307 | else if (!strcmp(words[i], "format")) |
| 308 | query->format = unescape(words[i+1]); |
| 309 | else if (!strcmp(words[i], "line")) { |
| 310 | char *first = words[i+1]; |
| 311 | char *last = strchr(first, '-'); |
| 312 | if (last) |
| 313 | *last++ = '\0'; |
| 314 | if (parse_lineno(first, &query->first_lineno) < 0) |
| 315 | return -EINVAL; |
| 316 | if (last != NULL) { |
| 317 | /* range <first>-<last> */ |
| 318 | if (parse_lineno(last, &query->last_lineno) < 0) |
| 319 | return -EINVAL; |
| 320 | } else { |
| 321 | query->last_lineno = query->first_lineno; |
| 322 | } |
| 323 | } else { |
Jim Cromie | ae27f86 | 2011-12-19 17:12:34 -0500 | [diff] [blame] | 324 | pr_err("unknown keyword \"%s\"\n", words[i]); |
Jason Baron | e9d376f | 2009-02-05 11:51:38 -0500 | [diff] [blame] | 325 | return -EINVAL; |
| 326 | } |
| 327 | } |
| 328 | |
| 329 | if (verbose) |
Joe Perches | 4ad275e | 2011-08-11 14:36:33 -0400 | [diff] [blame] | 330 | pr_info("q->function=\"%s\" q->filename=\"%s\" " |
| 331 | "q->module=\"%s\" q->format=\"%s\" q->lineno=%u-%u\n", |
| 332 | query->function, query->filename, |
Jason Baron | e9d376f | 2009-02-05 11:51:38 -0500 | [diff] [blame] | 333 | query->module, query->format, query->first_lineno, |
| 334 | query->last_lineno); |
| 335 | |
| 336 | return 0; |
| 337 | } |
| 338 | |
| 339 | /* |
| 340 | * Parse `str' as a flags specification, format [-+=][p]+. |
| 341 | * Sets up *maskp and *flagsp to be used when changing the |
| 342 | * flags fields of matched _ddebug's. Returns 0 on success |
| 343 | * or <0 on error. |
| 344 | */ |
| 345 | static int ddebug_parse_flags(const char *str, unsigned int *flagsp, |
| 346 | unsigned int *maskp) |
| 347 | { |
| 348 | unsigned flags = 0; |
Bart Van Assche | 8ba6ebf5 | 2011-01-23 17:17:24 +0100 | [diff] [blame] | 349 | int op = '=', i; |
Jason Baron | e9d376f | 2009-02-05 11:51:38 -0500 | [diff] [blame] | 350 | |
| 351 | switch (*str) { |
| 352 | case '+': |
| 353 | case '-': |
| 354 | case '=': |
| 355 | op = *str++; |
| 356 | break; |
| 357 | default: |
| 358 | return -EINVAL; |
| 359 | } |
| 360 | if (verbose) |
Joe Perches | 4ad275e | 2011-08-11 14:36:33 -0400 | [diff] [blame] | 361 | pr_info("op='%c'\n", op); |
Jason Baron | e9d376f | 2009-02-05 11:51:38 -0500 | [diff] [blame] | 362 | |
| 363 | for ( ; *str ; ++str) { |
Bart Van Assche | 8ba6ebf5 | 2011-01-23 17:17:24 +0100 | [diff] [blame] | 364 | for (i = ARRAY_SIZE(opt_array) - 1; i >= 0; i--) { |
| 365 | if (*str == opt_array[i].opt_char) { |
| 366 | flags |= opt_array[i].flag; |
| 367 | break; |
| 368 | } |
Jason Baron | e9d376f | 2009-02-05 11:51:38 -0500 | [diff] [blame] | 369 | } |
Bart Van Assche | 8ba6ebf5 | 2011-01-23 17:17:24 +0100 | [diff] [blame] | 370 | if (i < 0) |
| 371 | return -EINVAL; |
Jason Baron | e9d376f | 2009-02-05 11:51:38 -0500 | [diff] [blame] | 372 | } |
| 373 | if (flags == 0) |
| 374 | return -EINVAL; |
| 375 | if (verbose) |
Joe Perches | 4ad275e | 2011-08-11 14:36:33 -0400 | [diff] [blame] | 376 | pr_info("flags=0x%x\n", flags); |
Jason Baron | e9d376f | 2009-02-05 11:51:38 -0500 | [diff] [blame] | 377 | |
| 378 | /* calculate final *flagsp, *maskp according to mask and op */ |
| 379 | switch (op) { |
| 380 | case '=': |
| 381 | *maskp = 0; |
| 382 | *flagsp = flags; |
| 383 | break; |
| 384 | case '+': |
| 385 | *maskp = ~0U; |
| 386 | *flagsp = flags; |
| 387 | break; |
| 388 | case '-': |
| 389 | *maskp = ~flags; |
| 390 | *flagsp = 0; |
| 391 | break; |
| 392 | } |
| 393 | if (verbose) |
Joe Perches | 4ad275e | 2011-08-11 14:36:33 -0400 | [diff] [blame] | 394 | pr_info("*flagsp=0x%x *maskp=0x%x\n", *flagsp, *maskp); |
Jason Baron | e9d376f | 2009-02-05 11:51:38 -0500 | [diff] [blame] | 395 | return 0; |
| 396 | } |
| 397 | |
Thomas Renninger | fd89cfb | 2010-08-06 16:11:01 +0200 | [diff] [blame] | 398 | static int ddebug_exec_query(char *query_string) |
| 399 | { |
| 400 | unsigned int flags = 0, mask = 0; |
| 401 | struct ddebug_query query; |
| 402 | #define MAXWORDS 9 |
| 403 | int nwords; |
| 404 | char *words[MAXWORDS]; |
| 405 | |
| 406 | nwords = ddebug_tokenize(query_string, words, MAXWORDS); |
| 407 | if (nwords <= 0) |
| 408 | return -EINVAL; |
| 409 | if (ddebug_parse_query(words, nwords-1, &query)) |
| 410 | return -EINVAL; |
| 411 | if (ddebug_parse_flags(words[nwords-1], &flags, &mask)) |
| 412 | return -EINVAL; |
| 413 | |
| 414 | /* actually go and implement the change */ |
| 415 | ddebug_change(&query, flags, mask); |
| 416 | return 0; |
| 417 | } |
| 418 | |
Jason Baron | 431625d | 2011-10-04 14:13:19 -0700 | [diff] [blame] | 419 | #define PREFIX_SIZE 64 |
| 420 | |
| 421 | static int remaining(int wrote) |
Bart Van Assche | 8ba6ebf5 | 2011-01-23 17:17:24 +0100 | [diff] [blame] | 422 | { |
Jason Baron | 431625d | 2011-10-04 14:13:19 -0700 | [diff] [blame] | 423 | if (PREFIX_SIZE - wrote > 0) |
| 424 | return PREFIX_SIZE - wrote; |
| 425 | return 0; |
| 426 | } |
Bart Van Assche | 8ba6ebf5 | 2011-01-23 17:17:24 +0100 | [diff] [blame] | 427 | |
Jason Baron | 431625d | 2011-10-04 14:13:19 -0700 | [diff] [blame] | 428 | static char *dynamic_emit_prefix(const struct _ddebug *desc, char *buf) |
| 429 | { |
| 430 | int pos_after_tid; |
| 431 | int pos = 0; |
| 432 | |
| 433 | pos += snprintf(buf + pos, remaining(pos), "%s", KERN_DEBUG); |
| 434 | if (desc->flags & _DPRINTK_FLAGS_INCL_TID) { |
Bart Van Assche | 8ba6ebf5 | 2011-01-23 17:17:24 +0100 | [diff] [blame] | 435 | if (in_interrupt()) |
Jason Baron | 431625d | 2011-10-04 14:13:19 -0700 | [diff] [blame] | 436 | pos += snprintf(buf + pos, remaining(pos), "%s ", |
| 437 | "<intr>"); |
Bart Van Assche | 8ba6ebf5 | 2011-01-23 17:17:24 +0100 | [diff] [blame] | 438 | else |
Jason Baron | 431625d | 2011-10-04 14:13:19 -0700 | [diff] [blame] | 439 | pos += snprintf(buf + pos, remaining(pos), "[%d] ", |
| 440 | task_pid_vnr(current)); |
Bart Van Assche | 8ba6ebf5 | 2011-01-23 17:17:24 +0100 | [diff] [blame] | 441 | } |
Jason Baron | 431625d | 2011-10-04 14:13:19 -0700 | [diff] [blame] | 442 | pos_after_tid = pos; |
| 443 | if (desc->flags & _DPRINTK_FLAGS_INCL_MODNAME) |
| 444 | pos += snprintf(buf + pos, remaining(pos), "%s:", |
| 445 | desc->modname); |
| 446 | if (desc->flags & _DPRINTK_FLAGS_INCL_FUNCNAME) |
| 447 | pos += snprintf(buf + pos, remaining(pos), "%s:", |
| 448 | desc->function); |
| 449 | if (desc->flags & _DPRINTK_FLAGS_INCL_LINENO) |
Jim Cromie | 07100be | 2011-12-19 17:11:09 -0500 | [diff] [blame] | 450 | pos += snprintf(buf + pos, remaining(pos), "%d:", |
| 451 | desc->lineno); |
Jason Baron | 431625d | 2011-10-04 14:13:19 -0700 | [diff] [blame] | 452 | if (pos - pos_after_tid) |
| 453 | pos += snprintf(buf + pos, remaining(pos), " "); |
| 454 | if (pos >= PREFIX_SIZE) |
| 455 | buf[PREFIX_SIZE - 1] = '\0'; |
Joe Perches | 6c2140e | 2011-08-11 14:36:25 -0400 | [diff] [blame] | 456 | |
Jason Baron | 431625d | 2011-10-04 14:13:19 -0700 | [diff] [blame] | 457 | return buf; |
Joe Perches | 6c2140e | 2011-08-11 14:36:25 -0400 | [diff] [blame] | 458 | } |
| 459 | |
Bart Van Assche | 8ba6ebf5 | 2011-01-23 17:17:24 +0100 | [diff] [blame] | 460 | int __dynamic_pr_debug(struct _ddebug *descriptor, const char *fmt, ...) |
| 461 | { |
| 462 | va_list args; |
| 463 | int res; |
Jason Baron | 431625d | 2011-10-04 14:13:19 -0700 | [diff] [blame] | 464 | struct va_format vaf; |
| 465 | char buf[PREFIX_SIZE]; |
Bart Van Assche | 8ba6ebf5 | 2011-01-23 17:17:24 +0100 | [diff] [blame] | 466 | |
| 467 | BUG_ON(!descriptor); |
| 468 | BUG_ON(!fmt); |
| 469 | |
| 470 | va_start(args, fmt); |
Jason Baron | 431625d | 2011-10-04 14:13:19 -0700 | [diff] [blame] | 471 | vaf.fmt = fmt; |
| 472 | vaf.va = &args; |
| 473 | res = printk("%s%pV", dynamic_emit_prefix(descriptor, buf), &vaf); |
Bart Van Assche | 8ba6ebf5 | 2011-01-23 17:17:24 +0100 | [diff] [blame] | 474 | va_end(args); |
| 475 | |
| 476 | return res; |
| 477 | } |
| 478 | EXPORT_SYMBOL(__dynamic_pr_debug); |
| 479 | |
Joe Perches | cbc4663 | 2011-08-11 14:36:21 -0400 | [diff] [blame] | 480 | int __dynamic_dev_dbg(struct _ddebug *descriptor, |
| 481 | const struct device *dev, const char *fmt, ...) |
| 482 | { |
| 483 | struct va_format vaf; |
| 484 | va_list args; |
| 485 | int res; |
Jason Baron | 431625d | 2011-10-04 14:13:19 -0700 | [diff] [blame] | 486 | char buf[PREFIX_SIZE]; |
Joe Perches | cbc4663 | 2011-08-11 14:36:21 -0400 | [diff] [blame] | 487 | |
| 488 | BUG_ON(!descriptor); |
| 489 | BUG_ON(!fmt); |
| 490 | |
| 491 | va_start(args, fmt); |
Joe Perches | cbc4663 | 2011-08-11 14:36:21 -0400 | [diff] [blame] | 492 | vaf.fmt = fmt; |
| 493 | vaf.va = &args; |
Jason Baron | 431625d | 2011-10-04 14:13:19 -0700 | [diff] [blame] | 494 | res = __dev_printk(dynamic_emit_prefix(descriptor, buf), dev, &vaf); |
Joe Perches | cbc4663 | 2011-08-11 14:36:21 -0400 | [diff] [blame] | 495 | va_end(args); |
| 496 | |
| 497 | return res; |
| 498 | } |
| 499 | EXPORT_SYMBOL(__dynamic_dev_dbg); |
| 500 | |
Jason Baron | 0feefd9 | 2011-10-04 14:13:22 -0700 | [diff] [blame] | 501 | #ifdef CONFIG_NET |
| 502 | |
Jason Baron | ffa10cb | 2011-08-11 14:36:48 -0400 | [diff] [blame] | 503 | int __dynamic_netdev_dbg(struct _ddebug *descriptor, |
| 504 | const struct net_device *dev, const char *fmt, ...) |
| 505 | { |
| 506 | struct va_format vaf; |
| 507 | va_list args; |
| 508 | int res; |
Jason Baron | 431625d | 2011-10-04 14:13:19 -0700 | [diff] [blame] | 509 | char buf[PREFIX_SIZE]; |
Jason Baron | ffa10cb | 2011-08-11 14:36:48 -0400 | [diff] [blame] | 510 | |
| 511 | BUG_ON(!descriptor); |
| 512 | BUG_ON(!fmt); |
| 513 | |
| 514 | va_start(args, fmt); |
Jason Baron | ffa10cb | 2011-08-11 14:36:48 -0400 | [diff] [blame] | 515 | vaf.fmt = fmt; |
| 516 | vaf.va = &args; |
Jason Baron | 431625d | 2011-10-04 14:13:19 -0700 | [diff] [blame] | 517 | res = __netdev_printk(dynamic_emit_prefix(descriptor, buf), dev, &vaf); |
Jason Baron | ffa10cb | 2011-08-11 14:36:48 -0400 | [diff] [blame] | 518 | va_end(args); |
| 519 | |
| 520 | return res; |
| 521 | } |
| 522 | EXPORT_SYMBOL(__dynamic_netdev_dbg); |
| 523 | |
Jason Baron | 0feefd9 | 2011-10-04 14:13:22 -0700 | [diff] [blame] | 524 | #endif |
| 525 | |
Jim Cromie | bc757f6 | 2011-12-19 17:12:29 -0500 | [diff] [blame] | 526 | #define DDEBUG_STRING_SIZE 1024 |
| 527 | static __initdata char ddebug_setup_string[DDEBUG_STRING_SIZE]; |
| 528 | |
Thomas Renninger | a648ec0 | 2010-08-06 16:11:02 +0200 | [diff] [blame] | 529 | static __init int ddebug_setup_query(char *str) |
| 530 | { |
Jim Cromie | bc757f6 | 2011-12-19 17:12:29 -0500 | [diff] [blame] | 531 | if (strlen(str) >= DDEBUG_STRING_SIZE) { |
Joe Perches | 4ad275e | 2011-08-11 14:36:33 -0400 | [diff] [blame] | 532 | pr_warn("ddebug boot param string too large\n"); |
Thomas Renninger | a648ec0 | 2010-08-06 16:11:02 +0200 | [diff] [blame] | 533 | return 0; |
| 534 | } |
Jim Cromie | bc757f6 | 2011-12-19 17:12:29 -0500 | [diff] [blame] | 535 | strlcpy(ddebug_setup_string, str, DDEBUG_STRING_SIZE); |
Thomas Renninger | a648ec0 | 2010-08-06 16:11:02 +0200 | [diff] [blame] | 536 | return 1; |
| 537 | } |
| 538 | |
| 539 | __setup("ddebug_query=", ddebug_setup_query); |
| 540 | |
Jason Baron | e9d376f | 2009-02-05 11:51:38 -0500 | [diff] [blame] | 541 | /* |
| 542 | * File_ops->write method for <debugfs>/dynamic_debug/conrol. Gathers the |
| 543 | * command text from userspace, parses and executes it. |
| 544 | */ |
| 545 | static ssize_t ddebug_proc_write(struct file *file, const char __user *ubuf, |
| 546 | size_t len, loff_t *offp) |
| 547 | { |
Jason Baron | e9d376f | 2009-02-05 11:51:38 -0500 | [diff] [blame] | 548 | char tmpbuf[256]; |
Thomas Renninger | fd89cfb | 2010-08-06 16:11:01 +0200 | [diff] [blame] | 549 | int ret; |
Jason Baron | e9d376f | 2009-02-05 11:51:38 -0500 | [diff] [blame] | 550 | |
| 551 | if (len == 0) |
| 552 | return 0; |
| 553 | /* we don't check *offp -- multiple writes() are allowed */ |
| 554 | if (len > sizeof(tmpbuf)-1) |
| 555 | return -E2BIG; |
| 556 | if (copy_from_user(tmpbuf, ubuf, len)) |
| 557 | return -EFAULT; |
| 558 | tmpbuf[len] = '\0'; |
| 559 | if (verbose) |
Joe Perches | 4ad275e | 2011-08-11 14:36:33 -0400 | [diff] [blame] | 560 | pr_info("read %d bytes from userspace\n", (int)len); |
Jason Baron | e9d376f | 2009-02-05 11:51:38 -0500 | [diff] [blame] | 561 | |
Thomas Renninger | fd89cfb | 2010-08-06 16:11:01 +0200 | [diff] [blame] | 562 | ret = ddebug_exec_query(tmpbuf); |
| 563 | if (ret) |
| 564 | return ret; |
Jason Baron | e9d376f | 2009-02-05 11:51:38 -0500 | [diff] [blame] | 565 | |
| 566 | *offp += len; |
| 567 | return len; |
| 568 | } |
| 569 | |
| 570 | /* |
| 571 | * Set the iterator to point to the first _ddebug object |
| 572 | * and return a pointer to that first object. Returns |
| 573 | * NULL if there are no _ddebugs at all. |
| 574 | */ |
| 575 | static struct _ddebug *ddebug_iter_first(struct ddebug_iter *iter) |
| 576 | { |
| 577 | if (list_empty(&ddebug_tables)) { |
| 578 | iter->table = NULL; |
| 579 | iter->idx = 0; |
| 580 | return NULL; |
| 581 | } |
| 582 | iter->table = list_entry(ddebug_tables.next, |
| 583 | struct ddebug_table, link); |
| 584 | iter->idx = 0; |
| 585 | return &iter->table->ddebugs[iter->idx]; |
| 586 | } |
| 587 | |
| 588 | /* |
| 589 | * Advance the iterator to point to the next _ddebug |
| 590 | * object from the one the iterator currently points at, |
| 591 | * and returns a pointer to the new _ddebug. Returns |
| 592 | * NULL if the iterator has seen all the _ddebugs. |
| 593 | */ |
| 594 | static struct _ddebug *ddebug_iter_next(struct ddebug_iter *iter) |
| 595 | { |
| 596 | if (iter->table == NULL) |
| 597 | return NULL; |
| 598 | if (++iter->idx == iter->table->num_ddebugs) { |
| 599 | /* iterate to next table */ |
| 600 | iter->idx = 0; |
| 601 | if (list_is_last(&iter->table->link, &ddebug_tables)) { |
| 602 | iter->table = NULL; |
| 603 | return NULL; |
| 604 | } |
| 605 | iter->table = list_entry(iter->table->link.next, |
| 606 | struct ddebug_table, link); |
| 607 | } |
| 608 | return &iter->table->ddebugs[iter->idx]; |
| 609 | } |
| 610 | |
| 611 | /* |
| 612 | * Seq_ops start method. Called at the start of every |
| 613 | * read() call from userspace. Takes the ddebug_lock and |
| 614 | * seeks the seq_file's iterator to the given position. |
| 615 | */ |
| 616 | static void *ddebug_proc_start(struct seq_file *m, loff_t *pos) |
| 617 | { |
| 618 | struct ddebug_iter *iter = m->private; |
| 619 | struct _ddebug *dp; |
| 620 | int n = *pos; |
| 621 | |
| 622 | if (verbose) |
Joe Perches | 4ad275e | 2011-08-11 14:36:33 -0400 | [diff] [blame] | 623 | pr_info("called m=%p *pos=%lld\n", m, (unsigned long long)*pos); |
Jason Baron | e9d376f | 2009-02-05 11:51:38 -0500 | [diff] [blame] | 624 | |
| 625 | mutex_lock(&ddebug_lock); |
| 626 | |
| 627 | if (!n) |
| 628 | return SEQ_START_TOKEN; |
| 629 | if (n < 0) |
| 630 | return NULL; |
| 631 | dp = ddebug_iter_first(iter); |
| 632 | while (dp != NULL && --n > 0) |
| 633 | dp = ddebug_iter_next(iter); |
| 634 | return dp; |
| 635 | } |
| 636 | |
| 637 | /* |
| 638 | * Seq_ops next method. Called several times within a read() |
| 639 | * call from userspace, with ddebug_lock held. Walks to the |
| 640 | * next _ddebug object with a special case for the header line. |
| 641 | */ |
| 642 | static void *ddebug_proc_next(struct seq_file *m, void *p, loff_t *pos) |
| 643 | { |
| 644 | struct ddebug_iter *iter = m->private; |
| 645 | struct _ddebug *dp; |
| 646 | |
| 647 | if (verbose) |
Joe Perches | 4ad275e | 2011-08-11 14:36:33 -0400 | [diff] [blame] | 648 | pr_info("called m=%p p=%p *pos=%lld\n", |
| 649 | m, p, (unsigned long long)*pos); |
Jason Baron | e9d376f | 2009-02-05 11:51:38 -0500 | [diff] [blame] | 650 | |
| 651 | if (p == SEQ_START_TOKEN) |
| 652 | dp = ddebug_iter_first(iter); |
| 653 | else |
| 654 | dp = ddebug_iter_next(iter); |
| 655 | ++*pos; |
| 656 | return dp; |
| 657 | } |
| 658 | |
| 659 | /* |
| 660 | * Seq_ops show method. Called several times within a read() |
| 661 | * call from userspace, with ddebug_lock held. Formats the |
| 662 | * current _ddebug as a single human-readable line, with a |
| 663 | * special case for the header line. |
| 664 | */ |
| 665 | static int ddebug_proc_show(struct seq_file *m, void *p) |
| 666 | { |
| 667 | struct ddebug_iter *iter = m->private; |
| 668 | struct _ddebug *dp = p; |
| 669 | char flagsbuf[8]; |
| 670 | |
| 671 | if (verbose) |
Joe Perches | 4ad275e | 2011-08-11 14:36:33 -0400 | [diff] [blame] | 672 | pr_info("called m=%p p=%p\n", m, p); |
Jason Baron | e9d376f | 2009-02-05 11:51:38 -0500 | [diff] [blame] | 673 | |
| 674 | if (p == SEQ_START_TOKEN) { |
| 675 | seq_puts(m, |
| 676 | "# filename:lineno [module]function flags format\n"); |
| 677 | return 0; |
| 678 | } |
| 679 | |
| 680 | seq_printf(m, "%s:%u [%s]%s %s \"", |
| 681 | dp->filename, dp->lineno, |
| 682 | iter->table->mod_name, dp->function, |
| 683 | ddebug_describe_flags(dp, flagsbuf, sizeof(flagsbuf))); |
| 684 | seq_escape(m, dp->format, "\t\r\n\""); |
| 685 | seq_puts(m, "\"\n"); |
| 686 | |
| 687 | return 0; |
| 688 | } |
| 689 | |
| 690 | /* |
| 691 | * Seq_ops stop method. Called at the end of each read() |
| 692 | * call from userspace. Drops ddebug_lock. |
| 693 | */ |
| 694 | static void ddebug_proc_stop(struct seq_file *m, void *p) |
| 695 | { |
| 696 | if (verbose) |
Joe Perches | 4ad275e | 2011-08-11 14:36:33 -0400 | [diff] [blame] | 697 | pr_info("called m=%p p=%p\n", m, p); |
Jason Baron | e9d376f | 2009-02-05 11:51:38 -0500 | [diff] [blame] | 698 | mutex_unlock(&ddebug_lock); |
| 699 | } |
| 700 | |
| 701 | static const struct seq_operations ddebug_proc_seqops = { |
| 702 | .start = ddebug_proc_start, |
| 703 | .next = ddebug_proc_next, |
| 704 | .show = ddebug_proc_show, |
| 705 | .stop = ddebug_proc_stop |
| 706 | }; |
| 707 | |
| 708 | /* |
Jim Cromie | 07100be | 2011-12-19 17:11:09 -0500 | [diff] [blame] | 709 | * File_ops->open method for <debugfs>/dynamic_debug/control. Does |
| 710 | * the seq_file setup dance, and also creates an iterator to walk the |
| 711 | * _ddebugs. Note that we create a seq_file always, even for O_WRONLY |
| 712 | * files where it's not needed, as doing so simplifies the ->release |
| 713 | * method. |
Jason Baron | e9d376f | 2009-02-05 11:51:38 -0500 | [diff] [blame] | 714 | */ |
| 715 | static int ddebug_proc_open(struct inode *inode, struct file *file) |
| 716 | { |
| 717 | struct ddebug_iter *iter; |
| 718 | int err; |
| 719 | |
| 720 | if (verbose) |
Joe Perches | 4ad275e | 2011-08-11 14:36:33 -0400 | [diff] [blame] | 721 | pr_info("called\n"); |
Jason Baron | e9d376f | 2009-02-05 11:51:38 -0500 | [diff] [blame] | 722 | |
| 723 | iter = kzalloc(sizeof(*iter), GFP_KERNEL); |
| 724 | if (iter == NULL) |
| 725 | return -ENOMEM; |
| 726 | |
| 727 | err = seq_open(file, &ddebug_proc_seqops); |
| 728 | if (err) { |
| 729 | kfree(iter); |
| 730 | return err; |
| 731 | } |
| 732 | ((struct seq_file *) file->private_data)->private = iter; |
| 733 | return 0; |
| 734 | } |
| 735 | |
| 736 | static const struct file_operations ddebug_proc_fops = { |
| 737 | .owner = THIS_MODULE, |
| 738 | .open = ddebug_proc_open, |
| 739 | .read = seq_read, |
| 740 | .llseek = seq_lseek, |
| 741 | .release = seq_release_private, |
| 742 | .write = ddebug_proc_write |
| 743 | }; |
| 744 | |
| 745 | /* |
| 746 | * Allocate a new ddebug_table for the given module |
| 747 | * and add it to the global list. |
| 748 | */ |
| 749 | int ddebug_add_module(struct _ddebug *tab, unsigned int n, |
| 750 | const char *name) |
| 751 | { |
| 752 | struct ddebug_table *dt; |
| 753 | char *new_name; |
| 754 | |
| 755 | dt = kzalloc(sizeof(*dt), GFP_KERNEL); |
| 756 | if (dt == NULL) |
| 757 | return -ENOMEM; |
| 758 | new_name = kstrdup(name, GFP_KERNEL); |
| 759 | if (new_name == NULL) { |
| 760 | kfree(dt); |
| 761 | return -ENOMEM; |
| 762 | } |
| 763 | dt->mod_name = new_name; |
| 764 | dt->num_ddebugs = n; |
Jason Baron | e9d376f | 2009-02-05 11:51:38 -0500 | [diff] [blame] | 765 | dt->ddebugs = tab; |
| 766 | |
| 767 | mutex_lock(&ddebug_lock); |
| 768 | list_add_tail(&dt->link, &ddebug_tables); |
| 769 | mutex_unlock(&ddebug_lock); |
| 770 | |
| 771 | if (verbose) |
Joe Perches | 4ad275e | 2011-08-11 14:36:33 -0400 | [diff] [blame] | 772 | pr_info("%u debug prints in module %s\n", n, dt->mod_name); |
Jason Baron | e9d376f | 2009-02-05 11:51:38 -0500 | [diff] [blame] | 773 | return 0; |
| 774 | } |
| 775 | EXPORT_SYMBOL_GPL(ddebug_add_module); |
| 776 | |
| 777 | static void ddebug_table_free(struct ddebug_table *dt) |
| 778 | { |
| 779 | list_del_init(&dt->link); |
| 780 | kfree(dt->mod_name); |
| 781 | kfree(dt); |
| 782 | } |
| 783 | |
| 784 | /* |
| 785 | * Called in response to a module being unloaded. Removes |
| 786 | * any ddebug_table's which point at the module. |
| 787 | */ |
Yehuda Sadeh | ff49d74 | 2010-07-03 13:07:35 +1000 | [diff] [blame] | 788 | int ddebug_remove_module(const char *mod_name) |
Jason Baron | e9d376f | 2009-02-05 11:51:38 -0500 | [diff] [blame] | 789 | { |
| 790 | struct ddebug_table *dt, *nextdt; |
| 791 | int ret = -ENOENT; |
| 792 | |
| 793 | if (verbose) |
Joe Perches | 4ad275e | 2011-08-11 14:36:33 -0400 | [diff] [blame] | 794 | pr_info("removing module \"%s\"\n", mod_name); |
Jason Baron | e9d376f | 2009-02-05 11:51:38 -0500 | [diff] [blame] | 795 | |
| 796 | mutex_lock(&ddebug_lock); |
| 797 | list_for_each_entry_safe(dt, nextdt, &ddebug_tables, link) { |
| 798 | if (!strcmp(dt->mod_name, mod_name)) { |
| 799 | ddebug_table_free(dt); |
| 800 | ret = 0; |
| 801 | } |
| 802 | } |
| 803 | mutex_unlock(&ddebug_lock); |
| 804 | return ret; |
| 805 | } |
| 806 | EXPORT_SYMBOL_GPL(ddebug_remove_module); |
| 807 | |
| 808 | static void ddebug_remove_all_tables(void) |
| 809 | { |
| 810 | mutex_lock(&ddebug_lock); |
| 811 | while (!list_empty(&ddebug_tables)) { |
| 812 | struct ddebug_table *dt = list_entry(ddebug_tables.next, |
| 813 | struct ddebug_table, |
| 814 | link); |
| 815 | ddebug_table_free(dt); |
| 816 | } |
| 817 | mutex_unlock(&ddebug_lock); |
| 818 | } |
| 819 | |
Thomas Renninger | 6a5c083 | 2010-08-06 16:11:03 +0200 | [diff] [blame] | 820 | static __initdata int ddebug_init_success; |
| 821 | |
| 822 | static int __init dynamic_debug_init_debugfs(void) |
Jason Baron | e9d376f | 2009-02-05 11:51:38 -0500 | [diff] [blame] | 823 | { |
| 824 | struct dentry *dir, *file; |
Thomas Renninger | 6a5c083 | 2010-08-06 16:11:03 +0200 | [diff] [blame] | 825 | |
| 826 | if (!ddebug_init_success) |
| 827 | return -ENODEV; |
Jason Baron | e9d376f | 2009-02-05 11:51:38 -0500 | [diff] [blame] | 828 | |
| 829 | dir = debugfs_create_dir("dynamic_debug", NULL); |
| 830 | if (!dir) |
| 831 | return -ENOMEM; |
| 832 | file = debugfs_create_file("control", 0644, dir, NULL, |
| 833 | &ddebug_proc_fops); |
| 834 | if (!file) { |
| 835 | debugfs_remove(dir); |
| 836 | return -ENOMEM; |
| 837 | } |
Thomas Renninger | 6a5c083 | 2010-08-06 16:11:03 +0200 | [diff] [blame] | 838 | return 0; |
| 839 | } |
| 840 | |
| 841 | static int __init dynamic_debug_init(void) |
| 842 | { |
| 843 | struct _ddebug *iter, *iter_start; |
| 844 | const char *modname = NULL; |
| 845 | int ret = 0; |
| 846 | int n = 0; |
| 847 | |
Jason Baron | e9d376f | 2009-02-05 11:51:38 -0500 | [diff] [blame] | 848 | if (__start___verbose != __stop___verbose) { |
| 849 | iter = __start___verbose; |
| 850 | modname = iter->modname; |
| 851 | iter_start = iter; |
| 852 | for (; iter < __stop___verbose; iter++) { |
| 853 | if (strcmp(modname, iter->modname)) { |
| 854 | ret = ddebug_add_module(iter_start, n, modname); |
| 855 | if (ret) |
| 856 | goto out_free; |
| 857 | n = 0; |
| 858 | modname = iter->modname; |
| 859 | iter_start = iter; |
| 860 | } |
| 861 | n++; |
| 862 | } |
| 863 | ret = ddebug_add_module(iter_start, n, modname); |
| 864 | } |
Thomas Renninger | a648ec0 | 2010-08-06 16:11:02 +0200 | [diff] [blame] | 865 | |
| 866 | /* ddebug_query boot param got passed -> set it up */ |
| 867 | if (ddebug_setup_string[0] != '\0') { |
| 868 | ret = ddebug_exec_query(ddebug_setup_string); |
| 869 | if (ret) |
Joe Perches | 4ad275e | 2011-08-11 14:36:33 -0400 | [diff] [blame] | 870 | pr_warn("Invalid ddebug boot param %s", |
| 871 | ddebug_setup_string); |
Thomas Renninger | a648ec0 | 2010-08-06 16:11:02 +0200 | [diff] [blame] | 872 | else |
| 873 | pr_info("ddebug initialized with string %s", |
| 874 | ddebug_setup_string); |
Jason Baron | e9d376f | 2009-02-05 11:51:38 -0500 | [diff] [blame] | 875 | } |
Thomas Renninger | a648ec0 | 2010-08-06 16:11:02 +0200 | [diff] [blame] | 876 | |
Jason Baron | e9d376f | 2009-02-05 11:51:38 -0500 | [diff] [blame] | 877 | out_free: |
Thomas Renninger | 6a5c083 | 2010-08-06 16:11:03 +0200 | [diff] [blame] | 878 | if (ret) |
Jason Baron | e9d376f | 2009-02-05 11:51:38 -0500 | [diff] [blame] | 879 | ddebug_remove_all_tables(); |
Thomas Renninger | 6a5c083 | 2010-08-06 16:11:03 +0200 | [diff] [blame] | 880 | else |
| 881 | ddebug_init_success = 1; |
Jason Baron | e9d376f | 2009-02-05 11:51:38 -0500 | [diff] [blame] | 882 | return 0; |
| 883 | } |
Thomas Renninger | 6a5c083 | 2010-08-06 16:11:03 +0200 | [diff] [blame] | 884 | /* Allow early initialization for boot messages via boot param */ |
| 885 | arch_initcall(dynamic_debug_init); |
| 886 | /* Debugfs setup must be done later */ |
| 887 | module_init(dynamic_debug_init_debugfs); |