您的位置:首页 > 运维架构 > Linux

uclinux内核的console(6):调试信息输出

2009-03-19 11:14 507 查看
快乐虾 http://blog.csdn.net/lights_joy/ lights@hb165.com

本文适用于
ADI bf561 DSP
优视BF561EVB开发板
uclinux-2008r1.5-rc3 (smp patch)
Visual DSP++ 5.0 (update 5)

欢迎转载,但请保留作者信息



在内核调试时通常要输出一些信息,这些信息的输出通常由一些宏来控制,下面列举内核中用到的几个宏:

1.1 pr_debug

这个宏定义为:
#ifdef DEBUG
/* If you are writing a driver, please use dev_dbg instead */
#define pr_debug(fmt,arg...) /
printk(KERN_DEBUG fmt,##arg)
#else
static /*inline*/ int __attribute__ ((format (printf, 1, 2))) pr_debug(const char * fmt, ...)
{
return 0;
}
#endif
要想输出pr_debug中的信息,首先要求定义DEBUG宏。此外由于它使用了KERN_DEBUG这一输出级别,还必须在内核参数中使用ignore_loglevel。再不然就直接修改pr_debug的定义!
和pr_debug在一起的还有一个叫pr_info的宏,这个宏总能输出信息:
#define pr_info(fmt,arg...) /
printk(KERN_INFO fmt,##arg)

1.2 dev_dbg

这个宏定义为:
#define dev_printk(level, dev, format, arg...) /
printk(level "%s %s: " format , dev_driver_string(dev) , (dev)->bus_id , ## arg)

#ifdef DEBUG
#define dev_dbg(dev, format, arg...) /
dev_printk(KERN_DEBUG , dev , format , ## arg)
#else
static /*inline*/ int __attribute__ ((format (printf, 2, 3)))
dev_dbg(struct device * dev, const char * fmt, ...)
{
return 0;
}
#endif
同样,要想输出dev_dbg中的信息,首先要求定义DEBUG宏。此外由于它使用了KERN_DEBUG这一输出级别,还必须在内核参数中使用ignore_loglevel。再不然就直接修改它的定义!
使用这个宏的好处在于它可以输出驱动或者相关信息的名称:
/**
* dev_driver_string - Return a device's driver name, if at all possible
* @dev: struct device to get the name of
*
* Will return the device's driver's name if it is bound to a device. If
* the device is not bound to a device, it will return the name of the bus
* it is attached to. If it is not attached to a bus either, an empty
* string will be returned.
*/
const char *dev_driver_string(struct device *dev)
{
return dev->driver ? dev->driver->name :
(dev->bus ? dev->bus->name :
(dev->class ? dev->class->name : ""));
}
其实意义不是很大。
还有几个相似的宏:
#define dev_err(dev, format, arg...) /
dev_printk(KERN_ERR , dev , format , ## arg)
#define dev_info(dev, format, arg...) /
dev_printk(KERN_INFO , dev , format , ## arg)
#define dev_warn(dev, format, arg...) /
dev_printk(KERN_WARNING , dev , format , ## arg)
#define dev_notice(dev, format, arg...) /
dev_printk(KERN_NOTICE , dev , format , ## arg)
只是其输出级别不一样而已。

1.3 dprintk

这个宏没什么广泛影响,因为它只定义在个别的c文件里面,其影响只局限在它所在的.c文件。估计是dprintk这个名称比较受欢迎,所以拥有不少的fans。
比如在saa711x.c这个驱动中就是这样定义它的:
#define dprintk(num, format, args...) /
do { /
if (debug >= num) /
printk(format, ##args); /
} while (0)
再想偷懒的就这样定义:
#if DEBUG > 1
#define dprintk printk
#else
#define dprintk(x...) do { ; } while (0)
#endif
哈哈!

1 参考资料

uclinux内核的console(1):数据结构(2009-1-31)
uclinux内核的console(2):early console(2009-1-31)
uclinux内核的console(3):console驱动初始化(2009-1-31)
uclinux内核的console(4):通过console输出信息(2009-1-31)
uclinux内核的console(5):printk相关的内核参数(2009-3-19)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: