![]() | ![]() Main Index |
| MCA2 Programmer's Guide | ||||
|---|---|---|---|---|
| Prev | Fast Backward | Next | ||
Yes of course, using debuggers (gdb) is possible. But in many cases debuggers slow down execution or are cannot be used (RT-Linux). Often it is sufficient if values are printed out to console at specified lines of code.
There are a couple of commands supported by MCA2, that realize such printings independent from OS (Windows, Linux) or real time capabilities.
This include defines ERRORMSG, WARNINGMSG, INFOMSG and DEBUGMSG. if _DEBUG_ is defined these functions work like printf, otherwise they do nothing. This is a very easy possibility to switch all debug messages off.
ERRORMSG(...) prints on stderr independent of activated debug domains and current global debug level.
WARNINGMSG(...) prints on stdout independent of activated debug domains and if global debug level is smaller or equal to DL_WARNING.
INFOMSG(...) prints on stdout with debug level DL_INFO independent of activated debug domains.
DEBUGMSG(domain,level,...) prints on stdout if specified debug domain is activated and global debug level is smaller or equal to the specified one.
The global debug level is a global variable that is defined in debugdefs.c, which is part of libMCAmisc.
As levels the predefined symbols are recommendet:
#define DL_DEFAULT 0 #define DL_VERBOSE DL_DEFAULT-3 // output of everything #define DL_DEBUG DL_DEFAULT-2 // all debug messages #define DL_CREATE DL_DEFAULT-1 // debug message of constructors and destructors #define DL_INFO DL_DEFAULT // info messages #define DL_WARNING DL_DEFAULT+1 // warning messages |
Debug domains define groups of debug messages. The user is able to activate these groups individually using the the command line option --ddomain. This options requires a comma separated list of domain names. There are predefined MCA2 domains: at (AttributeTree), bb (Blackboard), tcp (TCP-Communication), system (MCA2 core), loop (MCA2 loop), all (activate all domains).
In Programs the following defined symbols are used:
enum debug_domain_bits{
DD_DEFAULT_BIT,
DD_SYSTEM_BIT,
DD_LOOP_BIT,
DD_TCP_BIT,
DD_BB_BIT,
DD_AT_BIT,
};
#define DD_DEFAULT (1 << DD_DEFAULT_BIT)
#define DD_SYSTEM (1 << DD_SYSTEM_BIT)
#define DD_LOOP (1 << DD_LOOP_BIT)
#define DD_TCP (1 << DD_TCP_BIT)
#define DD_BB (1 << DD_BB_BIT)
#define DD_AT (1 << DD_AT_BIT) |
Example 7-1. How to use debug defines
Here is an example of how to use the defines:
DEBUGMSG(DD_SYSTEM,DL_INFO,"PartBase: Set debug domain %s\n",debug_param); |
The global debug level can be set using the command line option --dlevel. Default value is 0.
If a user wants to define a new debug domain, he has to use other bits than the above (1 to 6). A 32 bit value is available, so the bits 7 to 32 can be used. New debug domains are only usefull for classes that are no modules. For the latter M_DEBUG output possibility has to be prefered. See next section for details on it.
In order to be able to activated user-defined debug domains, they must
be registered to the MCA system. This is done within
initPartDescription in your main program using the function
AddDebugDomain. It takes a description and a bit
number.