Share via


Define Debug Zones (Compact 2013)

3/26/2014

When you define debug zones, you associate each debug zone with a bit in a bit field because, later, you enable and disable debug zones by using a bit field in the global variable dpCurSettings. dpCurSettings is a DBGPARAM structure that also contains the name of the module and a set of names for the debug zones. Because you associate each debug zone with a bit in this bit field, you can OR the bit fields to determine which debug zones are active. The procedure below describes how to define debug zones, and Set Debug Zone Parameters describes how to implement the global variable dpCurSettings for each source code module.

When you create debug messages in your code, you use debug message macros, as explained in Create Debug Messages That Use Debug Zones. The first argument to these debug message macros is a condition under which the message is sent to the output stream. That condition is a debug zone that you have previously defined in the third step in the following procedure.

After you complete the steps in this procedure, you implement the global variable dpCurSettings in your module’s source code, as discussed in Set Debug Zone Parameters.

To define debug zones

  1. Assign an ID (0-15) to no more than 16 debug zones. This step is optional but creates more readable code in the following steps. The following example defines four debug zones.

    #define ZONEID_ERR          0
    #define ZONEID_WARN         1
    #define ZONEID_INIT         2
    #define ZONEID_TRACE        3
    
  2. Associate each debug zone with a bit in a 16-bit field. You do this by shifting bits to the left by an amount that corresponds to the zone ID, as in the following example.

    #define ZONEMASK_ERR          ( 1 << ZONEID_ERR )
    #define ZONEMASK_WARN         ( 1 << ZONEID_WARN )
    #define ZONEMASK_INIT         ( 1 << ZONEID_INIT )
    #define ZONEMASK_TRACE        ( 1 << ZONEID_TRACE )
    
  3. Define debug message macro conditions by using the DEBUGZONE macro with the zone ID as the input, as shown in the following example.

    #define ZONE_ERR            DEBUGZONE(ZONEID_ERR)
    #define ZONE_WARN           DEBUGZONE(ZONEID_WARN)
    #define ZONE_INIT           DEBUGZONE(ZONEID_INIT)
    #define ZONE_TRACE          DEBUGZONE(ZONEID_TRACE)
    

The following code is the complete example from the preceding steps.

#ifdef DEBUG

// Zone IDs
#define ZONEID_ERR          0
#define ZONEID_WARN         1
#define ZONEID_INIT         2
#define ZONEID_TRACE        3

// Zone masks 
#define ZONEMASK_ERR          ( 1 << ZONEID_ERR )
#define ZONEMASK_WARN         ( 1 << ZONEID_WARN )
#define ZONEMASK_INIT         ( 1 << ZONEID_INIT )
#define ZONEMASK_TRACE        ( 1 << ZONEID_TRACE )

// Debug message conditions
#define ZONE_ERR            DEBUGZONE(ZONEID_ERR)
#define ZONE_WARN           DEBUGZONE(ZONEID_WARN)
#define ZONE_INIT           DEBUGZONE(ZONEID_INIT)
#define ZONE_TRACE          DEBUGZONE(ZONEID_TRACE)


#endif

See Also

Concepts

Use Debug Zones
Kernel Debugger
Debugging

Other Resources

Windows Embedded Compact 2013