dynamic_debug.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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. __label__ do_printk; \
  41. __label__ out; \
  42. static struct _ddebug descriptor \
  43. __used \
  44. __attribute__((section("__verbose"), aligned(8))) = \
  45. { KBUILD_MODNAME, __func__, __FILE__, fmt, __LINE__, \
  46. _DPRINTK_FLAGS_DEFAULT }; \
  47. JUMP_LABEL(&descriptor.enabled, do_printk); \
  48. goto out; \
  49. do_printk: \
  50. printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__); \
  51. out: ; \
  52. } while (0)
  53. #define dynamic_dev_dbg(dev, fmt, ...) do { \
  54. __label__ do_printk; \
  55. __label__ out; \
  56. static struct _ddebug descriptor \
  57. __used \
  58. __attribute__((section("__verbose"), aligned(8))) = \
  59. { KBUILD_MODNAME, __func__, __FILE__, fmt, __LINE__, \
  60. _DPRINTK_FLAGS_DEFAULT }; \
  61. JUMP_LABEL(&descriptor.enabled, do_printk); \
  62. goto out; \
  63. do_printk: \
  64. dev_printk(KERN_DEBUG, dev, fmt, ##__VA_ARGS__); \
  65. out: ; \
  66. } while (0)
  67. #else
  68. static inline int ddebug_remove_module(const char *mod)
  69. {
  70. return 0;
  71. }
  72. #define dynamic_pr_debug(fmt, ...) \
  73. do { if (0) printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__); } while (0)
  74. #define dynamic_dev_dbg(dev, format, ...) \
  75. do { if (0) dev_printk(KERN_DEBUG, dev, fmt, ##__VA_ARGS__); } while (0)
  76. #endif
  77. #endif