|
1 /* |
|
2 * Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: Debug macros |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #ifndef DEBUG_H |
|
20 #define DEBUG_H |
|
21 |
|
22 ////////////////////////////////////////////////////////////////////////////// |
|
23 // Here are parameters need to be modified. |
|
24 // Component name |
|
25 #define MODULE_NAME "USBWATCHER" |
|
26 ////////////////////////////////////////////////////////////////////////////// |
|
27 |
|
28 |
|
29 // For handling unicode strings as L##MACRO is interpreted as LMACRO |
|
30 #define WIDEN2( x ) L##x |
|
31 #define WIDEN( x ) WIDEN2( x ) |
|
32 |
|
33 _LIT( KUsbPanicModule, ""WIDEN( MODULE_NAME ) ); |
|
34 |
|
35 #ifdef _DEBUG |
|
36 |
|
37 // Comment this line out if using real-time debugging |
|
38 //#define LOG_TO_FILE |
|
39 // =========================================================================== |
|
40 #if defined ( LOG_TO_FILE ) |
|
41 // =========================================================================== |
|
42 // Add corresponding libabry in mmp file |
|
43 // LIBRARY flogger.lib |
|
44 // The log file is located at |
|
45 // c:\logs\usb\MODULE_NAME.txt |
|
46 |
|
47 #include <flogger.h> |
|
48 |
|
49 #define DESC( x ) TPtrC( ( const TText* ) ( x ) ) |
|
50 #define DESC8( x ) TPtrC8( ( const TUint8* ) ( x ) ) |
|
51 _LIT( KUsbLogDir, "USB" ); |
|
52 _LIT( KUsbLogFile, ""WIDEN(MODULE_NAME)L".txt" ); |
|
53 |
|
54 // s: c string. |
|
55 #define LOG(s) RFileLogger::WriteFormat( KUsbLogDir, \ |
|
56 KUsbLogFile, EFileLoggingModeAppend, \ |
|
57 DESC8( "[%08x] ["MODULE_NAME"] "##s ), TUint(RThread().Id()) ) |
|
58 |
|
59 // s: c string contains "%x" |
|
60 // v: varaible corresponding to %x |
|
61 #define LOG1(s, v) RFileLogger::WriteFormat( KUsbLogDir, \ |
|
62 KUsbLogFile, EFileLoggingModeAppend, \ |
|
63 DESC8( "[%08x] ["MODULE_NAME"] "##s ), v, \ |
|
64 TUint(RThread().Id()) ) |
|
65 // s: c string contains "%x%y" |
|
66 // v1: varaible corresponding to %x |
|
67 // v2: varaible corresponding to %y |
|
68 #define LOG2(s, v1, v2) RFileLogger::WriteFormat( KUsbLogDir, \ |
|
69 KUsbLogFile, EFileLoggingModeAppend, \ |
|
70 DESC8( "[%08x] ["MODULE_NAME"] "##s ), TUint(RThread().Id()), \ |
|
71 v1, v2 ) |
|
72 |
|
73 // s: c string contains "%x%y%z" |
|
74 // v1: varaible corresponding to %x |
|
75 // v2: varaible corresponding to %y |
|
76 // v3: varaible corresponding to %z |
|
77 #define LOG3(s, v1, v2, v3) RFileLogger::WriteFormat( KUsbLogDir, \ |
|
78 KUsbLogFile, EFileLoggingModeAppend, \ |
|
79 DESC8( "[%08x] ["MODULE_NAME"] "##s ), \ |
|
80 TUint(RThread().Id()), v1, v2, v3 ) |
|
81 |
|
82 class TFuncLogger |
|
83 { |
|
84 public: |
|
85 TFuncLogger(const TDesC8& aFuncName) |
|
86 { |
|
87 iFuncName.Set( aFuncName ); |
|
88 RFileLogger::WriteFormat( KUsbLogDir, KUsbLogFile, |
|
89 EFileLoggingModeAppend, |
|
90 DESC8( "[%08x] ["MODULE_NAME"] >>%s" ), TUint(RThread().Id()), |
|
91 iFuncName.Ptr() ); |
|
92 } |
|
93 ~TFuncLogger() |
|
94 { |
|
95 RFileLogger::WriteFormat( KUsbLogDir, KUsbLogFile, |
|
96 EFileLoggingModeAppend, |
|
97 DESC8( "[%08x] ["MODULE_NAME"] <<%s" ), TUint(RThread().Id()), |
|
98 iFuncName.Ptr() ); |
|
99 } |
|
100 private: |
|
101 TPtrC8 iFuncName; |
|
102 }; |
|
103 // =========================================================================== |
|
104 #else //Real-time logging |
|
105 // =========================================================================== |
|
106 #include <e32debug.h> |
|
107 |
|
108 // Paramters same as above. |
|
109 #define LOG( str ) { RDebug::Printf( "[%08x] ["MODULE_NAME"] %s",\ |
|
110 TUint(RThread().Id()), str ); } |
|
111 |
|
112 #define LOG1( s, v ) { RDebug::Printf( "[%08x] ["MODULE_NAME"] "##s ,\ |
|
113 TUint(RThread().Id()), v ); } |
|
114 |
|
115 #define LOG2( s, v1,v2 ) { RDebug::Printf( "[%08x] ["MODULE_NAME"] "##s , \ |
|
116 TUint(RThread().Id()), v1, v2 ); } |
|
117 |
|
118 #define LOG3( s, v1, v2, v3 ) { RDebug::Printf( "[%08x] ["MODULE_NAME"] "##s, \ |
|
119 TUint(RThread().Id()), v1, v2, v3); } |
|
120 |
|
121 class TFuncLogger |
|
122 { |
|
123 public: |
|
124 TFuncLogger(const TDesC8& aFuncName) |
|
125 { |
|
126 iFuncName.Set( aFuncName ); |
|
127 RDebug::Printf( "[%08x] ["MODULE_NAME"] >>%s", TUint(RThread().Id()), |
|
128 iFuncName.Ptr()); |
|
129 } |
|
130 ~TFuncLogger() |
|
131 { |
|
132 RDebug::Printf( "[%08x] ["MODULE_NAME"] <<%s", TUint(RThread().Id()), |
|
133 iFuncName.Ptr()); |
|
134 } |
|
135 private: |
|
136 TPtrC8 iFuncName; |
|
137 }; |
|
138 #endif // LOG_TO_FILE |
|
139 |
|
140 #define LEAVE( exp ) {volatile TInt err = exp; \ |
|
141 LOG3( "LEAVE(%d) @file: %s, line: %d", err, __FILE__, __LINE__ );\ |
|
142 User::Leave( err );} |
|
143 |
|
144 #define LEAVEIFERROR( exp ) {volatile TInt err = exp; if(err < 0) LEAVE(err);} |
|
145 |
|
146 #define PANIC( exp ) {volatile TInt err = exp; \ |
|
147 LOG3( "PANIC(%d) @file: %s, line: %d", err, __FILE__, __LINE__ );\ |
|
148 User::Panic( KUsbPanicModule, err );} |
|
149 |
|
150 |
|
151 #define LOG_FUNC TFuncLogger __instrument(TPtrC8((TUint8*)__PRETTY_FUNCTION__)); |
|
152 |
|
153 #else // _DEBUG |
|
154 // =========================================================================== |
|
155 |
|
156 #define LOG( s ) |
|
157 #define LOG1( s, v ) |
|
158 #define LOG2( s, v1, v2 ) |
|
159 #define LOG3( s, v1, v2, v3 ) |
|
160 #define LOG_FUNC_ENTRY |
|
161 #define LOG_FUNC_EXIT |
|
162 #define LEAVE( exp ) User::Leave( exp ); |
|
163 #define LEAVEIFERROR( exp ) User::LeaveIfError( exp ); |
|
164 #define PANIC( err ) User::Panic( KUsbPanicModule, err ); |
|
165 #define LOG_FUNC |
|
166 // =========================================================================== |
|
167 #endif // _DEBUG |
|
168 // =========================================================================== |
|
169 #endif // DEBUG_H |
|
170 |
|
171 // End of File |