Differences
This shows you the differences between two versions of the page.
| Both sides previous revision Previous revision Next revision | Previous revision | ||
| printing_debugging [2018/09/25 12:50] – [printk.h] rpjday | printing_debugging [2018/09/25 13:27] (current) – [__netdev_printk()] rpjday | ||
|---|---|---|---|
| Line 123: | Line 123: | ||
| #else | #else | ||
| - | static inline __printf(3, 0) | + | ... snip ... |
| - | int dev_vprintk_emit(int level, const struct device *dev, | + | |
| - | const char *fmt, va_list args) | + | |
| - | { return 0; } | + | |
| - | static inline __printf(3, 4) | + | |
| - | int dev_printk_emit(int level, const struct device *dev, const char *fmt, ...) | + | |
| - | { return 0; } | + | |
| - | + | ||
| - | static inline void __dev_printk(const char *level, const struct device *dev, | + | |
| - | struct va_format *vaf) | + | |
| - | {} | + | |
| - | static inline __printf(3, 4) | + | |
| - | void dev_printk(const char *level, const struct device *dev, | + | |
| - | const char *fmt, ...) | + | |
| - | {} | + | |
| - | + | ||
| - | static inline __printf(2, 3) | + | |
| - | void _dev_emerg(const struct device *dev, const char *fmt, ...) | + | |
| - | {} | + | |
| - | static inline __printf(2, 3) | + | |
| - | void _dev_crit(const struct device *dev, const char *fmt, ...) | + | |
| - | {} | + | |
| - | static inline __printf(2, 3) | + | |
| - | void _dev_alert(const struct device *dev, const char *fmt, ...) | + | |
| - | {} | + | |
| - | static inline __printf(2, 3) | + | |
| - | void _dev_err(const struct device *dev, const char *fmt, ...) | + | |
| - | {} | + | |
| - | static inline __printf(2, 3) | + | |
| - | void _dev_warn(const struct device *dev, const char *fmt, ...) | + | |
| - | {} | + | |
| - | static inline __printf(2, 3) | + | |
| - | void _dev_notice(const struct device *dev, const char *fmt, ...) | + | |
| - | {} | + | |
| - | static inline __printf(2, 3) | + | |
| - | void _dev_info(const struct device *dev, const char *fmt, ...) | + | |
| - | {} | + | |
| #endif | #endif | ||
| Line 178: | Line 142: | ||
| _dev_info(dev, | _dev_info(dev, | ||
| </ | </ | ||
| + | |||
| + | ==== drivers/ | ||
| + | |||
| + | === dev_printk() === | ||
| + | |||
| + | < | ||
| + | void dev_printk(const char *level, const struct device *dev, | ||
| + | const char *fmt, ...) | ||
| + | { | ||
| + | struct va_format vaf; | ||
| + | va_list args; | ||
| + | |||
| + | va_start(args, | ||
| + | |||
| + | vaf.fmt = fmt; | ||
| + | vaf.va = &args; | ||
| + | |||
| + | __dev_printk(level, | ||
| + | |||
| + | va_end(args); | ||
| + | } | ||
| + | EXPORT_SYMBOL(dev_printk); | ||
| + | </ | ||
| + | |||
| + | === __dev_printk() === | ||
| + | |||
| + | < | ||
| + | static void __dev_printk(const char *level, const struct device *dev, | ||
| + | struct va_format *vaf) | ||
| + | { | ||
| + | if (dev) | ||
| + | dev_printk_emit(level[1] - ' | ||
| + | dev_driver_string(dev), | ||
| + | else | ||
| + | printk(" | ||
| + | } | ||
| + | </ | ||
| + | |||
| + | === dev_printk_emit() === | ||
| + | |||
| + | < | ||
| + | int dev_printk_emit(int level, const struct device *dev, const char *fmt, ...) | ||
| + | { | ||
| + | va_list args; | ||
| + | int r; | ||
| + | |||
| + | va_start(args, | ||
| + | |||
| + | r = dev_vprintk_emit(level, | ||
| + | |||
| + | va_end(args); | ||
| + | |||
| + | return r; | ||
| + | } | ||
| + | EXPORT_SYMBOL(dev_printk_emit); | ||
| + | </ | ||
| + | |||
| + | === dev_vprintk_emit() === | ||
| + | |||
| + | < | ||
| + | int dev_vprintk_emit(int level, const struct device *dev, | ||
| + | const char *fmt, va_list args) | ||
| + | { | ||
| + | char hdr[128]; | ||
| + | size_t hdrlen; | ||
| + | |||
| + | hdrlen = create_syslog_header(dev, | ||
| + | |||
| + | return vprintk_emit(0, | ||
| + | } | ||
| + | </ | ||
| + | |||
| + | ===== netdev debugging (net/ | ||
| + | |||
| + | ==== Defining macros ==== | ||
| + | |||
| + | < | ||
| + | #define define_netdev_printk_level(func, | ||
| + | void func(const struct net_device *dev, const char *fmt, ...) \ | ||
| + | { \ | ||
| + | struct va_format vaf; \ | ||
| + | va_list args; \ | ||
| + | \ | ||
| + | va_start(args, | ||
| + | \ | ||
| + | vaf.fmt = fmt; \ | ||
| + | vaf.va = & | ||
| + | \ | ||
| + | __netdev_printk(level, | ||
| + | \ | ||
| + | va_end(args); | ||
| + | } \ | ||
| + | EXPORT_SYMBOL(func); | ||
| + | |||
| + | define_netdev_printk_level(netdev_emerg, | ||
| + | define_netdev_printk_level(netdev_alert, | ||
| + | define_netdev_printk_level(netdev_crit, | ||
| + | define_netdev_printk_level(netdev_err, | ||
| + | define_netdev_printk_level(netdev_warn, | ||
| + | define_netdev_printk_level(netdev_notice, | ||
| + | define_netdev_printk_level(netdev_info, | ||
| + | </ | ||
| + | |||
| + | ==== Alternate way of calling __netdev_printk() ==== | ||
| + | |||
| + | < | ||
| + | void netdev_printk(const char *level, const struct net_device *dev, | ||
| + | const char *format, ...) | ||
| + | { | ||
| + | struct va_format vaf; | ||
| + | va_list args; | ||
| + | |||
| + | va_start(args, | ||
| + | |||
| + | vaf.fmt = format; | ||
| + | vaf.va = &args; | ||
| + | |||
| + | __netdev_printk(level, | ||
| + | |||
| + | va_end(args); | ||
| + | } | ||
| + | EXPORT_SYMBOL(netdev_printk); | ||
| + | </ | ||
| + | |||
| + | ==== __netdev_printk() ==== | ||
| + | |||
| + | < | ||
| + | static void __netdev_printk(const char *level, const struct net_device *dev, | ||
| + | struct va_format *vaf) | ||
| + | { | ||
| + | if (dev && dev-> | ||
| + | dev_printk_emit(level[1] - ' | ||
| + | dev-> | ||
| + | "%s %s %s%s: %pV", | ||
| + | dev_driver_string(dev-> | ||
| + | dev_name(dev-> | ||
| + | netdev_name(dev), | ||
| + | vaf); | ||
| + | } else if (dev) { | ||
| + | printk(" | ||
| + | | ||
| + | } else { | ||
| + | printk(" | ||
| + | } | ||
| + | } | ||
| + | </ | ||
| + | |||
| + | ===== Dynamic debugging ===== | ||
| + | |||
| + | ... coming ... | ||