Setting CFLAGS for pr_debug and printk
Asked Answered
M

2

6

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.

Milamilady answered 26/2, 2011 at 11:35 Comment(2)
Umm... is this in a makefile? A shell script?Kiosk
Its a makefile. I have corrected the question.Milamilady
D
1

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 the printk() 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:

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

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.

Demijohn answered 26/2, 2011 at 18:53 Comment(1)
Thanks. And, sorry, there are no square brackets. I have corrected the question.Milamilady
G
4

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.
Goodish answered 11/3, 2014 at 17:8 Comment(0)
D
1

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 the printk() 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:

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

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.

Demijohn answered 26/2, 2011 at 18:53 Comment(1)
Thanks. And, sorry, there are no square brackets. I have corrected the question.Milamilady

© 2022 - 2024 — McMap. All rights reserved.