a debugging mechanism

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
Fukuda

a debugging mechanism

Post 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
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:a debugging mechanism

Post 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
Fukuda

Re:a debugging mechanism

Post 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)
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:a debugging mechanism

Post 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
Post Reply