26
|
1 |
/*
|
|
2 |
* Copyright (c) 2010 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 |
* Initial Contributors:
|
|
9 |
* Nokia Corporation - initial contribution.
|
|
10 |
*
|
|
11 |
* Contributors:
|
|
12 |
* Description :tracing and debuging definitions.
|
|
13 |
*
|
|
14 |
*/
|
|
15 |
|
|
16 |
|
|
17 |
#ifndef DEBUG_H
|
|
18 |
#define DEBUG_H
|
|
19 |
|
|
20 |
#include <e32base.h>
|
|
21 |
#include <e32svr.h>
|
|
22 |
|
|
23 |
_LIT8(KDebugPrintS, "ATCmd: %s%S\r\n");
|
|
24 |
_LIT8(KDebugPrintD, "ATCmd: %s%d\r\n");
|
|
25 |
|
|
26 |
#ifdef _DEBUG
|
|
27 |
|
|
28 |
#include <flogger.h>
|
|
29 |
|
|
30 |
_LIT(KLogFile,"atmiscmdplugin.txt");
|
|
31 |
_LIT(KLogDir,"atmiscmdplugin");
|
|
32 |
_LIT(KATDebugFile, "log.txt" );
|
|
33 |
_LIT(KATDebugDir, "atmiscmdplugin" );
|
|
34 |
|
|
35 |
_LIT(KTracePrefix16, "[atmiscmdplugin] ");
|
|
36 |
_LIT8(KTracePrefix8, "[atmiscmdplugin] ");
|
|
37 |
_LIT8(KFuncFormat8, ">< %S");
|
|
38 |
_LIT8(KFuncThisFormat8, ">< %S, [0x%08X]");
|
|
39 |
_LIT8(KFuncEntryFormat8, "-> %S");
|
|
40 |
_LIT8(KFuncEntryThisFormat8, "-> %S, [0x%08X]");
|
|
41 |
_LIT8(KFuncEntryArgFormat8, "-> %S, (%S)");
|
|
42 |
_LIT8(KFuncExitFormat8, "<- %S");
|
|
43 |
_LIT(KPanicCategory, "atmiscmdplugin");
|
|
44 |
_LIT8(KPanicPrefix8, "PANIC code ");
|
|
45 |
_LIT8(KLeavePrefix8, "LEAVE code ");
|
|
46 |
|
|
47 |
const TInt KMaxLogLineLength = 256;
|
|
48 |
|
|
49 |
// Trace options
|
|
50 |
#define KPRINTERROR 0x00000001 // Print error
|
|
51 |
#define KPRINTINFO 0x00000002 // Print function trace
|
|
52 |
#define KPRINTSTATE 0x00000004 // Print state machine infos
|
|
53 |
#define KPRINTWARNING 0x00000008 // Print warnings
|
|
54 |
|
|
55 |
#define USE_FILE_LOGGING
|
|
56 |
|
|
57 |
const TInt KTraceMask = KPRINTERROR | KPRINTINFO | KPRINTSTATE | KPRINTWARNING;
|
|
58 |
|
|
59 |
NONSHARABLE_CLASS(TOverflowTruncate16) : public TDes16Overflow
|
|
60 |
{
|
|
61 |
public:
|
|
62 |
void Overflow(TDes16& /*aDes*/) {}
|
|
63 |
};
|
|
64 |
|
|
65 |
NONSHARABLE_CLASS(TOverflowTruncate8) : public TDes8Overflow
|
|
66 |
{
|
|
67 |
public:
|
|
68 |
void Overflow(TDes8& /*aDes*/) {}
|
|
69 |
};
|
|
70 |
|
|
71 |
inline void Trace(TRefByValue<const TDesC16> aFmt, ...)
|
|
72 |
{
|
|
73 |
VA_LIST list;
|
|
74 |
VA_START(list,aFmt);
|
|
75 |
RBuf16 buf;
|
|
76 |
buf.Create(KMaxLogLineLength);
|
|
77 |
buf.Zero();
|
|
78 |
buf.Append(KTracePrefix16);
|
|
79 |
TOverflowTruncate16 overflow;
|
|
80 |
buf.AppendFormatList(aFmt,list,&overflow);
|
|
81 |
RDebug::Print(buf);
|
|
82 |
#ifdef USE_FILE_LOGGING
|
|
83 |
RFileLogger::Write(KLogDir, KLogFile, EFileLoggingModeAppend, buf);
|
|
84 |
#endif
|
|
85 |
buf.Close();
|
|
86 |
}
|
|
87 |
|
|
88 |
inline void Trace(TRefByValue<const TDesC8> aFmt, ...)
|
|
89 |
{
|
|
90 |
VA_LIST list;
|
|
91 |
VA_START(list, aFmt);
|
|
92 |
TOverflowTruncate8 overflow;
|
|
93 |
RBuf8 buf8;
|
|
94 |
buf8.Create(KMaxLogLineLength);
|
|
95 |
buf8.Zero();
|
|
96 |
buf8.Append(KTracePrefix8);
|
|
97 |
buf8.AppendFormatList(aFmt, list, &overflow);
|
|
98 |
RDebug::RawPrint(buf8);
|
|
99 |
#ifdef USE_FILE_LOGGING
|
|
100 |
RFileLogger::Write(KLogDir, KLogFile, EFileLoggingModeAppend, buf8);
|
|
101 |
#endif
|
|
102 |
buf8.Close();
|
|
103 |
}
|
|
104 |
|
|
105 |
inline void TracePanic(
|
|
106 |
char* aFile,
|
|
107 |
TInt aLine,
|
|
108 |
TInt aPanicCode,
|
|
109 |
const TDesC& aPanicCategory)
|
|
110 |
{
|
|
111 |
TPtrC8 fullFileName((const TUint8*)aFile);
|
|
112 |
TPtrC8 fileName(fullFileName.Ptr()+fullFileName.LocateReverse('\\')+1);
|
|
113 |
RBuf8 buf;
|
|
114 |
buf.Create(KMaxLogLineLength);
|
|
115 |
buf.Zero();
|
|
116 |
buf.Append(KPanicPrefix8);
|
|
117 |
buf.AppendFormat(_L8("%d at line %d in file %S"), aPanicCode, aLine, &fileName);
|
|
118 |
Trace(buf);
|
|
119 |
buf.Close();
|
|
120 |
User::Panic(aPanicCategory, aPanicCode);
|
|
121 |
}
|
|
122 |
|
|
123 |
inline void TraceLeave(char* aFile, TInt aLine, TInt aReason)
|
|
124 |
{
|
|
125 |
TPtrC8 fullFileName((const TUint8*)aFile);
|
|
126 |
TPtrC8 fileName(fullFileName.Ptr()+fullFileName.LocateReverse('\\')+1);
|
|
127 |
RBuf8 buf;
|
|
128 |
buf.Create(KMaxLogLineLength);
|
|
129 |
buf.Zero();
|
|
130 |
buf.Append(KLeavePrefix8);
|
|
131 |
buf.AppendFormat(_L8("%d at line %d in file %S"), aReason, aLine, &fileName);
|
|
132 |
Trace(buf);
|
|
133 |
buf.Close();
|
|
134 |
User::LeaveIfError(aReason);
|
|
135 |
}
|
|
136 |
|
|
137 |
inline TBuf8<64> ArgFormat(TRefByValue<const TDesC8> aFmt, ...)
|
|
138 |
{
|
|
139 |
TOverflowTruncate8 overflow;
|
|
140 |
TBuf8<64> buf8;
|
|
141 |
buf8.Format(aFmt, &overflow);
|
|
142 |
return buf8;
|
|
143 |
}
|
|
144 |
|
|
145 |
#define TRACE_INFO(p) {if(KTraceMask & KPRINTINFO) Trace p;}
|
|
146 |
|
|
147 |
#define TRACE_ERROR(p) {if(KTraceMask & KPRINTERROR) Trace p;}
|
|
148 |
|
|
149 |
#define TRACE_STATE(p) {if(KTraceMask & KPRINTSTATE) Trace p;}
|
|
150 |
|
|
151 |
#define TRACE_WARNING(p) {if(KTraceMask & KPRINTWARNING) Trace p;}
|
|
152 |
|
|
153 |
#define TRACE_INFO_SEG(p) {if(KTraceMask & KPRINTINFO) p;}
|
|
154 |
|
|
155 |
#define TRACE_ASSERT(GUARD, CODE) {if (!(GUARD)) \
|
|
156 |
TracePanic(__FILE__, __LINE__, CODE, KPanicCategory);}
|
|
157 |
|
|
158 |
#define PANIC(CODE) TracePanic(__FILE__, __LINE__, CODE, KPanicCategory)
|
|
159 |
|
|
160 |
#define LEAVE_IF_ERROR(REASON) {if (REASON) \
|
|
161 |
TraceLeave(__FILE__, __LINE__, REASON);}
|
|
162 |
|
|
163 |
#define LEAVE(REASON) TraceLeave(__FILE__, __LINE__, REASON)
|
|
164 |
|
|
165 |
#define TRACE_FUNC_ENTRY {if(KTraceMask & KPRINTINFO) { \
|
|
166 |
TPtrC8 ptr8((TUint8*)__PRETTY_FUNCTION__); \
|
|
167 |
Trace(KFuncEntryFormat8, &ptr8);}}
|
|
168 |
|
|
169 |
#define TRACE_FUNC_ENTRY_THIS {if(KTraceMask & KPRINTINFO) {\
|
|
170 |
TPtrC8 ptr8((TUint8*)__PRETTY_FUNCTION__); \
|
|
171 |
Trace(KFuncEntryThisFormat8, &ptr8, this);}}
|
|
172 |
|
|
173 |
#define TRACE_FUNC_EXIT {if(KTraceMask & KPRINTINFO) {\
|
|
174 |
TPtrC8 ptr8((TUint8*)__PRETTY_FUNCTION__); \
|
|
175 |
Trace(KFuncExitFormat8, &ptr8);}}
|
|
176 |
|
|
177 |
#define TRACE_FUNC {if(KTraceMask & KPRINTINFO) { \
|
|
178 |
TPtrC8 ptr8((TUint8*)__PRETTY_FUNCTION__); \
|
|
179 |
Trace(KFuncFormat8, &ptr8);}}
|
|
180 |
|
|
181 |
#define TRACE_FUNC_THIS {if(KTraceMask & KPRINTINFO) {\
|
|
182 |
TPtrC8 ptr8((TUint8*)__PRETTY_FUNCTION__); \
|
|
183 |
Trace(KFuncThisFormat8, &ptr8, this);}}
|
|
184 |
|
|
185 |
#define TRACE_FUNC_ARG(a) { if(KTraceMask & KPRINTINFO) { \
|
|
186 |
TPtrC8 func( (TUint8*) __PRETTY_FUNCTION__ ); \
|
|
187 |
TPtrC8 arg( ArgFormat a ); \
|
|
188 |
Trace( KFuncEntryArgFormat8, &func, &arg ); } }
|
|
189 |
|
|
190 |
#define RETURN_IF_ERR(ERR) {if(ERR) {Trace(_L8(" RETURN %d at file %S line %d"), ERR, &(TPtrC8((const TUint8*)__FILE__)), __LINE__); return ERR;}}
|
|
191 |
|
|
192 |
#else // ! _DEBUG
|
|
193 |
|
|
194 |
#define TRACE_INFO(p)
|
|
195 |
|
|
196 |
#define TRACE_ERROR(p)
|
|
197 |
|
|
198 |
#define TRACE_STATE(p)
|
|
199 |
|
|
200 |
#define TRACE_WARNING(p)
|
|
201 |
|
|
202 |
#define TRACE_INFO_SEG(p)
|
|
203 |
|
|
204 |
#define TRACE_ASSERT(GUARD, CODE)
|
|
205 |
|
|
206 |
#define PANIC(CODE) {User::Panic(KPanicCategory, CODE);}
|
|
207 |
|
|
208 |
#define LEAVE_IF_ERROR(REASON) {static_cast<void>(User::LeaveIfError(REASON));}
|
|
209 |
|
|
210 |
#define LEAVE(REASON) {static_cast<void>(User::Leave(REASON));}
|
|
211 |
|
|
212 |
#define TRACE_FUNC_ENTRY
|
|
213 |
|
|
214 |
#define TRACE_FUNC_ENTRY_THIS
|
|
215 |
|
|
216 |
#define TRACE_FUNC_EXIT
|
|
217 |
|
|
218 |
#define TRACE_FUNC
|
|
219 |
|
|
220 |
#define TRACE_FUNC_THIS
|
|
221 |
|
|
222 |
#define TRACE_FUNC_ARG(a)
|
|
223 |
|
|
224 |
#define RETURN_IF_ERR(ERR) {if(ERR) return ERR;}
|
|
225 |
|
|
226 |
inline void Trace(TRefByValue<const TDesC16> aFmt, ...)
|
|
227 |
{
|
|
228 |
}
|
|
229 |
|
|
230 |
inline void Trace(TRefByValue<const TDesC8> aFmt, ...)
|
|
231 |
{
|
|
232 |
}
|
|
233 |
#endif // _DEBUG
|
|
234 |
|
|
235 |
#endif // DEBUG_H
|
|
236 |
|