blob: 0c9653f11c181cb50885d5185786a8d2d3d6c335 [file] [log] [blame]
Jason Barone9d376f2009-02-05 11:51:38 -05001#ifndef _DYNAMIC_DEBUG_H
2#define _DYNAMIC_DEBUG_H
3
Jason Baron52159d92010-09-17 11:09:17 -04004#include <linux/jump_label.h>
5
Jason Barone9d376f2009-02-05 11:51:38 -05006/* dynamic_printk_enabled, and dynamic_printk_enabled2 are bitmasks in which
7 * bit n is set to 1 if any modname hashes into the bucket n, 0 otherwise. They
8 * use independent hash functions, to reduce the chance of false positives.
9 */
10extern long long dynamic_debug_enabled;
11extern long long dynamic_debug_enabled2;
12
13/*
14 * An instance of this structure is created in a special
15 * ELF section at every dynamic debug callsite. At runtime,
16 * the special section is treated as an array of these.
17 */
18struct _ddebug {
19 /*
20 * These fields are used to drive the user interface
21 * for selecting and displaying debug callsites.
22 */
23 const char *modname;
24 const char *function;
25 const char *filename;
26 const char *format;
Jason Barone9d376f2009-02-05 11:51:38 -050027 unsigned int lineno:24;
28 /*
29 * The flags field controls the behaviour at the callsite.
30 * The bits here are changed dynamically when the user
Florian Ragwitz2b2f68b2010-05-24 14:33:21 -070031 * writes commands to <debugfs>/dynamic_debug/control
Jason Barone9d376f2009-02-05 11:51:38 -050032 */
33#define _DPRINTK_FLAGS_PRINT (1<<0) /* printk() a message using the format */
Bart Van Assche8ba6ebf2011-01-23 17:17:24 +010034#define _DPRINTK_FLAGS_INCL_MODNAME (1<<1)
35#define _DPRINTK_FLAGS_INCL_FUNCNAME (1<<2)
36#define _DPRINTK_FLAGS_INCL_LINENO (1<<3)
37#define _DPRINTK_FLAGS_INCL_TID (1<<4)
Jason Barone9d376f2009-02-05 11:51:38 -050038#define _DPRINTK_FLAGS_DEFAULT 0
39 unsigned int flags:8;
Jason Baron52159d92010-09-17 11:09:17 -040040 char enabled;
Jason Barone9d376f2009-02-05 11:51:38 -050041} __attribute__((aligned(8)));
42
43
44int ddebug_add_module(struct _ddebug *tab, unsigned int n,
45 const char *modname);
46
47#if defined(CONFIG_DYNAMIC_DEBUG)
Yehuda Sadehff49d742010-07-03 13:07:35 +100048extern int ddebug_remove_module(const char *mod_name);
Bart Van Assche8ba6ebf2011-01-23 17:17:24 +010049extern int __dynamic_pr_debug(struct _ddebug *descriptor, const char *fmt, ...)
50 __attribute__ ((format (printf, 2, 3)));
Jason Barone9d376f2009-02-05 11:51:38 -050051
Jason Barone9d376f2009-02-05 11:51:38 -050052#define dynamic_pr_debug(fmt, ...) do { \
53 static struct _ddebug descriptor \
54 __used \
55 __attribute__((section("__verbose"), aligned(8))) = \
Jason Baron52159d92010-09-17 11:09:17 -040056 { KBUILD_MODNAME, __func__, __FILE__, fmt, __LINE__, \
57 _DPRINTK_FLAGS_DEFAULT }; \
Jason Baron2d75af22011-01-07 13:36:58 -050058 if (unlikely(descriptor.enabled)) \
Bart Van Assche8ba6ebf2011-01-23 17:17:24 +010059 __dynamic_pr_debug(&descriptor, pr_fmt(fmt), ##__VA_ARGS__); \
Jason Barone9d376f2009-02-05 11:51:38 -050060 } while (0)
61
62
63#define dynamic_dev_dbg(dev, fmt, ...) do { \
64 static struct _ddebug descriptor \
65 __used \
66 __attribute__((section("__verbose"), aligned(8))) = \
Jason Baron52159d92010-09-17 11:09:17 -040067 { KBUILD_MODNAME, __func__, __FILE__, fmt, __LINE__, \
68 _DPRINTK_FLAGS_DEFAULT }; \
Jason Baron2d75af22011-01-07 13:36:58 -050069 if (unlikely(descriptor.enabled)) \
70 dev_printk(KERN_DEBUG, dev, fmt, ##__VA_ARGS__); \
Jason Barone9d376f2009-02-05 11:51:38 -050071 } while (0)
72
73#else
74
Yehuda Sadehff49d742010-07-03 13:07:35 +100075static inline int ddebug_remove_module(const char *mod)
Jason Barone9d376f2009-02-05 11:51:38 -050076{
77 return 0;
78}
79
Joe Perches00b55862009-12-14 18:00:14 -080080#define dynamic_pr_debug(fmt, ...) \
81 do { if (0) printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__); } while (0)
Philipp Reisnerbe70e262010-10-14 11:58:20 +020082#define dynamic_dev_dbg(dev, fmt, ...) \
Joe Perches00b55862009-12-14 18:00:14 -080083 do { if (0) dev_printk(KERN_DEBUG, dev, fmt, ##__VA_ARGS__); } while (0)
Jason Barone9d376f2009-02-05 11:51:38 -050084#endif
85
86#endif