dynamic_debug.h 2.6 KB

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