Adding printf() to observe semaphore behavior?
philip at semanchuk.com
Thu Mar 3 18:05:22 UTC 2016
> On Feb 22, 2016, at 9:01 PM, Philip Semanchuk <philip at semanchuk.com> wrote:
> Hi all,
> I’m trying to debug a potential kernel problem with POSIX semaphores. I’m trying to build a custom kernel with some added printf() statements and I’m not seeing any output, neither to /var/log/messages nor to the console. I would appreciate any help at getting the kernel to talk to me.
> Here’s what I’ve already done on my PC BSD 10.2 running inside a VM —
> - Downloaded the source to /usr/src
> - Added a printf(“Hello world\n”) in each implementation of sem_open() (both in lib/libc/gen/sem.c and sem_new.c) and one inside the implementation of ksem_open() (in sys/kern/uipc_sem.c) for good measure. I did not #include <stdio.h> which I’ve read is the correct thing to do when one wants to use the kernel’s printf().
> - cd /usr/src
> - sudo make buildkernel
> - sudo make installkernel
> - reboot
> - Create a POSIX semaphore. It works, but I don’t see my “Hello world” message.
> Any suggestions on what I’m doing wrong would be appreciated.
Here’s the answer my own question for anyone else who might have the same problem.
POSIX semaphores are implemented in libc.ko. If you want to experiment with them (say, by adding printf() as I was doing), modify the appropriate files (e.g. sem_new.c) and then —
make DEBUG_FLAGS=-g obj all install clean
You might be able to load the new libc.ko with kldunload/kldload, otherwise you’ll have to reboot.
More info here:
More information about the freebsd-questions