1e9d376f0SJason Baron #ifndef _DYNAMIC_DEBUG_H 2e9d376f0SJason Baron #define _DYNAMIC_DEBUG_H 3e9d376f0SJason Baron 4e9d376f0SJason Baron /* dynamic_printk_enabled, and dynamic_printk_enabled2 are bitmasks in which 5e9d376f0SJason Baron * bit n is set to 1 if any modname hashes into the bucket n, 0 otherwise. They 6e9d376f0SJason Baron * use independent hash functions, to reduce the chance of false positives. 7e9d376f0SJason Baron */ 8e9d376f0SJason Baron extern long long dynamic_debug_enabled; 9e9d376f0SJason Baron extern long long dynamic_debug_enabled2; 10e9d376f0SJason Baron 11e9d376f0SJason Baron /* 12e9d376f0SJason Baron * An instance of this structure is created in a special 13e9d376f0SJason Baron * ELF section at every dynamic debug callsite. At runtime, 14e9d376f0SJason Baron * the special section is treated as an array of these. 15e9d376f0SJason Baron */ 16e9d376f0SJason Baron struct _ddebug { 17e9d376f0SJason Baron /* 18e9d376f0SJason Baron * These fields are used to drive the user interface 19e9d376f0SJason Baron * for selecting and displaying debug callsites. 20e9d376f0SJason Baron */ 21e9d376f0SJason Baron const char *modname; 22e9d376f0SJason Baron const char *function; 23e9d376f0SJason Baron const char *filename; 24e9d376f0SJason Baron const char *format; 25e9d376f0SJason Baron unsigned int lineno:24; 26e9d376f0SJason Baron /* 27e9d376f0SJason Baron * The flags field controls the behaviour at the callsite. 28e9d376f0SJason Baron * The bits here are changed dynamically when the user 292b2f68b5SFlorian Ragwitz * writes commands to <debugfs>/dynamic_debug/control 30e9d376f0SJason Baron */ 31e9d376f0SJason Baron #define _DPRINTK_FLAGS_PRINT (1<<0) /* printk() a message using the format */ 328ba6ebf5SBart Van Assche #define _DPRINTK_FLAGS_INCL_MODNAME (1<<1) 338ba6ebf5SBart Van Assche #define _DPRINTK_FLAGS_INCL_FUNCNAME (1<<2) 348ba6ebf5SBart Van Assche #define _DPRINTK_FLAGS_INCL_LINENO (1<<3) 358ba6ebf5SBart Van Assche #define _DPRINTK_FLAGS_INCL_TID (1<<4) 36e9d376f0SJason Baron #define _DPRINTK_FLAGS_DEFAULT 0 37e9d376f0SJason Baron unsigned int flags:8; 3852159d98SJason Baron char enabled; 39e9d376f0SJason Baron } __attribute__((aligned(8))); 40e9d376f0SJason Baron 41e9d376f0SJason Baron 42e9d376f0SJason Baron int ddebug_add_module(struct _ddebug *tab, unsigned int n, 43e9d376f0SJason Baron const char *modname); 44e9d376f0SJason Baron 45e9d376f0SJason Baron #if defined(CONFIG_DYNAMIC_DEBUG) 46ff49d74aSYehuda Sadeh extern int ddebug_remove_module(const char *mod_name); 478ba6ebf5SBart Van Assche extern int __dynamic_pr_debug(struct _ddebug *descriptor, const char *fmt, ...) 488ba6ebf5SBart Van Assche __attribute__ ((format (printf, 2, 3))); 49e9d376f0SJason Baron 50*cbc46635SJoe Perches struct device; 51*cbc46635SJoe Perches 52*cbc46635SJoe Perches extern int __dynamic_dev_dbg(struct _ddebug *descriptor, 53*cbc46635SJoe Perches const struct device *dev, 54*cbc46635SJoe Perches const char *fmt, ...) 55*cbc46635SJoe Perches __attribute__ ((format (printf, 3, 4))); 56*cbc46635SJoe Perches 57e9d376f0SJason Baron #define dynamic_pr_debug(fmt, ...) do { \ 58e9d376f0SJason Baron static struct _ddebug descriptor \ 59e9d376f0SJason Baron __used \ 60e9d376f0SJason Baron __attribute__((section("__verbose"), aligned(8))) = \ 6152159d98SJason Baron { KBUILD_MODNAME, __func__, __FILE__, fmt, __LINE__, \ 6252159d98SJason Baron _DPRINTK_FLAGS_DEFAULT }; \ 632d75af2fSJason Baron if (unlikely(descriptor.enabled)) \ 648ba6ebf5SBart Van Assche __dynamic_pr_debug(&descriptor, pr_fmt(fmt), ##__VA_ARGS__); \ 65e9d376f0SJason Baron } while (0) 66e9d376f0SJason Baron 67e9d376f0SJason Baron #define dynamic_dev_dbg(dev, fmt, ...) do { \ 68e9d376f0SJason Baron static struct _ddebug descriptor \ 69e9d376f0SJason Baron __used \ 70e9d376f0SJason Baron __attribute__((section("__verbose"), aligned(8))) = \ 7152159d98SJason Baron { KBUILD_MODNAME, __func__, __FILE__, fmt, __LINE__, \ 7252159d98SJason Baron _DPRINTK_FLAGS_DEFAULT }; \ 732d75af2fSJason Baron if (unlikely(descriptor.enabled)) \ 74*cbc46635SJoe Perches __dynamic_dev_dbg(&descriptor, dev, fmt, ##__VA_ARGS__); \ 75e9d376f0SJason Baron } while (0) 76e9d376f0SJason Baron 77e9d376f0SJason Baron #else 78e9d376f0SJason Baron 79ff49d74aSYehuda Sadeh static inline int ddebug_remove_module(const char *mod) 80e9d376f0SJason Baron { 81e9d376f0SJason Baron return 0; 82e9d376f0SJason Baron } 83e9d376f0SJason Baron 8400b55864SJoe Perches #define dynamic_pr_debug(fmt, ...) \ 8500b55864SJoe Perches do { if (0) printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__); } while (0) 86be70e267SPhilipp Reisner #define dynamic_dev_dbg(dev, fmt, ...) \ 8700b55864SJoe Perches do { if (0) dev_printk(KERN_DEBUG, dev, fmt, ##__VA_ARGS__); } while (0) 88e9d376f0SJason Baron #endif 89e9d376f0SJason Baron 90e9d376f0SJason Baron #endif 91