Setting CFLAGS for pr_debug and printk

I am trying to understand the Linux kernel module and would like to see the output of pr_debug and pr_debug . I am using GNU Make.
I understand that to receive pr_debug messages, we must use DDEBUG .

So how do you enable printk instructions?

Suppose the file name is kvm.c What is the difference between the two:

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

What this operator does:

  CFLAGS_kvm.o := -I. 

[Change]:
It seems my use of square brackets has caused some confusion. In fact, by [filename], I meant some file, say kvm.c.

+6
makefile printf-debugging printk
source share
2 answers

I don’t know how to activate printk() - what were you looking for on Google? Among other things, I found this one , which apparently implies that printk() almost always available (but you should note messages with the appropriate level, and there is probably control over which levels are displayed on the console).

The square brackets in the macro name are unorthodox - and therefore probably the 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 would help everyone if you said such things.

Designation := is the direct assignment of a variable. RHS is evaluated when a string is read and processed, and not when a macro is used, as is usually the case. This means that if macros are specified in RHS, subsequent changes to these macros will not affect the value of this macro. Consider:

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

The first option states that CFLAGS will be formed from the 4 named macros (well, in fact, it simply copies the line ready for further expansion), but does not expand the values ​​until the (presumably) compilation of the C command is used.

The second variation immediately looks for the values ​​of 4 macros at the moment of reading the line and expands it. Subsequent changes to 4 related macros are not reflected in CFLAGS.

The designation += adds RHS to the macro, not just replacing it.

+1
source share

From 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. 
+4
source share

All Articles