kernel/eka/drivers/debug/rmdebug/d_driver_event_info.cpp
changeset 259 57b9594f5772
parent 247 d8d70de2bd36
child 260 a1a318fd91af
child 266 0008ccd16016
equal deleted inserted replaced
247:d8d70de2bd36 259:57b9594f5772
     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 //
       
    15 
       
    16 #include "d_driver_event_info.h"
       
    17 #include <kernel/kernel.h>
       
    18 #include <kernel/kern_priv.h>
       
    19 
       
    20 using namespace Debug;
       
    21 
       
    22 TDriverEventInfo::TDriverEventInfo()
       
    23 	{
       
    24 	Reset();
       
    25 	}
       
    26 
       
    27 void TDriverEventInfo::Reset()
       
    28 	{
       
    29 	iProcessId = 0;
       
    30 	iThreadId = 0;
       
    31 	iCurrentPC = 0;
       
    32 	iExceptionNumber = 0;
       
    33 	iFileName.FillZ();
       
    34 	iPanicCategory.FillZ();
       
    35 	iCodeAddress = 0;
       
    36 	iDataAddress = 0;
       
    37 	iThreadIdValid = (TUint8)EFalse;
       
    38 	iProcessIdValid = (TUint8)EFalse;
       
    39 	iEventType = EEventsUnknown;
       
    40 	iUidsValid = (TUint8)EFalse;
       
    41 	};
       
    42 
       
    43 /**
       
    44   Copy the data from this object into the object pointed to by aEventInfo in
       
    45   the client thread aClientThread. It is assumed that the write is performed
       
    46   on behalf of aClientThread.
       
    47 
       
    48   @param aClientThread client thread to write the data to
       
    49   @param aEventInfo TEventInfo object in the client thread to populate with data
       
    50   @param aAsyncGetValueRequest TClientDataRequest object used for pinning user memory
       
    51 
       
    52   @return KErrNone on success, or one of the other system wide error codes
       
    53   */
       
    54 TInt TDriverEventInfo::WriteEventToClientThread(TClientDataRequest<TEventInfo>* aAsyncGetValueRequest, DThread* aClientThread) const
       
    55 	{
       
    56 	// create a temporary TEventInfo to populate with the relevant data
       
    57 	TEventInfo eventInfo;
       
    58 	TInt err = KErrNone;	
       
    59 	
       
    60 	// populate the data that is common to all events
       
    61 	err = PopulateCommonEventInfo(eventInfo);
       
    62 
       
    63 	if(KErrNone != err)
       
    64 		{
       
    65 		return err;
       
    66 		}
       
    67 	
       
    68 	// populate the event specific data (means filling in the correct union member)
       
    69 	err = PopulateEventSpecificInfo(eventInfo);
       
    70 
       
    71 	// write the data to the client and return any error
       
    72 	if(KErrNone == err)
       
    73 		{
       
    74 		aAsyncGetValueRequest->Data() = eventInfo;
       
    75 		}
       
    76 	
       
    77 	return err;
       
    78 	}
       
    79 	
       
    80 /**
       
    81   Write the common event values into aEventInfo
       
    82 
       
    83   @param aEventInfo TEventInfo object to write data into
       
    84   */
       
    85 TInt TDriverEventInfo::PopulateCommonEventInfo(TEventInfo& aEventInfo) const
       
    86 	{
       
    87 	aEventInfo.iEventType = iEventType;
       
    88 	aEventInfo.iProcessId = iProcessId;
       
    89 	aEventInfo.iProcessIdValid = iProcessIdValid;
       
    90 	aEventInfo.iThreadId = iThreadId;
       
    91 	aEventInfo.iThreadIdValid = iThreadIdValid;
       
    92 	
       
    93 	return KErrNone;
       
    94 	}
       
    95 
       
    96 /**
       
    97   Write the event specific values into aEventInfo
       
    98 
       
    99   @param aEventInfo TEventInfo object to write data into
       
   100   */
       
   101 TInt TDriverEventInfo::PopulateEventSpecificInfo(TEventInfo& aEventInfo) const
       
   102 	{
       
   103 	TInt ret = KErrNone;
       
   104 	
       
   105 	switch(aEventInfo.iEventType)
       
   106 		{
       
   107 		case EEventsBreakPoint:
       
   108 			ret = PopulateThreadBreakPointInfo(aEventInfo);
       
   109 			return ret;
       
   110 		case EEventsProcessBreakPoint:
       
   111 			ret = PopulateThreadBreakPointInfo(aEventInfo);
       
   112 			return ret;
       
   113 		case EEventsSwExc:
       
   114 			ret = PopulateThreadSwExceptionInfo(aEventInfo);
       
   115 			return ret;
       
   116 		case EEventsHwExc:
       
   117 			ret = PopulateThreadHwExceptionInfo(aEventInfo);
       
   118 			return ret;
       
   119 		case EEventsKillThread:
       
   120 			ret = PopulateThreadKillInfo(aEventInfo);
       
   121 			return ret;
       
   122 		case EEventsAddLibrary:
       
   123 			ret = PopulateLibraryLoadedInfo(aEventInfo);
       
   124 			return ret;
       
   125 		case EEventsRemoveLibrary:
       
   126 			ret = PopulateLibraryUnloadedInfo(aEventInfo);
       
   127 			return ret;
       
   128 		case EEventsUserTrace:
       
   129 			ret = PopulateUserTraceInfo(aEventInfo);
       
   130 			return ret;
       
   131 		case EEventsStartThread:
       
   132 			ret = PopulateStartThreadInfo(aEventInfo);
       
   133 			return ret;
       
   134 		case EEventsUserTracesLost:
       
   135 			//no event specific data to be filled here
       
   136 			return KErrNone;
       
   137 		case EEventsAddProcess:
       
   138 			ret = PopulateAddProcessInfo(aEventInfo);
       
   139 			return ret;
       
   140 		case EEventsRemoveProcess:
       
   141 			ret = PopulateRemoveProcessInfo(aEventInfo);
       
   142 			return ret;
       
   143 		}
       
   144 	
       
   145 	return KErrArgument;
       
   146 	}
       
   147 
       
   148 /**
       
   149   Write the event specific values for a break point event into TEventInfo
       
   150 
       
   151   @param aEventInfo TEventInfo object to write data into
       
   152   */
       
   153 TInt TDriverEventInfo::PopulateThreadBreakPointInfo(TEventInfo& aEventInfo) const
       
   154 	{
       
   155 	aEventInfo.iThreadBreakPointInfo.iExceptionNumber = (TExcType)iExceptionNumber;
       
   156 	TInt ret = PopulateRmdArmExcInfo(aEventInfo);
       
   157 	
       
   158 	return ret;
       
   159 	}
       
   160 
       
   161 /**
       
   162   Write the event specific values for a thread exception event into TEventInfo
       
   163 
       
   164   @param aEventInfo TEventInfo object to write data into
       
   165   */
       
   166 TInt TDriverEventInfo::PopulateThreadSwExceptionInfo(TEventInfo& aEventInfo) const
       
   167 	{
       
   168 	aEventInfo.iThreadSwExceptionInfo.iCurrentPC = iCurrentPC;
       
   169 	aEventInfo.iThreadSwExceptionInfo.iExceptionNumber = (TExcType)iExceptionNumber;
       
   170 	
       
   171 	return KErrNone;
       
   172 	}
       
   173 
       
   174 /**
       
   175   Write the event specific values for a thread exception event into TEventInfo
       
   176 
       
   177   @param aEventInfo TEventInfo object to write data into
       
   178   */
       
   179 TInt TDriverEventInfo::PopulateThreadHwExceptionInfo(TEventInfo& aEventInfo) const
       
   180 	{
       
   181 	aEventInfo.iThreadHwExceptionInfo.iExceptionNumber = (TExcType)iExceptionNumber;
       
   182 	TInt ret = PopulateRmdArmExcInfo(aEventInfo);
       
   183 	return ret;
       
   184 	}
       
   185 
       
   186 /**
       
   187   Write the event specific values for a thread panic event into TEventInfo
       
   188 
       
   189   @param aEventInfo TEventInfo object to write data into
       
   190   */
       
   191 TInt TDriverEventInfo::PopulateThreadKillInfo(TEventInfo& aEventInfo) const
       
   192 	{
       
   193 	aEventInfo.iThreadKillInfo.iCurrentPC = iCurrentPC;
       
   194 	aEventInfo.iThreadKillInfo.iExitReason = iExceptionNumber;
       
   195 	aEventInfo.iThreadKillInfo.iExitType = iExitType;
       
   196 	aEventInfo.iThreadKillInfo.iPanicCategoryLength = iPanicCategory.Length();
       
   197 	TPtr8 panicCategoryPtr(&(aEventInfo.iThreadKillInfo.iPanicCategory[0]), iPanicCategory.Length());
       
   198 	panicCategoryPtr = iPanicCategory;
       
   199 	
       
   200 	return KErrNone;
       
   201 	}
       
   202 
       
   203 /**
       
   204   Write the event specific values for a library loaded event into TEventInfo
       
   205 
       
   206   @param aEventInfo TEventInfo object to write data into
       
   207   */
       
   208 TInt TDriverEventInfo::PopulateStartThreadInfo(TEventInfo& aEventInfo) const
       
   209 	{
       
   210 	aEventInfo.iStartThreadInfo.iFileNameLength = iFileName.Length();
       
   211 	TPtr8 fileNamePtr(&(aEventInfo.iStartThreadInfo.iFileName[0]), iFileName.Length());
       
   212 	fileNamePtr = iFileName;
       
   213 	
       
   214 	return KErrNone;
       
   215 	}
       
   216 
       
   217 /**
       
   218   Write the event specific values for an AddProcess event into TEventInfo
       
   219 
       
   220   @param aEventInfo TEventInfo object to write data into
       
   221   */
       
   222 TInt TDriverEventInfo::PopulateAddProcessInfo(TEventInfo& aEventInfo) const
       
   223 	{
       
   224 	aEventInfo.iAddProcessInfo.iFileNameLength = iFileName.Length();
       
   225 	TPtr8 fileNamePtr(&(aEventInfo.iAddProcessInfo.iFileName[0]), iFileName.Length());
       
   226 	fileNamePtr = iFileName;
       
   227 
       
   228 	const TInt uid3offset = 2;
       
   229 	aEventInfo.iAddProcessInfo.iUid3 = iUids.iUid[uid3offset].iUid;
       
   230 	aEventInfo.iAddProcessInfo.iCreatorThreadId = iCreatorThreadId;
       
   231 
       
   232 	return KErrNone;
       
   233 	}
       
   234 
       
   235 /**
       
   236   Write the event specific values for a RemoveProcess event into TEventInfo
       
   237 
       
   238   @param aEventInfo TEventInfo object to write data into
       
   239   */
       
   240 TInt TDriverEventInfo::PopulateRemoveProcessInfo(TEventInfo& aEventInfo) const
       
   241 	{
       
   242 	aEventInfo.iRemoveProcessInfo.iFileNameLength = iFileName.Length();
       
   243 	TPtr8 fileNamePtr(&(aEventInfo.iRemoveProcessInfo.iFileName[0]), iFileName.Length());
       
   244 	fileNamePtr = iFileName;
       
   245 	
       
   246 	return KErrNone;
       
   247 	}
       
   248 
       
   249 /**
       
   250   Write the event specific values for a library loaded event into TEventInfo
       
   251 
       
   252   @param aEventInfo TEventInfo object to write data into
       
   253   */
       
   254 TInt TDriverEventInfo::PopulateLibraryLoadedInfo(TEventInfo& aEventInfo) const
       
   255 	{
       
   256 	aEventInfo.iLibraryLoadedInfo.iCodeAddress = iCodeAddress;
       
   257 	aEventInfo.iLibraryLoadedInfo.iDataAddress = iDataAddress;
       
   258 	aEventInfo.iLibraryLoadedInfo.iFileNameLength = iFileName.Length();
       
   259 	TPtr8 fileNamePtr(&(aEventInfo.iLibraryLoadedInfo.iFileName[0]), iFileName.Length());
       
   260 	fileNamePtr = iFileName;
       
   261 	
       
   262 	return KErrNone;
       
   263 	}
       
   264 
       
   265 /**
       
   266   Write the event specific values for a library unloaded event into TEventInfo
       
   267 
       
   268   @param aEventInfo TEventInfo object to write data into
       
   269   */
       
   270 TInt TDriverEventInfo::PopulateLibraryUnloadedInfo(TEventInfo& aEventInfo) const
       
   271 	{
       
   272 	aEventInfo.iLibraryUnloadedInfo.iFileNameLength = iFileName.Length();
       
   273 	TPtr8 fileNamePtr(&(aEventInfo.iLibraryUnloadedInfo.iFileName[0]), iFileName.Length());
       
   274 	fileNamePtr = iFileName;
       
   275 	
       
   276 	return KErrNone;
       
   277 	}
       
   278 
       
   279 /**
       
   280   Write the ArmExcInfo values into TEventInfo
       
   281 
       
   282   @param aEventInfo TEventInfo object to write data into
       
   283   */
       
   284 TInt TDriverEventInfo::PopulateRmdArmExcInfo(TEventInfo& aEventInfo) const
       
   285 	{
       
   286 	switch(iEventType)
       
   287 		{
       
   288 		case EEventsProcessBreakPoint:
       
   289 		case EEventsBreakPoint:
       
   290 			aEventInfo.iThreadBreakPointInfo.iRmdArmExcInfo = iRmdArmExcInfo;
       
   291 			break;
       
   292 		case EEventsHwExc:
       
   293 			aEventInfo.iThreadHwExceptionInfo.iRmdArmExcInfo = iRmdArmExcInfo;
       
   294 			break;
       
   295 		}
       
   296 	
       
   297 	return KErrNone;
       
   298 	}
       
   299 
       
   300 /**
       
   301  * Writes the user trace into TEventInfo
       
   302  * 
       
   303  * @param aEventInfo TEventInfo object to write data into
       
   304  */
       
   305 TInt TDriverEventInfo::PopulateUserTraceInfo(TEventInfo& aEventInfo) const
       
   306 	{	
       
   307 	aEventInfo.iUserTraceInfo.iUserTraceLength = (TInt)iArg2;
       
   308 	
       
   309 	TPtr8 ptr(aEventInfo.iUserTraceInfo.iUserTraceText, (TInt)iArg2, TUserTraceSize );
       
   310 	ptr.Copy(iUserTraceText, (TInt)iArg2);
       
   311 		
       
   312 	return KErrNone;
       
   313 	}
       
   314 
       
   315 TBool TDriverEventInfo::FreezeOnSuspend() const
       
   316 	{
       
   317 	switch(iEventType)
       
   318 		{
       
   319 		case EEventsHwExc:
       
   320 		case EEventsBreakPoint:
       
   321 		case EEventsProcessBreakPoint:
       
   322 			return ETrue;
       
   323 		case EEventsKillThread:
       
   324 			{
       
   325 			return (iExitType == EExitPanic);
       
   326 			}
       
   327 		}
       
   328 	return EFalse;
       
   329 	}
       
   330 
       
   331 TBool TDriverEventInfo::TookException() const
       
   332 	{
       
   333 	return iExitType == EExitPanic &&
       
   334 		iExceptionNumber == ECausedException &&
       
   335 		iPanicCategory == KLitKernExec;
       
   336 	}
       
   337