为pr_debug和printk设置CFLAGS

时间:2011-02-26 11:35:15

标签: makefile printf-debugging printk

我正在尝试了解Linux内核模块,并希望看到pr_debugprintk的输出。我正在使用GNU Make 我了解要收到pr_debug条消息,我们必须使用DDEBUG

那么,如何启用printk语句?

假设文件名为kvm.c。这两者有什么区别:

      CFLAGS_kvm.o := -DDEBUG
      CFLAGS_kvm.o += -DDEBUG

这句话的作用是什么:

      CFLAGS_kvm.o := -I.

[编辑]:
 看起来我使用方括号引起了一些混乱。实际上通过[filename],我的意思是一些文件,比如说kvm.c。

2 个答案:

答案 0 :(得分:4)

来自https://www.kernel.org/doc/local/pr_debug.txt

pr_debug()

Some files call pr_debug(), which is ordinarily an empty macro that discards
its arguments at compile time.  To enable debugging output, build the
appropriate file with -DDEBUG by adding

  CFLAGS_[filename].o := -DDEBUG

to the makefile.

For example, to see all attempts to spawn a usermode helper (such as
/sbin/hotplug), add to lib/Makefile the line:

    CFLAGS_kobject_uevent.o := -DDEBUG

Then boot the new kernel, do something that spawns a usermode helper, and
use the "dmesg" command to view the pr_debug() output.

答案 1 :(得分:1)

我不知道如何激活printk() - 你用Google搜索了什么?除此之外,我发现this似乎暗示printk()几乎总是可用的(但你必须用适当的级别来标记消息,并且可能控制哪些级别显示在控制台)。

宏名称中的方括号是非正统的 - 因此可能是特定于您系统的扩展名。

在这些内容之间进行阅读,很可能是你在讨论Linux内核,因此也就是GNU Make,但如果你说出这些内容,你会帮助所有人。

:=表示法是对变量的立即赋值。读取和处理行时评估RHS,而不是通常情况下使用宏时评估RHS。这意味着如果RHS上引用了宏,则对这些宏的后续更改不会影响此宏的值。考虑:

CFLAGS  = ${OFLAGS} ${IFLAGS} ${DFLAGS} ${WFLAGS}
CFLAGS := ${OFLAGS} ${IFLAGS} ${DFLAGS} ${WFLAGS}

第一个变体注意到CFLAGS将由4个命名的宏组成(实际上,它只是复制准备好以后扩展的行),但是在它被用于(可能是)C编译之前不会扩展值。命令。

第二个变体会在读取行时立即查找4个宏的值并将其展开。 4个引用宏的后续更改不会反映在CFLAGS中。

+=表示法将RHS添加到宏中,而不是简单地替换它。