dynamic_debug.h 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. #ifndef _DYNAMIC_DEBUG_H
  2. #define _DYNAMIC_DEBUG_H
  3. #include <linux/jump_label.h>
  4. /* dynamic_printk_enabled, and dynamic_printk_enabled2 are bitmasks in which
  5. * bit n is set to 1 if any modname hashes into the bucket n, 0 otherwise. They
  6. * use independent hash functions, to reduce the chance of false positives.
  7. */
  8. extern long long dynamic_debug_enabled;
  9. extern long long dynamic_debug_enabled2;
  10. /*
  11. * An instance of this structure is created in a special
  12. * ELF section at every dynamic debug callsite. At runtime,
  13. * the special section is treated as an array of these.
  14. */
  15. struct _ddebug {
  16. /*
  17. * These fields are used to drive the user interface
  18. * for selecting and displaying debug callsites.
  19. */
  20. const char *modname;
  21. const char *function;
  22. const char *filename;
  23. const char *format;
  24. unsigned int lineno:24;
  25. /*
  26. * The flags field controls the behaviour at the callsite.
  27. * The bits here are changed dynamically when the user
  28. * writes commands to <debugfs>/dynamic_debug/control
  29. */
  30. #define _DPRINTK_FLAGS_PRINT (1<<0) /* printk() a message using the format */
  31. #define _DPRINTK_FLAGS_INCL_MODNAME (1<<1)
  32. #define _DPRINTK_FLAGS_INCL_FUNCNAME (1<<2)
  33. #define _DPRINTK_FLAGS_INCL_LINENO (1<<3)
  34. #define _DPRINTK_FLAGS_INCL_TID (1<<4)
  35. #define _DPRINTK_FLAGS_DEFAULT 0
  36. unsigned int flags:8;
  37. char enabled;
  38. } __attribute__((aligned(8)));
  39. int ddebug_add_module(struct _ddebug *tab, unsigned int n,
  40. const char *modname);
  41. #if defined(CONFIG_DYNAMIC_DEBUG)
  42. extern int ddebug_remove_module(const char *mod_name);
  43. extern int __dynamic_pr_debug(struct _ddebug *descriptor, const char *fmt, ...)
  44. __attribute__ ((format (printf, 2, 3)));
  45. #define dynamic_pr_debug(fmt, ...) do { \
  46. static struct _ddebug descriptor \
  47. __used \
  48. __attribute__((section("__verbose"), aligned(8))) = \
  49. { KBUILD_MODNAME, __func__, __FILE__, fmt, __LINE__, \
  50. _DPRINTK_FLAGS_DEFAULT }; \
  51. if (unlikely(descriptor.enabled)) \
  52. __dynamic_pr_debug(&descriptor, pr_fmt(fmt), ##__VA_ARGS__); \
  53. } while (0)
  54. #define dynamic_dev_dbg(dev, fmt, ...) do { \
  55. static struct _ddebug descriptor \
  56. __used \
  57. __attribute__((section("__verbose"), aligned(8))) = \
  58. { KBUILD_MODNAME, __func__, __FILE__, fmt, __LINE__, \
  59. _DPRINTK_FLAGS_DEFAULT }; \
  60. if (unlikely(descriptor.enabled)) \
  61. dev_printk(KERN_DEBUG, dev, fmt, ##__VA_ARGS__); \
  62. } while (0)
  63. #else
  64. static inline int ddebug_remove_module(const char *mod)
  65. {
  66. return 0;
  67. }
  68. #define dynamic_pr_debug(fmt, ...) \
  69. do { if (0) printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__); } while (0)
  70. #define dynamic_dev_dbg(dev, fmt, ...) \
  71. do { if (0) dev_printk(KERN_DEBUG, dev, fmt, ##__VA_ARGS__); } while (0)
  72. #endif
  73. #endif