dynamic_debug.h 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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_DEFAULT 0
  32. unsigned int flags:8;
  33. char enabled;
  34. } __attribute__((aligned(8)));
  35. int ddebug_add_module(struct _ddebug *tab, unsigned int n,
  36. const char *modname);
  37. #if defined(CONFIG_DYNAMIC_DEBUG)
  38. extern int ddebug_remove_module(const char *mod_name);
  39. #define dynamic_pr_debug(fmt, ...) do { \
  40. static struct _ddebug descriptor \
  41. __used \
  42. __attribute__((section("__verbose"), aligned(8))) = \
  43. { KBUILD_MODNAME, __func__, __FILE__, fmt, __LINE__, \
  44. _DPRINTK_FLAGS_DEFAULT }; \
  45. if (unlikely(descriptor.enabled)) \
  46. printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__); \
  47. } while (0)
  48. #define dynamic_dev_dbg(dev, fmt, ...) do { \
  49. static struct _ddebug descriptor \
  50. __used \
  51. __attribute__((section("__verbose"), aligned(8))) = \
  52. { KBUILD_MODNAME, __func__, __FILE__, fmt, __LINE__, \
  53. _DPRINTK_FLAGS_DEFAULT }; \
  54. if (unlikely(descriptor.enabled)) \
  55. dev_printk(KERN_DEBUG, dev, fmt, ##__VA_ARGS__); \
  56. } while (0)
  57. #else
  58. static inline int ddebug_remove_module(const char *mod)
  59. {
  60. return 0;
  61. }
  62. #define dynamic_pr_debug(fmt, ...) \
  63. do { if (0) printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__); } while (0)
  64. #define dynamic_dev_dbg(dev, fmt, ...) \
  65. do { if (0) dev_printk(KERN_DEBUG, dev, fmt, ##__VA_ARGS__); } while (0)
  66. #endif
  67. #endif