Page 1 of 1

a debugging mechanism

Posted: Thu Nov 27, 2003 8:55 am
by Fukuda
My debugging mechanism works like this:

Code: Select all

#ifdef _DEBUG_H
    #define DEBUG(Y) Y
#else
    #define DEBUG(Y)
#endif
...
...
DEBUG(printf("Error1");)
I want a debugging mechanism that give me chance to debug my os modul by modul. For example, I want to write, in keyboard modul:

Code: Select all

DEBUG(1 ,printf("DEBUG:Keyboard Error"));
and in mouse modul:

Code: Select all

DEBUG(2, printf("DEBUG:Mouse Error"));
The code below doesnt work, but I think it explains what I want.

Code: Select all

#ifdef _DEBUG_H && #if _DEBUG_H == ModulNo
   #define DEBUG(ModulNo, Y) Y
#else
   #define DEBUG(ModulNo, Y)
#endif

Re:a debugging mechanism

Posted: Thu Nov 27, 2003 12:57 pm
by Pype.Clicker
what about replacing DEBUG(module, ... ) by DB_MODULE(...) ?

otherwise, you could do

Code: Select all

#define DEBUG(module, action) \
    if (module&DEBUGGED_MODULES) action

Re:a debugging mechanism

Posted: Thu Nov 27, 2003 2:00 pm
by Fukuda
Pype.Clicker wrote: what about replacing DEBUG(module, ... ) by DB_MODULE(...) ?
Do u mind a little bit explaining it?

Code: Select all

#define DEBUG(module, action) \
    #if (module&DEBUGGED_MODULES) action
umm.. may I use #if directive as this vay? (Ill check after disconnecting from net)

Re:a debugging mechanism

Posted: Thu Nov 27, 2003 4:21 pm
by Pype.Clicker
err ... note that i had no "#" before my if !
i was just using the fact that a good compiler generates no code for

Code: Select all

if (0) action();
and generate no test code for

Code: Select all

if (1) action();
thus if you have

Code: Select all

#include <debug.h>
#define DEBUG_MODULES (DB_KEYB|DB_MOUSE)

DEBUG(DB_KEYB,printf("keyboard debugger turned on"));
the condition "DB_KEYB&(DB_KEYB|DB_MOUSE)" resolves to a constant true value, and the printf code will be assembled.

If you want to get a sneak peek on how i "solved" this for my own project, get a look at debug.h here
and at debug.chere