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.
Fukuda
Post
by Fukuda » Thu Nov 27, 2003 8:55 am
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
Pype.Clicker
Member
Posts: 5964 Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:
Post
by Pype.Clicker » Thu Nov 27, 2003 12:57 pm
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
Post
by Fukuda » Thu Nov 27, 2003 2:00 pm
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)
Pype.Clicker
Member
Posts: 5964 Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:
Post
by Pype.Clicker » Thu Nov 27, 2003 4:21 pm
err ... note that i had no "#" before my if !
i was just using the fact that a good compiler generates no code for
and generate no test code for
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.c
here