os/kernelhwsrv/kernel/eka/debug/ost/src/ost.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
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".
     7 //
     8 // Initial Contributors:
     9 // Nokia Corporation - initial contribution.
    10 //
    11 // Contributors:
    12 //
    13 // Description:
    14 // Trace API
    15 //
    16 
    17 #include <opensystemtrace.h>
    18 #include "traceutils.h"
    19 
    20 
    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.
    23 #ifdef __DOXYGEN__
    24 	#define SYMBIAN_TRACE_EXECUTABLE_IS_INCLUDED
    25 #endif //__DOXYGEN__
    26 
    27 
    28 
    29 /**
    30  * This method currently incorrectly returns 0, it should be returning the UID3 of the executable.
    31  *
    32  * @deprecated
    33  * @return Returns 0.
    34  */
    35 EXPORT_C TComponentId TTraceContext::DefaultComponentId()
    36 	{
    37 	return 0;
    38 	}
    39 
    40 
    41 /**
    42  * Check if thread identification will be added by default.
    43  * @deprecated
    44  */
    45 EXPORT_C THasThreadIdentification TTraceContext::HasThreadIdentification()  const
    46 	{
    47 	return iHasThreadIdentification;
    48 	};
    49 
    50 /**
    51  * Check if PC will be added by default.
    52  * @deprecated
    53  */
    54 EXPORT_C THasProgramCounter TTraceContext::HasProgramCounter()  const
    55 	{
    56 	return iHasProgramCounter;
    57 	};
    58 
    59 
    60 /**
    61  * Get the current group ID in form of classification (although classification is deprecated)
    62  *
    63  * @deprecated Use TTraceContext::GroupId() instead.
    64  * @return The current group ID of the trace point context, in form of classification.
    65  */
    66 EXPORT_C TClassification TTraceContext::Classification() const
    67 	{
    68 	return static_cast<TClassification>(iGroupId);
    69 	};
    70 
    71 /**
    72  * Get the current group ID
    73  *
    74  * @deprecated
    75  * @return The current group ID of the trace point context.
    76  */
    77 EXPORT_C TGroupId TTraceContext::GroupId() const
    78     {
    79     return iGroupId;
    80     };
    81 
    82 /**
    83  * Get the current Component Id
    84  *
    85  * @deprecated
    86  * @return The currently set Component Id
    87  */
    88 EXPORT_C TComponentId TTraceContext::ComponentId() const
    89 	{
    90 	return iComponentId;
    91 	}
    92 
    93 
    94 //--------------------- OST compiled in ------------------------
    95 #ifdef SYMBIAN_TRACE_EXECUTABLE_IS_INCLUDED
    96 
    97 
    98 
    99 // --------- OstPrintf ------------
   100 
   101 /**
   102 Prints a string by outputting a trace packet with the Trace ID KFormatPrintf.
   103 
   104 If the specified string is too long to fit into a single trace packet
   105 a multipart trace is generated.
   106 
   107 @deprecated
   108 
   109 @param aContext 	The trace packet context. @see TTraceContext
   110 @param aDes			The string. This can be of variable length.
   111 
   112 @return 			The trace packet was/was not output.
   113 
   114 @See BTrace::TMultipart
   115 */
   116 EXPORT_C TBool OstPrint(const TTraceContext& aContext, const TDesC8& aDes)
   117 	{
   118 	if(IsTraceActive(aContext))
   119 		{
   120 		GET_PC(pc);
   121 		return OST_SECONDARY_ANY(aContext.GroupId(), aContext.ComponentId(), aContext.HasThreadIdentification(), aContext.HasProgramCounter(), pc, KFormatPrintf, aDes.Ptr(), aDes.Size());
   122 		}
   123 	return EFalse;
   124 	};
   125 
   126 
   127 #ifdef  __KERNEL_MODE__
   128 
   129 /**
   130 Prints a formatted string in kernel mode only by outputting a trace packet with the Trace ID KFormatPrintf.
   131 
   132 The function uses Kern::AppendFormat() to do the formatting.
   133 
   134 Although it is safe to call this function from an ISR, it polls the output
   135 serial port and may take a long time to complete, invalidating any
   136 real-time guarantee.
   137 
   138 If called from an ISR, it is possible for output text to be intermingled
   139 with other output text if one set of output interrupts or preempts another.
   140 
   141 Some of the formatting options may not work inside an ISR.
   142 
   143 Be careful not to use a string that is too long to fit onto the stack.
   144 If the specified string is too long to fit into a single trace packet
   145 a multipart trace is generated.
   146 
   147 @deprecated
   148 
   149 @param aContext 	The trace packet context. @see TTraceContext
   150 @param aFmt 		The format string. This must not be longer than 256 characters.
   151 @param ...			A variable number of arguments to be converted to text as dictated
   152 					by the format string.
   153 
   154 @return 			The trace packet was/was not output.
   155 
   156 @pre Calling thread can either be in a critical section or not.
   157 @pre Interrupts must be enabled.
   158 @pre Kernel must be unlocked
   159 @pre Call in any context.
   160 @pre Suitable for use in a device driver
   161 
   162 @see Kern::AppendFormat()
   163 @See BTrace::TMultipart
   164 
   165 */
   166 EXPORT_C TBool OstPrintf(const TTraceContext& aContext, const char* aFmt, ...)
   167 	{
   168 	if(IsTraceActive(aContext))
   169 		{
   170 		GET_PC(pc);
   171 		TBuf8<KMaxPrintfSize> buf;
   172 		VA_LIST list;
   173 		VA_START(list,aFmt);
   174 		Kern::AppendFormat(buf,aFmt,list);
   175 		return OST_SECONDARY_ANY(aContext.GroupId(), aContext.ComponentId(), aContext.HasThreadIdentification(), aContext.HasProgramCounter(), pc, KFormatPrintf, buf.Ptr(), buf.Size());
   176 		}
   177 	return EFalse;
   178 	}
   179 
   180 /**
   181 Prints a formatted string by outputting a trace packet with the Trace ID KFormatPrintf.
   182 
   183 If the specified string is too long to fit into a single trace packet
   184 a multipart trace is generated.
   185 
   186 @deprecated
   187 
   188 @param aContext 	The trace packet context. @see TTraceContext
   189 @param aFmt 		The format string. This must not be longer than 256 characters.
   190 @param ...			A variable number of arguments to be converted to text as dictated
   191 					by the format string.
   192 
   193 @return 			The trace packet was/was not output.
   194 
   195 @See BTrace::TMultipart
   196 */
   197 EXPORT_C TBool OstPrintf(const TTraceContext& aContext, TRefByValue<const TDesC8> aFmt,...)
   198 	{
   199 	if(IsTraceActive(aContext))
   200 		{
   201 		GET_PC(pc);
   202 		TBuf8<KMaxPrintfSize> buf;
   203 		VA_LIST list;
   204 		VA_START(list,aFmt);
   205 		TDesC8 fmt = aFmt;
   206 		Kern::AppendFormat(buf,(char*)fmt.Ptr(),list);
   207 		return OST_SECONDARY_ANY(aContext.GroupId(), aContext.ComponentId(), aContext.HasThreadIdentification(), aContext.HasProgramCounter(), pc, KFormatPrintf, buf.Ptr(), buf.Size());
   208 		}
   209 	return EFalse;
   210 	}
   211 
   212 #endif // __KERNEL_MODE__
   213 #ifndef __KERNEL_MODE__
   214 
   215 /**
   216 Prints a formatted string by outputting a trace packet with the Trace ID KFormatPrintf.
   217 
   218 
   219 If the specified string is too long to fit into a single trace packet
   220 a multipart trace is generated.
   221 
   222 @deprecated
   223 
   224 @param aContext 	The trace packet context. @see TTraceContext
   225 @param aFmt 		The format string. This must not be longer than 256 characters.
   226 @param ...			A variable number of arguments to be converted to text as dictated
   227 					by the format string.
   228 
   229 @return 			The trace packet was/was not output.
   230 
   231 @See BTrace::TMultipart
   232 */
   233 EXPORT_C TBool OstPrintf(const TTraceContext& aContext, const char* aFmt, ...)
   234 	{
   235 	if(IsTraceActive(aContext))
   236 		{
   237 		GET_PC(pc);
   238 		TTruncateOverflow8 overflow;
   239 		VA_LIST list;
   240 		VA_START(list,aFmt);
   241 		TPtrC8 fmt((const TText8*)aFmt);
   242 		TBuf8<KMaxPrintfSize> buf;
   243 		// coverity[uninit_use_in_call : FALSE]
   244 		buf.AppendFormatList(fmt,list,&overflow);
   245 		return OST_SECONDARY_ANY(aContext.GroupId(), aContext.ComponentId(), aContext.HasThreadIdentification(), aContext.HasProgramCounter(), pc, KFormatPrintf, buf.Ptr(), buf.Size());
   246 		}
   247 	return EFalse;
   248 	};
   249 
   250 /**
   251 Prints a formatted string by outputting a trace packet with the Trace ID KFormatPrintf.
   252 
   253 If the specified string is too long to fit into a single trace packet
   254 a multipart trace is generated.
   255 
   256 @deprecated
   257 
   258 @param aContext 	The trace packet context. @see TTraceContext
   259 @param aFmt 		The format string. This must not be longer than 256 characters.
   260 @param ...			A variable number of arguments to be converted to text as dictated
   261 					by the format string.
   262 
   263 @return 			The trace packet was/was not output.
   264 
   265 @See BTrace::TMultipart
   266 */
   267 EXPORT_C TBool OstPrintf(const TTraceContext& aContext, TRefByValue<const TDesC8> aFmt,...)
   268 	{
   269 	if(IsTraceActive(aContext))
   270 		{
   271 		GET_PC(pc);
   272 		TTruncateOverflow8 overflow;
   273 		VA_LIST list;
   274 		VA_START(list,aFmt);
   275 		TBuf8<KMaxPrintfSize> buf;
   276 		// coverity[uninit_use_in_call : FALSE]
   277 		buf.AppendFormatList(aFmt,list,&overflow);
   278 		return OST_SECONDARY_ANY(aContext.GroupId(), aContext.ComponentId(), aContext.HasThreadIdentification(), aContext.HasProgramCounter(), pc, KFormatPrintf, buf.Ptr(), buf.Size());
   279 		}
   280 	return EFalse;
   281 	}
   282 
   283 /**
   284 Prints a formatted string by outputting a trace packet with the Trace ID
   285 KFormatPrintfUnicode for unicode strings and KFormatPrintf for other strings.
   286 
   287 If the specified string is too long to fit into a single trace packet
   288 a multipart trace is generated.
   289 
   290 @deprecated
   291 
   292 @param aContext 	The trace packet context. @see TTraceContext
   293 @param aFmt 		The format string. This must not be longer than 256 characters.
   294 @param ...			A variable number of arguments to be converted to text as dictated
   295 					by the format string.
   296 
   297 @return 			The trace packet was/was not output.
   298 
   299 @See BTrace::TMultipart
   300 */
   301 EXPORT_C TBool OstPrintf(const TTraceContext& aContext, TRefByValue<const TDesC16> aFmt,...)
   302 	{
   303 	if(IsTraceActive(aContext))
   304 		{
   305 		GET_PC(pc);
   306 		TTruncateOverflow16 overflow;
   307 		VA_LIST list;
   308 		VA_START(list,aFmt);
   309 		TBuf<KMaxPrintfSize> buf;
   310 		// coverity[uninit_use_in_call : FALSE]
   311 		buf.AppendFormatList(aFmt,list,&overflow);
   312 		#ifndef _UNICODE
   313 		TPtr8 p(buf.Collapse());
   314 		return OST_SECONDARY_ANY(aContext.GroupId(), aContext.ComponentId(), aContext.HasThreadIdentification(), aContext.HasProgramCounter(), myPc, KFormatPrintf, buf.PtrZ(), p.Size());
   315 		#else //_UNICODE
   316 		return OST_SECONDARY_ANY(aContext.GroupId(), aContext.ComponentId(), aContext.HasThreadIdentification(), aContext.HasProgramCounter(), pc, KFormatPrintfUnicode, buf.PtrZ(), buf.Size());
   317 		#endif //_UNICODE
   318 		}
   319 	return EFalse;
   320 	};
   321 
   322 
   323 /**
   324 Prints a string by outputting a trace packet with the Trace ID KFormatPrintfUnicode
   325 
   326 If the specified string is too long to fit into a single trace packet
   327 a multipart trace is generated.
   328 
   329 @deprecated
   330 
   331 @param aContext 	The trace packet context. @see TTraceContext
   332 @param aDes			The string. This must not be longer than 256 characters.
   333 
   334 @return 			The trace packet was/was not output.
   335 
   336 @See BTrace::TMultipart
   337 */
   338 EXPORT_C TBool OstPrint(const TTraceContext& aContext, const TDesC16& aDes)
   339 	{
   340 	if(IsTraceActive(aContext))
   341 		{
   342 		GET_PC(pc);
   343 		return OST_SECONDARY_ANY(aContext.GroupId(), aContext.ComponentId(), aContext.HasThreadIdentification(), aContext.HasProgramCounter(), pc, KFormatPrintfUnicode, aDes.Ptr(), aDes.Size());
   344 		}
   345 	return EFalse;
   346 	}
   347 #endif // __KERNEL_MODE__
   348 
   349 
   350 // --------- trace ------------
   351 
   352 /**
   353 Outputs a trace packet containing no payload data.
   354 
   355 @deprecated
   356 
   357 @param aContext 	The trace packet context. @see TTraceContext
   358 @param aTraceId	    The trace point identifier as specified by @see TTraceId
   359 
   360 @return		 		The trace packet was/was not output.
   361 */
   362 EXPORT_C TBool OstTrace(const TTraceContext& aContext, TTraceId aTraceId)
   363 	{
   364 	GET_PC(pc);
   365 	return OST_SECONDARY_0(aContext.GroupId(),aContext.ComponentId(),aContext.HasThreadIdentification(),aContext.HasProgramCounter(), pc, aTraceId);
   366 	}
   367 
   368 /**
   369 Outputs a trace packet containing 4 bytes of data.
   370 
   371 This method is likely to be deprecated soon.
   372 
   373 @param aContext 	The trace packet context. @see TTraceContext
   374 @param aTraceId	    The trace point identifier as specified by @see TTraceId
   375 @param aData		4 bytes of data
   376 
   377 @return 		The trace packet was/was not output.
   378 */
   379 EXPORT_C TBool OstTrace(const TTraceContext& aContext, TTraceId aTraceId, TUint32 aData)
   380 	{
   381 	GET_PC(pc);
   382 	return OST_SECONDARY_1(aContext.GroupId(),aContext.ComponentId(),aContext.HasThreadIdentification(),aContext.HasProgramCounter(),pc,aTraceId,aData);
   383 	}
   384 
   385 /**
   386 Outputs a trace packet containing 8 bytes of data.
   387 
   388 @deprecated
   389 
   390 @param aContext 	The trace packet context. @see TTraceContext
   391 @param aTraceId	    The trace point identifier as specified by @see TTraceId
   392 @param aData1		4 bytes of data
   393 @param aData2		4 bytes of data
   394 
   395 @return 		The trace packet was/was not output.
   396 */
   397 EXPORT_C TBool OstTrace(const TTraceContext& aContext, TTraceId aTraceId, TUint32 aData1, TUint32 aData2)
   398 	{
   399 	GET_PC(pc);
   400 	TUint32 packet[2];
   401 	packet[0] = aData1;
   402 	packet[1] = aData2;
   403 	return OST_SECONDARY_ANY(aContext.GroupId(), aContext.ComponentId(), aContext.HasThreadIdentification(), aContext.HasProgramCounter(), pc, aTraceId, &packet, 8);
   404 	}
   405 
   406 /**
   407 Outputs a trace packet containing variable length data.
   408 
   409 If the specified data is too big to fit into a single
   410 trace packet a multipart trace is generated.
   411 
   412 @deprecated
   413 
   414 @param aContext 	The trace packet context. @see TTraceContext
   415 @param aTraceId	    The trace point identifier as specified by @see TTraceId
   416 @param aData		Address of additional data to add to trace packet.
   417 					Must be word aligned, i.e. a multiple of 4.
   418 @param aSize		Number of bytes of additional data.
   419 
   420 @return 			The trace packet was/was not output.
   421 
   422 @See BTrace::TMultipart
   423 */
   424 EXPORT_C TBool OstTrace(const TTraceContext& aContext, TTraceId aTraceId, const TAny* aData, TInt aSize)
   425 	{
   426 	if(IsTraceActive(aContext))
   427 		{
   428 		GET_PC(pc);
   429 		return OST_SECONDARY_ANY(aContext.GroupId(), aContext.ComponentId(), aContext.HasThreadIdentification(), aContext.HasProgramCounter(), pc, aTraceId, aData, aSize);
   430 		}
   431 	return EFalse;
   432 	}
   433 
   434 /**
   435 Outputs a trace packet containing 4 bytes of data.
   436 
   437 @deprecated
   438 
   439 @param aContext 	The trace packet context. @see TTraceContext
   440 @param aTraceId	    The trace point identifier as specified by @see TTraceId
   441 @param aData		4 bytes of data
   442 
   443 @return 		The trace packet was/was not output.
   444 */
   445 EXPORT_C TBool OstTrace(const TTraceContext& aContext, const TTraceId aTraceId, const TUint16 aData)
   446 	{
   447 	GET_PC(pc);
   448 	return OST_SECONDARY_1(aContext.GroupId(),aContext.ComponentId(),aContext.HasThreadIdentification(),aContext.HasProgramCounter(),pc,aTraceId,aData);
   449 	}
   450 
   451 /**
   452 Outputs a trace packet containing 4 bytes of data.
   453 
   454 @deprecated
   455 
   456 @param aContext 	The trace packet context. @see TTraceContext
   457 @param aTraceId	    The trace point identifier as specified by @see TTraceId
   458 @param aData		4 bytes of data
   459 
   460 @return 		The trace packet was/was not output.
   461 */
   462 EXPORT_C TBool OstTrace(const TTraceContext& aContext, const TTraceId aTraceId, const TUint8 aData)
   463 	{
   464 	GET_PC(pc);
   465 	return OST_SECONDARY_1(aContext.GroupId(),aContext.ComponentId(),aContext.HasThreadIdentification(),aContext.HasProgramCounter(),pc,aTraceId,aData);
   466 	}
   467 
   468 #ifndef __KERNEL_MODE__
   469 /**
   470 Outputs a trace packet containing variable length data.
   471 
   472 If the specified data is too big to fit into a single
   473 trace record a multipart trace is generated.
   474 
   475 @deprecated
   476 
   477 @param aContext 	Attributes of the trace point.
   478 @param aTraceId	    The trace point identifier as specified by @see TTraceId
   479 @param aData		Additional data to add to trace packet.
   480 					Must be word aligned, i.e. a multiple of 4.
   481 
   482 @return 			The trace packet was/was not logged.
   483 
   484 @See BTrace::TMultipart
   485 */
   486 EXPORT_C TBool OstTrace(const TTraceContext& aContext, const TTraceId aTraceId, const TDesC16& aData)
   487 	{
   488 	if(IsTraceActive(aContext))
   489 		{
   490 		GET_PC(pc);
   491 		return OST_SECONDARY_ANY(aContext.GroupId(), aContext.ComponentId(), aContext.HasThreadIdentification(), aContext.HasProgramCounter(), pc, aTraceId, aData.Ptr(), aData.Size());
   492 		}
   493 	return EFalse;
   494 	}
   495 #endif //__KERNEL_MODE__
   496 
   497 /**
   498 Outputs a trace packet containing variable length data.
   499 
   500 If the specified data is too big to fit into a single
   501 trace record a multipart trace is generated.
   502 
   503 @deprecated
   504 
   505 @param aContext 	Attributes of the trace point.
   506 @param aTraceId	    The trace point identifier as specified by @see TTraceId
   507 @param aData		Additional data to add to trace packet.
   508 					Must be word aligned, i.e. a multiple of 4.
   509 
   510 @return 			The trace packet was/was not logged.
   511 
   512 @See BTrace::TMultipart
   513 */
   514 EXPORT_C TBool OstTrace(const TTraceContext& aContext, const TTraceId aTraceId, const TDesC8& aData)
   515 	{
   516 	if(IsTraceActive(aContext))
   517 		{
   518 		GET_PC(pc);
   519 		return OST_SECONDARY_ANY(aContext.GroupId(), aContext.ComponentId(), aContext.HasThreadIdentification(), aContext.HasProgramCounter(), pc, aTraceId, aData.Ptr(), aData.Size());
   520 		}
   521 	return EFalse;
   522 	}
   523 
   524 
   525 
   526 /**
   527  * Check whether a trace packet would be traced or not.
   528  *
   529  * @deprecated
   530  *
   531  * @param aContext The context of the trace packet(s) to be checked.
   532  * @return Returns whether the trace packet would be traced or not.
   533  * Note: The value should never be stored since the filters can be changed without warning.
   534  */
   535 EXPORT_C TBool IsTraceActive(const TTraceContext& aContext)
   536 	{
   537 	return BTrace::CheckFilter2(aContext.GroupId(), aContext.ComponentId());
   538 	};
   539 
   540 //--------------------- OST compiled out ------------------------
   541 
   542 #else //SYMBIAN_TRACE_EXECUTABLE_IS_INCLUDED
   543 
   544 //--------OstPrintf
   545 EXPORT_C TBool OstPrintf(const TTraceContext&, const char*, ...) { return EFalse; }
   546 EXPORT_C TBool OstPrint(const TTraceContext&, const TDesC8&) { return EFalse; }
   547 EXPORT_C TBool OstPrintf(const TTraceContext&, TRefByValue<const TDesC8> ,...) { return EFalse; }
   548 #ifndef  __KERNEL_MODE__
   549 EXPORT_C TBool OstPrintf(const TTraceContext&, TRefByValue<const TDesC16>,...) { return EFalse; }
   550 EXPORT_C TBool OstPrint(const TTraceContext&, const TDesC16&) { return EFalse; }
   551 #endif //__KERNEL_MODE__
   552 
   553 //--------OstTrace
   554 EXPORT_C TBool OstTrace(const TTraceContext&, TTraceId) { return EFalse; }
   555 EXPORT_C TBool OstTrace(const TTraceContext&, TTraceId, TUint32) { return EFalse; }
   556 EXPORT_C TBool OstTrace(const TTraceContext&, TTraceId, TUint32, TUint32) { return EFalse; }
   557 EXPORT_C TBool OstTrace(const TTraceContext&, TTraceId, const TAny*, TInt) { return EFalse; }
   558 
   559 EXPORT_C TBool OstTrace(const TTraceContext&, const TTraceId, const TUint8) { return EFalse; }
   560 EXPORT_C TBool OstTrace(const TTraceContext&, const TTraceId, const TUint16) { return EFalse; }
   561 EXPORT_C TBool OstTrace(const TTraceContext&, const TTraceId, const TDesC8&) { return EFalse; }
   562 #ifndef __KERNEL_MODE__
   563 EXPORT_C TBool OstTrace(const TTraceContext&, const TTraceId, const TDesC16&) { return EFalse; }
   564 #endif
   565 EXPORT_C TBool IsTraceActive(const TTraceContext&) { return EFalse; }
   566 
   567 
   568 #endif //SYMBIAN_TRACE_EXECUTABLE_IS_INCLUDED