Update contrib.
1 // Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
2 // All rights reserved.
3 // This component and the accompanying materials are made available
4 // under the terms of the License "Eclipse Public License v1.0"
5 // which accompanies this distribution, and is available
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
18 #include "traceutils.h"
21 //Add the Doxygen macro so that Doxygen doesn't need to know about the SYMBIAN_TRACE_EXECUTABLE_IS_INCLUDED define.
22 //This allows doxygen to pick up the comments for the enabled implementation of the trace API.
24 #define SYMBIAN_TRACE_EXECUTABLE_IS_INCLUDED
33 * This method currently returns 0 until a fix is provided
35 * DPDEF110067 [Trace STP][ADP37] No Way for The Secondary Category to Be Set To Default
36 * DEF119891 [TraceSTP] 1.4.1 Default the ModuleUid
37 * This will in the future return the UID3 of the executable.
41 EXPORT_C TModuleUid TTraceContext::DefaultModuleUid()
48 * Check if thread identification will be added by default.
50 EXPORT_C THasThreadIdentification TTraceContext::HasThreadIdentification() const
52 return iHasThreadIdentification;
56 * Check if PC will be added by default.
58 EXPORT_C THasProgramCounter TTraceContext::HasProgramCounter() const
60 return iHasProgramCounter;
65 * Get the current classification
67 * @return The current classification of the trace point context.
69 EXPORT_C TClassification TTraceContext::Classification() const
71 return iClassification;
75 * Get the current module Uid
77 * @return The currently set module Uid
79 EXPORT_C TModuleUid TTraceContext::ModuleUid() const
85 //--------------------- UTrace compiled in ------------------------
86 #ifdef SYMBIAN_TRACE_EXECUTABLE_IS_INCLUDED
90 // --------- printf ------------
93 Prints a string by outputting a trace packet with the format id KFormatPrintf.
95 If the specified string is too long to fit into a single trace packet
96 a multipart trace is generated.
98 @param aContext The trace packet context. @see TTraceContext
99 @param aDes The string. This can be of variable length.
101 @return The trace packet was/was not output.
103 @See BTrace::TMultipart
105 EXPORT_C TBool Print(const TTraceContext& aContext, const TDesC8& aDes)
107 if(WouldBeTracedNow(aContext))
110 return UTRACE_SECONDARY_ANY(aContext.Classification(), aContext.ModuleUid(), aContext.HasThreadIdentification(), aContext.HasProgramCounter(), pc, KFormatPrintf, aDes.Ptr(), aDes.Size());
116 #ifdef __KERNEL_MODE__
119 Prints a formatted string in kernel mode only by outputting a trace packet with the format id KFormatPrintf.
121 The function uses Kern::AppendFormat() to do the formatting.
123 Although it is safe to call this function from an ISR, it polls the output
124 serial port and may take a long time to complete, invalidating any
127 If called from an ISR, it is possible for output text to be intermingled
128 with other output text if one set of output interrupts or preempts another.
130 Some of the formatting options may not work inside an ISR.
132 Be careful not to use a string that is too long to fit onto the stack.
133 If the specified string is too long to fit into a single trace packet
134 a multipart trace is generated.
137 @param aContext The trace packet context. @see TTraceContext
138 @param aFmt The format string. This must not be longer than 256 characters.
139 @param ... A variable number of arguments to be converted to text as dictated
140 by the format string.
142 @return The trace packet was/was not output.
144 @pre Calling thread can either be in a critical section or not.
145 @pre Interrupts must be enabled.
146 @pre Kernel must be unlocked
147 @pre Call in any context.
148 @pre Suitable for use in a device driver
150 @see Kern::AppendFormat()
151 @See BTrace::TMultipart
153 Note: Until the Utrace packet format is changed this call will not add the
154 FormatId to the trace packet for kernel side traces.
156 EXPORT_C TBool Printf(const TTraceContext& aContext, const char* aFmt, ...)
158 if(WouldBeTracedNow(aContext))
161 TBuf8<KMaxPrintfSize> buf;
164 Kern::AppendFormat(buf,aFmt,list);
165 return UTRACE_SECONDARY_ANY(aContext.Classification(), aContext.ModuleUid(), aContext.HasThreadIdentification(), aContext.HasProgramCounter(), pc, KFormatPrintf, buf.Ptr(), buf.Size());
171 Prints a formatted string by outputting a trace packet with the format id KFormatPrintf.
173 If the specified string is too long to fit into a single trace packet
174 a multipart trace is generated.
176 @param aContext The trace packet context. @see TTraceContext
177 @param aFmt The format string. This must not be longer than 256 characters.
178 @param ... A variable number of arguments to be converted to text as dictated
179 by the format string.
181 @return The trace packet was/was not output.
183 @See BTrace::TMultipart
185 EXPORT_C TBool Printf(const TTraceContext& aContext, TRefByValue<const TDesC8> aFmt,...)
187 if(WouldBeTracedNow(aContext))
190 TBuf8<KMaxPrintfSize> buf;
194 Kern::AppendFormat(buf,(char*)fmt.Ptr(),list);
195 return UTRACE_SECONDARY_ANY(aContext.Classification(), aContext.ModuleUid(), aContext.HasThreadIdentification(), aContext.HasProgramCounter(), pc, KFormatPrintf, buf.Ptr(), buf.Size());
200 #endif // __KERNEL_MODE__
201 #ifndef __KERNEL_MODE__
204 Prints a formatted string by outputting a trace packet with the format id KFormatPrintf.
207 If the specified string is too long to fit into a single trace packet
208 a multipart trace is generated.
210 @param aContext The trace packet context. @see TTraceContext
211 @param aFmt The format string. This must not be longer than 256 characters.
212 @param ... A variable number of arguments to be converted to text as dictated
213 by the format string.
215 @return The trace packet was/was not output.
217 @See BTrace::TMultipart
219 EXPORT_C TBool Printf(const TTraceContext& aContext, const char* aFmt, ...)
221 if(WouldBeTracedNow(aContext))
224 TTruncateOverflow8 overflow;
227 TPtrC8 fmt((const TText8*)aFmt);
228 TBuf8<KMaxPrintfSize> buf;
229 // coverity[uninit_use_in_call]
230 buf.AppendFormatList(fmt,list,&overflow);
231 return UTRACE_SECONDARY_ANY(aContext.Classification(), aContext.ModuleUid(), aContext.HasThreadIdentification(), aContext.HasProgramCounter(), pc, KFormatPrintf, buf.Ptr(), buf.Size());
237 Prints a formatted string by outputting a trace packet with the format id KFormatPrintf.
239 If the specified string is too long to fit into a single trace packet
240 a multipart trace is generated.
242 @param aContext The trace packet context. @see TTraceContext
243 @param aFmt The format string. This must not be longer than 256 characters.
244 @param ... A variable number of arguments to be converted to text as dictated
245 by the format string.
247 @return The trace packet was/was not output.
249 @See BTrace::TMultipart
251 EXPORT_C TBool Printf(const TTraceContext& aContext, TRefByValue<const TDesC8> aFmt,...)
253 if(WouldBeTracedNow(aContext))
256 TTruncateOverflow8 overflow;
259 TBuf8<KMaxPrintfSize> buf;
260 // coverity[uninit_use_in_call]
261 buf.AppendFormatList(aFmt,list,&overflow);
262 return UTRACE_SECONDARY_ANY(aContext.Classification(), aContext.ModuleUid(), aContext.HasThreadIdentification(), aContext.HasProgramCounter(), pc, KFormatPrintf, buf.Ptr(), buf.Size());
268 Prints a formatted string by outputting a trace packet with the format id
269 KFormatPrintfUnicode for unicode strings and KFormatPrintf for other strings.
271 If the specified string is too long to fit into a single trace packet
272 a multipart trace is generated.
274 @param aContext The trace packet context. @see TTraceContext
275 @param aFmt The format string. This must not be longer than 256 characters.
276 @param ... A variable number of arguments to be converted to text as dictated
277 by the format string.
279 @return The trace packet was/was not output.
281 @See BTrace::TMultipart
283 EXPORT_C TBool Printf(const TTraceContext& aContext, TRefByValue<const TDesC16> aFmt,...)
285 if(WouldBeTracedNow(aContext))
288 TTruncateOverflow16 overflow;
291 TBuf<KMaxPrintfSize> buf;
292 // coverity[uninit_use_in_call]
293 buf.AppendFormatList(aFmt,list,&overflow);
295 TPtr8 p(buf.Collapse());
296 return UTRACE_SECONDARY_ANY(aContext.Classification(), aContext.ModuleUid(), aContext.HasThreadIdentification(), aContext.HasProgramCounter(), myPc, KFormatPrintf, buf.PtrZ(), p.Size());
298 return UTRACE_SECONDARY_ANY(aContext.Classification(), aContext.ModuleUid(), aContext.HasThreadIdentification(), aContext.HasProgramCounter(), pc, KFormatPrintfUnicode, buf.PtrZ(), buf.Size());
306 Prints a string by outputting a trace packet with the format id KFormatPrintf
308 If the specified string is too long to fit into a single trace packet
309 a multipart trace is generated.
311 @param aContext The trace packet context. @see TTraceContext
312 @param aDes The string. This must not be longer than 256 characters.
314 @return The trace packet was/was not output.
316 @See BTrace::TMultipart
318 EXPORT_C TBool Print(const TTraceContext& aContext, const TDesC16& aDes)
320 if(WouldBeTracedNow(aContext))
323 return UTRACE_SECONDARY_ANY(aContext.Classification(), aContext.ModuleUid(), aContext.HasThreadIdentification(), aContext.HasProgramCounter(), pc, KFormatPrintfUnicode, aDes.Ptr(), aDes.Size());
327 #endif // __KERNEL_MODE__
330 // --------- trace ------------
333 Outputs a trace packet containing no payload data.
335 @param aContext The trace packet context. @see TTraceContext
336 @param aFormatId A format identifier as specified by @see TFormatId
338 @return The trace packet was/was not output.
340 EXPORT_C TBool Trace(const TTraceContext& aContext, TFormatId aFormatId)
343 return UTRACE_SECONDARY_0(aContext.Classification(),aContext.ModuleUid(),aContext.HasThreadIdentification(),aContext.HasProgramCounter(), pc, aFormatId);
347 Outputs a trace packet containing 4 bytes of data.
349 @param aContext The trace packet context. @see TTraceContext
350 @param aFormatId A format identifier as specified by @see TFormatId
351 @param aData 4 bytes of data
353 @return The trace packet was/was not output.
355 EXPORT_C TBool Trace(const TTraceContext& aContext, TFormatId aFormatId, TUint32 aData)
358 return UTRACE_SECONDARY_1(aContext.Classification(),aContext.ModuleUid(),aContext.HasThreadIdentification(),aContext.HasProgramCounter(),pc,aFormatId,aData);
362 Outputs a trace packet containing 8 bytes of data.
364 @param aContext The trace packet context. @see TTraceContext
365 @param aFormatId A format identifier as specified by @see TFormatId
366 @param aData1 4 bytes of data
367 @param aData2 4 bytes of data
369 @return The trace packet was/was not output.
371 EXPORT_C TBool Trace(const TTraceContext& aContext, TFormatId aFormatId, TUint32 aData1, TUint32 aData2)
377 return UTRACE_SECONDARY_ANY(aContext.Classification(), aContext.ModuleUid(), aContext.HasThreadIdentification(), aContext.HasProgramCounter(), pc, aFormatId, &packet, 8);
381 Outputs a trace packet containing variable length data.
383 If the specified data is too big to fit into a single
384 trace packet a multipart trace is generated.
387 @param aContext The trace packet context. @see TTraceContext
388 @param aFormatId A format identifier as specified by @see TFormatId
389 @param aData Address of additional data to add to trace packet.
390 Must be word aligned, i.e. a multiple of 4.
391 @param aSize Number of bytes of additional data.
393 @return The trace packet was/was not output.
395 @See BTrace::TMultipart
397 EXPORT_C TBool Trace(const TTraceContext& aContext, TFormatId aFormatId, const TAny* aData, TInt aSize)
399 if(WouldBeTracedNow(aContext))
402 return UTRACE_SECONDARY_ANY(aContext.Classification(), aContext.ModuleUid(), aContext.HasThreadIdentification(), aContext.HasProgramCounter(), pc, aFormatId, aData, aSize);
408 Outputs a trace packet containing 4 bytes of data.
410 @param aContext The trace packet context. @see TTraceContext
411 @param aFormatId A format identifier as specified by @see TFormatId
412 @param aData 4 bytes of data
414 @return The trace packet was/was not output.
416 EXPORT_C TBool Trace(const TTraceContext& aContext, const TFormatId aFormatId, const TUint16 aData)
419 return UTRACE_SECONDARY_1(aContext.Classification(),aContext.ModuleUid(),aContext.HasThreadIdentification(),aContext.HasProgramCounter(),pc,aFormatId,aData);
423 Outputs a trace packet containing 4 bytes of data.
425 @param aContext The trace packet context. @see TTraceContext
426 @param aFormatId A format identifier as specified by @see TFormatId
427 @param aData 4 bytes of data
429 @return The trace packet was/was not output.
431 EXPORT_C TBool Trace(const TTraceContext& aContext, const TFormatId aFormatId, const TUint8 aData)
434 return UTRACE_SECONDARY_1(aContext.Classification(),aContext.ModuleUid(),aContext.HasThreadIdentification(),aContext.HasProgramCounter(),pc,aFormatId,aData);
437 #ifndef __KERNEL_MODE__
439 Outputs a trace packet containing variable length data.
441 If the specified data is too big to fit into a single
442 trace record a multipart trace is generated.
444 @param aContext Attributes of the trace point.
445 @param aFormatId A format identifier as specified by @see TFormatId
446 @param aData Additional data to add to trace packet.
447 Must be word aligned, i.e. a multiple of 4.
449 @return The trace packet was/was not logged.
451 @See BTrace::TMultipart
453 EXPORT_C TBool Trace(const TTraceContext& aContext, const TFormatId aFormatId, const TDesC16& aData)
455 if(WouldBeTracedNow(aContext))
458 return UTRACE_SECONDARY_ANY(aContext.Classification(), aContext.ModuleUid(), aContext.HasThreadIdentification(), aContext.HasProgramCounter(), pc, aFormatId, aData.Ptr(), aData.Size());
462 #endif //__KERNEL_MODE__
465 Outputs a trace packet containing variable length data.
467 If the specified data is too big to fit into a single
468 trace record a multipart trace is generated.
470 @param aContext Attributes of the trace point.
471 @param aFormatId A format identifier as specified by @see TFormatId
472 @param aData Additional data to add to trace packet.
473 Must be word aligned, i.e. a multiple of 4.
475 @return The trace packet was/was not logged.
477 @See BTrace::TMultipart
479 EXPORT_C TBool Trace(const TTraceContext& aContext, const TFormatId aFormatId, const TDesC8& aData)
481 if(WouldBeTracedNow(aContext))
484 return UTRACE_SECONDARY_ANY(aContext.Classification(), aContext.ModuleUid(), aContext.HasThreadIdentification(), aContext.HasProgramCounter(), pc, aFormatId, aData.Ptr(), aData.Size());
492 * Check whether a trace packet would be traced or not.
494 * @param aContext The context of the trace packet(s) to be checked.
495 * @return Returns whether the trace packet would be traced or not.
496 * Note: The value should never be stored since the filters can be changed without warning.
498 EXPORT_C TBool WouldBeTracedNow(const TTraceContext& aContext)
500 return BTrace::CheckFilter2(aContext.Classification(), aContext.ModuleUid());
503 //--------------------- UTrace compiled out ------------------------
505 #else //SYMBIAN_TRACE_EXECUTABLE_IS_INCLUDED
508 EXPORT_C TBool Printf(const TTraceContext&, const char*, ...) { return EFalse; }
509 EXPORT_C TBool Print(const TTraceContext&, const TDesC8&) { return EFalse; }
510 EXPORT_C TBool Printf(const TTraceContext&, TRefByValue<const TDesC8> ,...) { return EFalse; }
511 #ifndef __KERNEL_MODE__
512 EXPORT_C TBool Printf(const TTraceContext&, TRefByValue<const TDesC16>,...) { return EFalse; }
513 EXPORT_C TBool Print(const TTraceContext&, const TDesC16&) { return EFalse; }
514 #endif //__KERNEL_MODE__
517 EXPORT_C TBool Trace(const TTraceContext&, TFormatId) { return EFalse; }
518 EXPORT_C TBool Trace(const TTraceContext&, TFormatId, TUint32) { return EFalse; }
519 EXPORT_C TBool Trace(const TTraceContext&, TFormatId, TUint32, TUint32) { return EFalse; }
520 EXPORT_C TBool Trace(const TTraceContext&, TFormatId, const TAny*, TInt) { return EFalse; }
522 EXPORT_C TBool Trace(const TTraceContext&, const TFormatId, const TUint8) { return EFalse; }
523 EXPORT_C TBool Trace(const TTraceContext&, const TFormatId, const TUint16) { return EFalse; }
524 EXPORT_C TBool Trace(const TTraceContext&, const TFormatId, const TDesC8&) { return EFalse; }
525 #ifndef __KERNEL_MODE__
526 EXPORT_C TBool Trace(const TTraceContext&, const TFormatId, const TDesC16&) { return EFalse; }
528 EXPORT_C TBool WouldBeTracedNow(const TTraceContext&) { return EFalse; }
531 #endif //SYMBIAN_TRACE_EXECUTABLE_IS_INCLUDED