Page 1 of 1

debug output macro

Posted: Wed Oct 11, 2006 3:00 pm
by OZ
Hi,
I' trying to get some decent debug output, which I may enable or disable in the makefile. I searched around the web, but I just don't get it working. It just doesn't print a single thing although I think it should ...

Code: Select all

 void kerror(char *msg,...);

Code: Select all

#undef FD_ERROR
#      define FD_ERROR(msg, args...) kerror(msg, ## args)

#undef FD_DEBUG
#   ifdef KFD_DEBUG
#      define FD_DEBUG(msg, args...) kprintf(msg, ## args)
#   else
#      define FD_DEBUG(msg, args...)
#   endif

#undef FD_INFO
#   ifdef KFD_INFO
#      define FD_INFO(msg, args...) kprintf(msg, ## args)
#   else
#      define FD_INFO(msg, args...)
#   endif

Code: Select all

KFD_DO_DEBUG=y
KFD_DO_INFO=y
ifeq ($(KFD_DO_DEBUG),y)
   DEBFLAGS += -DKFD_DEBUG 
else
   DEBFLAGS += -UDKFD_DEBUG
endif
ifeq ($(KFD_DO_INFO),y)
   DEBFLAGS += -DKFD_INFO
else
   DEBFLAGS += -UDKFD_INFO
endif
CFLAGS += $(DEBFLAGS)
I just called them like this:

Code: Select all

if(!kfd_reset()){
      FD_DEBUG("reset failed\n");
      return FD_ERR;
   }
could this be an issue to not using the builtin va_args of gcc? Any hint how I could test, what happens to this macros?

Re:debug output macro

Posted: Wed Oct 11, 2006 3:43 pm
by nick8325
The code there looks OK to me. You can see what the macros turn into by running gcc -E on your source file (which will just run the preprocessor).

GCC has builtin support for va_list stuff - something like

Code: Select all

#define va_list __builtin_va_list
#define va_start(l, p) __builtin_va_start(l, p)
#define va_arg(l, t) __builtin_va_arg(l, t)
#define va_end(l) __builtin_va_end(l)
should work as stdarg.h, if you don't want to define your own version.

Re:debug output macro

Posted: Thu Oct 12, 2006 2:56 am
by Pype.Clicker
you can use "gcc -E <stuff>" to ask the compiler not to compile, but just to preprocess, and see how the macro have expanded...

you could also use "objdump -drS <elf kernel>" to see if there's something assembled for those calls.

or you could use "strings <binary kernel>" to see if the strings you wanted to print are there (if they arent, either you messed your linker script, or the macros haven't expanded as expected).

Re:debug output macro

Posted: Thu Oct 12, 2006 9:25 am
by OZ
thx a lot, I finally got it working. When I used gcc -E it showed up, that my macros got expanded as expected to, but it seems my makefile was the issue. I just fixed it by using the -D switch directly. Seems as if my approach to add them conditionally to the CFLAGS did not succeed.

Code: Select all

kfloppy.o: drivers/floppy/kfloppy.c
   $(CC) $(CFLAGS)   -DKFD_INFO -c drivers/floppy/kfloppy.c -o kfloppy.o
this works, thx

Re:debug output macro

Posted: Fri Oct 13, 2006 1:39 am
by Pype.Clicker
Seems as if my approach to add them conditionally to the CFLAGS did not succeed.
true, makefiles can sometimes be a weird thing to deal with. especially when it comes to conditionnal compilation ... just make sure you correctly figured out the difference between "myvar = stuff", "myvar := stuff", "myvar ?= stuff" and "myvar += stuff" before you rely on them or just stick to "setenv CFLAGS_OPTIONS stuff" in your command line before you invoke "make" :P