为 pr_debug 和 printk 设置 CFLAGS
我正在尝试了解 Linux 内核模块,并希望查看 pr_debug 和 printk 的输出。我正在使用 GNU Make。
我知道要获取 pr_debug 消息,我们必须使用 DDEBUG
。
那么,如何启用 printk
语句?
假设文件名是kvm.c
。这两者有什么区别:
CFLAGS_kvm.o := -DDEBUG
CFLAGS_kvm.o += -DDEBUG
这个语句有什么作用:
CFLAGS_kvm.o := -I.
[编辑]:
看起来我对方括号的使用引起了一些混乱。实际上,我所说的[文件名]是指一些文件,比如 kvm.c。
I am trying to understand a Linux kernel module and would like to see the output of pr_debug
and printk
. I am using GNU Make.
I understand that to get pr_debug messages, we have to use DDEBUG
.
So, how do I enable printk
statements ?
Lets say filename is kvm.c
. What is the difference between these two:
CFLAGS_kvm.o := -DDEBUG
CFLAGS_kvm.o += -DDEBUG
What does this statement do:
CFLAGS_kvm.o := -I.
[Edit]:
It looks like my usage of square brackets has caused some confusion. Actually by [filename], I meant some file, say kvm.c.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
来自
https://www.kernel.org/doc/local/pr_debug.txt
:From
https://www.kernel.org/doc/local/pr_debug.txt
:我不知道如何激活
printk()
- 您通过 Google 搜索了什么?除此之外,我发现这个 这似乎意味着printk()
几乎总是可用的(但是您必须使用适当的级别标记消息,并且可能可以控制控制台上显示的级别)。宏名称中的方括号是非正统的 - 因此可能是特定于您的系统的扩展。从字里行间看,您可能正在谈论 Linux 内核,因此也可能谈论 GNU Make,但是您如果你说出这样的事情,会对每个人都有帮助。
:=
表示法是对变量的立即赋值。 RHS 在读取和处理行时进行评估,而不是像通常情况那样在使用宏时进行评估。这意味着如果 RHS 上引用了宏,则随后对这些宏的更改不会影响该宏的值。考虑:第一个变体指出 CFLAGS 将由 4 个命名宏组成(实际上,它只是复制该行以供以后扩展),但在(大概)在 C 编译命令中使用它之前不会扩展这些值。
第二种变体在读取该行时立即查找 4 个宏的值并将其展开。 4 个引用宏的后续更改不会反映在 CFLAGS 中。
+=
符号将 RHS 添加到宏中,而不是简单地替换它。I don't know about how to activate
printk()
- what did you search for with Google? Amongst other things, I found this which seems to imply theprintk()
is almost always available (but you have to mark the messages with an appropriate level, and there is probably a control over which levels are displayed on the console).The square brackets in a macro name are unorthodox - and therefore probably an extension specific to your system.Reading between the lines, it is likely that you are talking about the Linux kernel and therefore GNU Make, but you'd help everyone if you stated such things.
The
:=
notation is an immediate assignment to the variable. The RHS is evaluated when the line is read and processed, not when the macro is used as is normally the case. It means that if there are macros referenced on the RHS, subsequent changes to those macros will not affect the value of this macro. Consider:The first variation notes that CFLAGS will be formed from the 4 named macros (well, actually, it simply copies the line ready for later expansion), but does not expand the values until it is used in (presumably) a C compilation command.
The second variation immediately looks for the values of the 4 macros at the time when the line is read and expands them out. Subsequent changes in the 4 referenced macros are not reflected in CFLAGS.
The
+=
notation adds the RHS to the macro, rather than simply replacing it.