author | William Roberts <williamr@symbian.org> |
Thu, 22 Jul 2010 16:44:03 +0100 | |
branch | GCC_SURGE |
changeset 63 | ef2686f7597e |
parent 39 | 82988ef59a49 |
parent 35 | 9d8b04ca6939 |
permissions | -rw-r--r-- |
35 | 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 |
||
39
82988ef59a49
Bug 2961 - GCC compilation issues with debug macro string expansion fixed
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
25
diff
changeset
|
112 |
#define LOG1( s, v ) { RDebug::Printf( "[%08x] ["MODULE_NAME"] " s ,\ |
35 | 113 |
TUint(RThread().Id()), v ); } |
114 |
||
39
82988ef59a49
Bug 2961 - GCC compilation issues with debug macro string expansion fixed
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
25
diff
changeset
|
115 |
#define LOG2( s, v1,v2 ) { RDebug::Printf( "[%08x] ["MODULE_NAME"] " s , \ |
35 | 116 |
TUint(RThread().Id()), v1, v2 ); } |
117 |
||
39
82988ef59a49
Bug 2961 - GCC compilation issues with debug macro string expansion fixed
Sebastian Brannstrom <sebastianb@symbian.org>
parents:
25
diff
changeset
|
118 |
#define LOG3( s, v1, v2, v3 ) { RDebug::Printf( "[%08x] ["MODULE_NAME"] " s, \ |
35 | 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; \ |
|
145 |
if(err__ < 0) LEAVE(err__);} |
|
146 |
||
147 |
#define PANIC( exp ) {volatile TInt err_ = exp; \ |
|
148 |
LOG3( "PANIC(%d) @file: %s, line: %d", err_, __FILE__, __LINE__ );\ |
|
149 |
User::Panic( KUsbPanicModule, err_ );} |
|
150 |
||
151 |
||
152 |
#define LOG_FUNC TFuncLogger __instrument(TPtrC8((TUint8*)__PRETTY_FUNCTION__)); |
|
153 |
||
154 |
#else // _DEBUG |
|
155 |
// =========================================================================== |
|
156 |
||
157 |
#define LOG( s ) |
|
158 |
#define LOG1( s, v ) |
|
159 |
#define LOG2( s, v1, v2 ) |
|
160 |
#define LOG3( s, v1, v2, v3 ) |
|
161 |
#define LOG_FUNC_ENTRY |
|
162 |
#define LOG_FUNC_EXIT |
|
163 |
#define LEAVE( exp ) User::Leave( exp ); |
|
164 |
#define LEAVEIFERROR( exp ) User::LeaveIfError( exp ); |
|
165 |
#define PANIC( err ) User::Panic( KUsbPanicModule, err ); |
|
166 |
#define LOG_FUNC |
|
167 |
// =========================================================================== |
|
168 |
#endif // _DEBUG |
|
169 |
// =========================================================================== |
|
170 |
#endif // DEBUG_H |
|
171 |
||
172 |
// End of File |