dynamic_debug.h 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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. char primary_hash;
  24. char secondary_hash;
  25. unsigned int lineno:24;
  26. /*
  27. * The flags field controls the behaviour at the callsite.
  28. * The bits here are changed dynamically when the user
  29. * writes commands to <debugfs>/dynamic_debug/ddebug
  30. */
  31. #define _DPRINTK_FLAGS_PRINT (1<<0) /* printk() a message using the format */
  32. #define _DPRINTK_FLAGS_DEFAULT 0
  33. unsigned int flags:8;
  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(char *mod_name);
  39. #define __dynamic_dbg_enabled(dd) ({ \
  40. int __ret = 0; \
  41. if (unlikely((dynamic_debug_enabled & (1LL << DEBUG_HASH)) && \
  42. (dynamic_debug_enabled2 & (1LL << DEBUG_HASH2)))) \
  43. if (unlikely(dd.flags)) \
  44. __ret = 1; \
  45. __ret; })
  46. #define dynamic_pr_debug(fmt, ...) do { \
  47. static struct _ddebug descriptor \
  48. __used \
  49. __attribute__((section("__verbose"), aligned(8))) = \
  50. { KBUILD_MODNAME, __func__, __FILE__, fmt, DEBUG_HASH, \
  51. DEBUG_HASH2, __LINE__, _DPRINTK_FLAGS_DEFAULT }; \
  52. if (__dynamic_dbg_enabled(descriptor)) \
  53. printk(KERN_DEBUG KBUILD_MODNAME ":" fmt, \
  54. ##__VA_ARGS__); \
  55. } while (0)
  56. #define dynamic_dev_dbg(dev, fmt, ...) do { \
  57. static struct _ddebug descriptor \
  58. __used \
  59. __attribute__((section("__verbose"), aligned(8))) = \
  60. { KBUILD_MODNAME, __func__, __FILE__, fmt, DEBUG_HASH, \
  61. DEBUG_HASH2, __LINE__, _DPRINTK_FLAGS_DEFAULT }; \
  62. if (__dynamic_dbg_enabled(descriptor)) \
  63. dev_printk(KERN_DEBUG, dev, \
  64. KBUILD_MODNAME ": " fmt, \
  65. ##__VA_ARGS__); \
  66. } while (0)
  67. #else
  68. static inline int ddebug_remove_module(char *mod)
  69. {
  70. return 0;
  71. }
  72. #define dynamic_pr_debug(fmt, ...) do { } while (0)
  73. #define dynamic_dev_dbg(dev, format, ...) do { } while (0)
  74. #endif
  75. #endif