dynamic_debug.h 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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:24;
  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_PRINT (1<<0) /* printk() a message using the format */
  24. #define _DPRINTK_FLAGS_INCL_MODNAME (1<<1)
  25. #define _DPRINTK_FLAGS_INCL_FUNCNAME (1<<2)
  26. #define _DPRINTK_FLAGS_INCL_LINENO (1<<3)
  27. #define _DPRINTK_FLAGS_INCL_TID (1<<4)
  28. #define _DPRINTK_FLAGS_DEFAULT 0
  29. unsigned int flags:8;
  30. char enabled;
  31. } __attribute__((aligned(8)));
  32. int ddebug_add_module(struct _ddebug *tab, unsigned int n,
  33. const char *modname);
  34. #if defined(CONFIG_DYNAMIC_DEBUG)
  35. extern int ddebug_remove_module(const char *mod_name);
  36. extern int __dynamic_pr_debug(struct _ddebug *descriptor, const char *fmt, ...)
  37. __attribute__ ((format (printf, 2, 3)));
  38. struct device;
  39. extern int __dynamic_dev_dbg(struct _ddebug *descriptor,
  40. const struct device *dev,
  41. const char *fmt, ...)
  42. __attribute__ ((format (printf, 3, 4)));
  43. #define dynamic_pr_debug(fmt, ...) do { \
  44. static struct _ddebug descriptor \
  45. __used \
  46. __attribute__((section("__verbose"), aligned(8))) = \
  47. { KBUILD_MODNAME, __func__, __FILE__, fmt, __LINE__, \
  48. _DPRINTK_FLAGS_DEFAULT }; \
  49. if (unlikely(descriptor.enabled)) \
  50. __dynamic_pr_debug(&descriptor, pr_fmt(fmt), ##__VA_ARGS__); \
  51. } while (0)
  52. #define dynamic_dev_dbg(dev, fmt, ...) do { \
  53. static struct _ddebug descriptor \
  54. __used \
  55. __attribute__((section("__verbose"), aligned(8))) = \
  56. { KBUILD_MODNAME, __func__, __FILE__, fmt, __LINE__, \
  57. _DPRINTK_FLAGS_DEFAULT }; \
  58. if (unlikely(descriptor.enabled)) \
  59. __dynamic_dev_dbg(&descriptor, dev, fmt, ##__VA_ARGS__); \
  60. } while (0)
  61. #else
  62. static inline int ddebug_remove_module(const char *mod)
  63. {
  64. return 0;
  65. }
  66. #define dynamic_pr_debug(fmt, ...) \
  67. do { if (0) printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__); } while (0)
  68. #define dynamic_dev_dbg(dev, fmt, ...) \
  69. do { if (0) dev_printk(KERN_DEBUG, dev, fmt, ##__VA_ARGS__); } while (0)
  70. #endif
  71. #endif