Solved printf statements in kernel, silly question...

Hi All,

I noticed in /usr/src/sys/nfs/bootp_subr.c there are a large number of printf statements. For example
Code:
printf("Interface list:\n");
I have never really looked at the kernel code much before, and a thought occured to help me work out what is going wrong with my other current issue.

Silly question, maybe a 101 question, and I'll get asked to leave the room, but where exactly do the printf statements get printed to? In a normal c-style binary, they get printed to the active console, but I am not seeing any of these 'printf' statements appearing on the console when booted; there are a lot...

Does 'printf' only print when running a kernel with with kernel config twiddle changed and the kernel recompiled, and if so which twiddle needs to be set?

And if you say that I need to attach a debugger to see the 'printf' outputs, how do I do that during boot: as the kernel is launching, rather than normal multiuser phase (e.g. before init is even run) please?

Again, Thank you for your patience in advance.
James.
 
/me being proud he knows the answer to this specific question because he was trying to write his first driver recently ;)

Short and incomplete answer: to the console(s) during boot. It also ends up in /var/log/dmesg.log (easiest accessible via dmesg).

However ... the printf you're asking about is wrapped inside a "#ifdef BOOTP_DEBUG", while it isn't defined anywhere. There is a line in (/usr/src)/stand/libsa/bootp.c:
#define BOOTP_DEBUGxx. Most likely the developer of this code initially added this for his own use.
Most other printf statements in this file are status/error-case only. The ones in bootpc_decode_reply() all end up on a single line.

More complete answer: if you want these, you'll have to define BOOTP_DEBUG in that specific c-file (or in both with an #ifndef around it) and recompile the kernel.
These printf statements are used in many drivers, but are in some way or capacity disabled: using macro's, with an #if or #ifdef or inside of an if-statement e.g. if(bootverbose)
 
kernel printf()'s go directly to the console
Thats what I would have thought, but there are a lot (49) of printf statements in that one file alone, and some of them are called prior to the "white kernel text ending", but not seeing them in dmesg at all.

For example here are a few that should be printed:
Code:
printf("hostname %s ", p);
printf("rootfs %s ", p);
printf("router ");
printf("subnet mask ");
printf(" server ");
printf("%s at ", ifctx->ireq.ifr_name);

UPDATE: Just rebooted a PXE client machine and the words "rootfs", "server", "router", and "subnet mask" are not in dmesg.
 
Short and incomplete answer: to the console(s) during boot.
A somewhat more complete answer: those message go to the system console(s) and the kernel message buffer.
The latter is in memory and can be read in a couple of way including via /dev/klog.
E.g., dmesg(8) reads the message buffer.
And /var/run/dmesg.boot is produced using that command.
syslogd(8) uses /dev/klog to read kernel messages to dispatch them to log files according to its configuration.
Etc.
 
Thats what I would have thought, but there are a lot (49) of printf statements in that one file alone, and some of them are called prior to the "white kernel text ending", but not seeing them in dmesg at all.

For example here are a few that should be printed:
Code:
printf("hostname %s ", p);
printf("rootfs %s ", p);
printf("router ");
printf("subnet mask ");
printf(" server ");
printf("%s at ", ifctx->ireq.ifr_name);

UPDATE: Just rebooted a PXE client machine and the words "rootfs", "server", "router", and "subnet mask" are not in dmesg.

The bootloader's messages are not captured in dmesg. The machinery for that isn't up yet.
 
OK, on diving into it a bit further got the behaviour I expected.

Many thanks to Andriy, cracauer@, Kai Burghardt and malavon of whom are all correct: the whole code block (nee /usr/src/sys/nfs/bootp_subr.c) I was looking at wasn't compiled in to GENERIC as the correct kernel option (option BOOTP) hadn't been set. Couldn't see the wood for the trees, but with a custom kernel it worked like a charm.
 
Back
Top