dynamic_debug.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. #ifndef _DYNAMIC_DEBUG_H
  2. #define _DYNAMIC_DEBUG_H
  3. /*
  4. * An instance of this structure is created in a special
  5. * ELF section at every dynamic debug callsite. At runtime,
  6. * the special section is treated as an array of these.
  7. */
  8. struct _ddebug {
  9. /*
  10. * These fields are used to drive the user interface
  11. * for selecting and displaying debug callsites.
  12. */
  13. const char *modname;
  14. const char *function;
  15. const char *filename;
  16. const char *format;
  17. unsigned int lineno:18;
  18. /*
  19. * The flags field controls the behaviour at the callsite.
  20. * The bits here are changed dynamically when the user
  21. * writes commands to <debugfs>/dynamic_debug/control
  22. */
  23. #define _DPRINTK_FLAGS_NONE 0
  24. #define _DPRINTK_FLAGS_PRINT (1<<0) /* printk() a message using the format */
  25. #define _DPRINTK_FLAGS_INCL_MODNAME (1<<1)
  26. #define _DPRINTK_FLAGS_INCL_FUNCNAME (1<<2)
  27. #define _DPRINTK_FLAGS_INCL_LINENO (1<<3)
  28. #define _DPRINTK_FLAGS_INCL_TID (1<<4)
  29. #if defined DEBUG
  30. #define _DPRINTK_FLAGS_DEFAULT _DPRINTK_FLAGS_PRINT
  31. #else
  32. #define _DPRINTK_FLAGS_DEFAULT 0
  33. #endif
  34. unsigned int flags:8;
  35. } __attribute__((aligned(8)));
  36. int ddebug_add_module(struct _ddebug *tab, unsigned int n,
  37. const char *modname);
  38. #if defined(CONFIG_DYNAMIC_DEBUG)
  39. extern int ddebug_remove_module(const char *mod_name);
  40. extern __printf(2, 3)
  41. int __dynamic_pr_debug(struct _ddebug *descriptor, const char *fmt, ...);
  42. struct device;
  43. extern __printf(3, 4)
  44. int __dynamic_dev_dbg(struct _ddebug *descriptor, const struct device *dev,
  45. const char *fmt, ...);
  46. struct net_device;
  47. extern __printf(3, 4)
  48. int __dynamic_netdev_dbg(struct _ddebug *descriptor,
  49. const struct net_device *dev,
  50. const char *fmt, ...);
  51. #define DEFINE_DYNAMIC_DEBUG_METADATA(name, fmt) \
  52. static struct _ddebug __used __aligned(8) \
  53. __attribute__((section("__verbose"))) name = { \
  54. .modname = KBUILD_MODNAME, \
  55. .function = __func__, \
  56. .filename = __FILE__, \
  57. .format = (fmt), \
  58. .lineno = __LINE__, \
  59. .flags = _DPRINTK_FLAGS_DEFAULT, \
  60. }
  61. #define dynamic_pr_debug(fmt, ...) \
  62. do { \
  63. DEFINE_DYNAMIC_DEBUG_METADATA(descriptor, fmt); \
  64. if (unlikely(descriptor.flags & _DPRINTK_FLAGS_PRINT)) \
  65. __dynamic_pr_debug(&descriptor, pr_fmt(fmt), \
  66. ##__VA_ARGS__); \
  67. } while (0)
  68. #define dynamic_dev_dbg(dev, fmt, ...) \
  69. do { \
  70. DEFINE_DYNAMIC_DEBUG_METADATA(descriptor, fmt); \
  71. if (unlikely(descriptor.flags & _DPRINTK_FLAGS_PRINT)) \
  72. __dynamic_dev_dbg(&descriptor, dev, fmt, \
  73. ##__VA_ARGS__); \
  74. } while (0)
  75. #define dynamic_netdev_dbg(dev, fmt, ...) \
  76. do { \
  77. DEFINE_DYNAMIC_DEBUG_METADATA(descriptor, fmt); \
  78. if (unlikely(descriptor.flags & _DPRINTK_FLAGS_PRINT)) \
  79. __dynamic_netdev_dbg(&descriptor, dev, fmt, \
  80. ##__VA_ARGS__); \
  81. } while (0)
  82. #else
  83. static inline int ddebug_remove_module(const char *mod)
  84. {
  85. return 0;
  86. }
  87. #define dynamic_pr_debug(fmt, ...) \
  88. do { if (0) printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__); } while (0)
  89. #define dynamic_dev_dbg(dev, fmt, ...) \
  90. do { if (0) dev_printk(KERN_DEBUG, dev, fmt, ##__VA_ARGS__); } while (0)
  91. #endif
  92. #endif