platforms/os/Symbian/WVSS/src/utils/gendebug.h
changeset 0 10c42ec6c05f
equal deleted inserted replaced
-1:000000000000 0:10c42ec6c05f
       
     1 /*
       
     2  * gendebug.h
       
     3  *
       
     4  * Copyright(c) 1998 - 2010 Texas Instruments. All rights reserved.      
       
     5  * All rights reserved.      
       
     6  * 
       
     7  * This program and the accompanying materials are made available under the 
       
     8  * terms of the Eclipse Public License v1.0 or BSD License which accompanies
       
     9  * this distribution. The Eclipse Public License is available at
       
    10  * http://www.eclipse.org/legal/epl-v10.html and the BSD License is as below.                                   
       
    11  *                                                                       
       
    12  * Redistribution and use in source and binary forms, with or without    
       
    13  * modification, are permitted provided that the following conditions    
       
    14  * are met:                                                              
       
    15  *                                                                       
       
    16  *  * Redistributions of source code must retain the above copyright     
       
    17  *    notice, this list of conditions and the following disclaimer.      
       
    18  *  * Redistributions in binary form must reproduce the above copyright  
       
    19  *    notice, this list of conditions and the following disclaimer in    
       
    20  *    the documentation and/or other materials provided with the         
       
    21  *    distribution.                                                      
       
    22  *  * Neither the name Texas Instruments nor the names of its            
       
    23  *    contributors may be used to endorse or promote products derived    
       
    24  *    from this software without specific prior written permission.      
       
    25  *                                                                       
       
    26  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS   
       
    27  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT     
       
    28  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 
       
    29  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT  
       
    30  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 
       
    31  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT      
       
    32  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 
       
    33  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 
       
    34  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT   
       
    35  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
       
    36  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
       
    37  */
       
    38 
       
    39 /*
       
    40 * ============================================================================
       
    41 *  Name     : gendebug from gendebug.h
       
    42 *  Part of  : WLAN Networking
       
    43 
       
    44 * ============================================================================
       
    45 */
       
    46 
       
    47 
       
    48 #ifndef GENDEBUG_H
       
    49 #define GENDEBUG_H
       
    50 
       
    51 #ifndef __KERNEL_MODE__
       
    52 #include <e32svr.h>
       
    53 #endif
       
    54 
       
    55 /** @file gendebug.h
       
    56     @brief Common helper file for debugging. 
       
    57 
       
    58     The file contains methods for adding traces and hardcoded breakpoint.
       
    59 
       
    60     @page page1 A documentation for general helper module for doing debugging and tracing.
       
    61 
       
    62     @subsection subsec1 This subsection describes the usage of hardcoded breakpoints.
       
    63 
       
    64     Hardcoded breakpoints are usefull for allowing the execution to stop in right places
       
    65     without bringing the OS down like using general assertions would do. Hardcoded breakpoints
       
    66     must be used together with debugger. The hardcoded breakpoints are used by inserting
       
    67     macro _DBG_MUST_BREAK into source code.
       
    68 
       
    69     @note This feature has not been implemented yet.
       
    70 
       
    71     @subsection subsec2 This subsection describes the usage of trace utilities.
       
    72 
       
    73     Tracing is the most important way of doing HW level debugging (after looking the source of course).
       
    74     Most of times users don't have access to debuggers and doing debugging in the field can be greatly
       
    75     improved if there are great variety of configurable traces available.
       
    76 
       
    77     In order to use the macro in kernel space, ALWAYS_KERNEL must be defined in the MMP-file of the module.
       
    78 
       
    79     To use static tracing the module using these utilities must have defined DEBUG_LEVEL (this is integer constant) in
       
    80     MMP-file. This constant defines the bit-mask for the set of traces, which are put into code at the compile time. See
       
    81     the macro definitions for details.
       
    82 
       
    83     The other way to do tracing is to use run-time tracing, which requires from user to put class member variable iDbgLevel
       
    84     into their class. This variable is used the same way as the static flag by using bit-mask to define enabled traces. See
       
    85     the macro definitions for details.
       
    86 */
       
    87 
       
    88 
       
    89 #if defined(_DEBUG)
       
    90 #define _DBG_MUST_BREAK
       
    91 #else
       
    92 #define _DBG_MUST_BREAK
       
    93 #endif
       
    94 
       
    95 /** Critical trace-level is used when system is about to down very soon because of critical error. 
       
    96     In most cases this trace level can be replaced by using assert with trace but in some cases
       
    97     more information can be provided by using this debug level
       
    98 */
       
    99 #define CRIT_LEVEL              0x00000001
       
   100 
       
   101 /** Serious trace-level is used when something bad and unexpected has happened but system might be
       
   102     able to recover. In another words, software is not going to bring system forcefully down but
       
   103     that's exactly what might happen due to an error.
       
   104 */
       
   105 #define SERIOUS_LEVEL           0x00000002
       
   106 
       
   107 /* Error level is used to trace various errors, which are due to legal errors in normal operation. */
       
   108 #define ERROR_LEVEL             0x00000004
       
   109 
       
   110 /* Warning level is used to trace various warning, which are due to abnormal behaviour. */
       
   111 #define WARNING_LEVEL           0x00000008
       
   112 
       
   113 /* Info level is used to trace all general information. */
       
   114 #define INFO_LEVEL              0x00000010
       
   115 
       
   116 /* User definable trace level. This comment and definition should be replaced by the real usage. */
       
   117 #define USER_DEFINED_1          0x000010000
       
   118 /* User definable trace level. This comment and definition should be replaced by the real usage. */
       
   119 #define USER_DEFINED_2          0x000020000
       
   120 /* User definable trace level. This comment and definition should be replaced by the real usage. */
       
   121 #define USER_DEFINED_3          0x000040000
       
   122 /* User definable trace level. This comment and definition should be replaced by the real usage. */
       
   123 #define USER_DEFINED_4          0x000080000
       
   124 /* User definable trace level. This comment and definition should be replaced by the real usage. */
       
   125 #define USER_DEFINED_5          0x000100000
       
   126 /* User definable trace level. This comment and definition should be replaced by the real usage. */
       
   127 #define USER_DEFINED_6          0x000200000
       
   128 /* User definable trace level. This comment and definition should be replaced by the real usage. */
       
   129 #define USER_DEFINED_7          0x000400000
       
   130 /* User definable trace level. This comment and definition should be replaced by the real usage. */
       
   131 #define USER_DEFINED_8          0x000800000
       
   132 
       
   133 #define DEVICE_1_MASK           0x0000f000
       
   134 #define DEVICE_2_MASK           0x000f0000
       
   135 #define DEVICE_3_MASK           0x00f00000
       
   136 #define DEVICE_4_MASK           0x0f000000
       
   137 
       
   138 // Override debug-level definition for your own in MMP file
       
   139 #ifndef DEBUG_LEVEL
       
   140 #define DEBUG_LEVEL 0x000000FF
       
   141 #endif
       
   142 
       
   143 
       
   144 
       
   145 #pragma warning(disable : 4127)    // conditional expression is constant
       
   146 
       
   147 #if defined(_DEBUG) || defined(TRACES)
       
   148 
       
   149 // Do not directly use this macro
       
   150 //lint -emacro({717}, UtilDump)   do while(0)
       
   151 //lint -emacro({774}, UtilDump)   conditional expression is constant
       
   152 #define UtilDump(PFUNCTION,SRCLEVEL,TRGLEVEL,STRING) \
       
   153         do { \
       
   154             TUint32 _level = (TRGLEVEL); \
       
   155             if (SRCLEVEL & _level) { \
       
   156             PFUNCTION STRING; \
       
   157             } \
       
   158         } while (0)
       
   159 
       
   160 #ifdef __KERNEL_MODE__
       
   161 	#define TraceDump(LEVEL,STRING) UtilDump(Kern::Printf,DEBUG_LEVEL,LEVEL,STRING)
       
   162 	#define RTraceDump(LEVEL,STRING) UtilDump(Kern::Printf,iDbgLevel,LEVEL,STRING)
       
   163 #else
       
   164 	#define TraceDump(LEVEL,STRING) UtilDump(RDebug::Print,DEBUG_LEVEL,LEVEL,STRING)
       
   165 	#define RTraceDump(LEVEL,STRING) UtilDump(RDebug::Print,iDbgLevel,LEVEL,STRING)
       
   166 #endif
       
   167 
       
   168 #else  // it is release mode
       
   169 //lint -emacro({717}, TraceDump) do while(0)
       
   170 #define TraceDump(LEVEL,STRING) do {} while (0)
       
   171 //lint -emacro({717}, RTraceDump) do while(0)
       
   172 #define RTraceDump(LEVEL,STRING) do {} while (0)
       
   173 
       
   174 #endif // _DEBUG
       
   175 
       
   176 
       
   177 
       
   178 
       
   179 #endif // GENDEBUG_H
       
   180 
       
   181 // End of file
       
   182