dbgsrv/coredumpserver/plugins/formatters/test/testcrashdatasource.cpp
changeset 0 c6b0df440bee
equal deleted inserted replaced
-1:000000000000 0:c6b0df440bee
       
     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 "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 <e32debug.h>
       
    17 
       
    18 #include <rm_debug_api.h>
       
    19 #include "testcrashdatasource.h"
       
    20 #include <debuglogging.h>
       
    21 
       
    22 CTestCrashDataSource::CTestCrashDataSource( )
       
    23     {
       
    24 	RDebug::Printf( "test_crashdatasource.cpp::CTestCrashDataSource::CTestCrashDataSource()\n" );
       
    25     }
       
    26 
       
    27 
       
    28 // second-phase constructor
       
    29 void CTestCrashDataSource::ConstructL()
       
    30     {
       
    31 	RDebug::Printf( "test_crashdatasource.cpp::CTestCrashDataSource::ConstructL()\n" );
       
    32     }
       
    33 
       
    34 
       
    35 // destructor
       
    36 CTestCrashDataSource::~CTestCrashDataSource()
       
    37     {
       
    38 	RDebug::Printf( "test_crashdatasource.cpp::CTestCrashDataSource::~CTestCrashDataSource()\n" );
       
    39     }
       
    40 
       
    41 
       
    42 
       
    43 TInt CTestCrashDataSource::SetSimRegValues(  const TUint32    aThreadId,
       
    44 						RRegisterList & aRegisterList )
       
    45 	{
       
    46 
       
    47 	RDebug::Print( _L("CTestCrashDataSource::SetSimRegValues()\n") );
       
    48 
       
    49 	if( aRegisterList.Count() > 0 )
       
    50 		{
       
    51 
       
    52 		TUint8  val8  = (TUint8)(KRegValue8 + aThreadId);
       
    53 		TUint16 val16 = (TUint16)(KRegValue16 + aThreadId); 
       
    54 		TUint32 val32 = (TUint32)(KRegValue32 + aThreadId); 
       
    55 		TUint64 val64 = (TUint64)(MAKE_TUINT64(0xFEDCBA98u,0x76543210u) + aThreadId); 
       
    56 
       
    57 		for( TInt i = 0; i < aRegisterList.Count(); i ++ )
       
    58 			{
       
    59 			
       
    60 			TRegisterData & reg = aRegisterList[i];
       
    61 
       
    62 			switch ( reg.iSize )
       
    63 				{
       
    64 				case 0:
       
    65 					reg.iValue8  =  val8 + i;
       
    66 					RDebug::Printf( " Setting reg[%d] iValue8=0x%X\n", i, reg.iValue8 ); 
       
    67 					break;
       
    68 				case 1:
       
    69 					reg.iValue16 =  val16+ i;
       
    70 					RDebug::Printf( " Setting reg[%d] iValue16=0x%X\n", i, reg.iValue16 ); 
       
    71 					break;
       
    72 				case 2:
       
    73 					reg.iValue32 =  val32+ i;
       
    74 					RDebug::Printf( " Setting reg[%d] iValue32=0x%X\n", i, reg.iValue32 ); 
       
    75 					break;
       
    76 				case 3:
       
    77 					reg.iValue64 =  val64+ i;
       
    78 					RDebug::Printf( " Setting reg[%d]=0x%X%X\n", i,
       
    79 						I64HIGH(reg.iValue64), I64LOW(reg.iValue64) ); 
       
    80 					break;
       
    81 				}
       
    82 
       
    83             //reg.iAvailable = i%8 ? ETrue : EFalse;
       
    84             /*
       
    85 			if ( 0 == ((i+1) % 8) )
       
    86 				{
       
    87 				RDebug::Printf( "   setting reg[%d] as not available\n", i );
       
    88 				reg.iAvailable = EFalse;
       
    89 				}
       
    90             */
       
    91 			}
       
    92 
       
    93 		return KErrNone;
       
    94 
       
    95 		}
       
    96 
       
    97 	return KErrBadHandle;
       
    98 
       
    99 	}
       
   100 
       
   101 
       
   102 void CTestCrashDataSource::PrintRegs( RRegisterList & aRegisterList )
       
   103 	{
       
   104 	RDebug::Printf( "CTestCrashDataSource::PrintRegs()\n" );
       
   105 
       
   106 	if( aRegisterList.Count() > 0 )
       
   107 		{
       
   108 		for( TInt i = 0; i < aRegisterList.Count(); i ++ )
       
   109 			{			
       
   110 			TRegisterData & reg = aRegisterList[i];
       
   111 
       
   112 			RDebug::Printf( " reg[%d] iRegClass=%d, iId=%d, iSubId=%d, iSize=%d, iAvailable=", 
       
   113 				i, reg.iRegClass, reg.iId, reg.iSubId, reg.iSize );
       
   114             if(reg.iAvailable)
       
   115                 RDebug::Printf( "ETrue\n" );
       
   116             else
       
   117                 RDebug::Printf( "EFalse\n" );
       
   118 
       
   119 			switch ( reg.iSize )
       
   120 				{
       
   121 				case 0:
       
   122 					RDebug::Printf( "  iValue8=0x%X\n", reg.iValue8 ); break;
       
   123 				case 1:
       
   124 					RDebug::Printf( "  iValue16=0x%X\n", reg.iValue16 ); break;
       
   125 				case 2:
       
   126 					RDebug::Printf( "  iValue32=0x%X\n", reg.iValue32 ); break;
       
   127 				case 3:
       
   128 					RDebug::Printf( "  iValue64=0x%X%X\n", 
       
   129 						I64HIGH(reg.iValue64), I64LOW(reg.iValue64) ); 
       
   130 					break;
       
   131 				}
       
   132 			}
       
   133 		}
       
   134 	else
       
   135 		{
       
   136 		RDebug::Printf( " No registers to print\n" );
       
   137 		}
       
   138 	}
       
   139 
       
   140 
       
   141 void CTestCrashDataSource::GetRegisterListL( RRegisterList & aRegisterList )
       
   142 {
       
   143 
       
   144 	LOG_MSG("CTestCrashDataSource::GetRegisterListL()\n");
       
   145 
       
   146     TFunctionalityRegister ids[] = {ERegisterR0,
       
   147                                     ERegisterR1,
       
   148                                     ERegisterR2,
       
   149                                     ERegisterR3,
       
   150                                     ERegisterR4,
       
   151                                     ERegisterR5,
       
   152                                     ERegisterR6,
       
   153                                     ERegisterR7,
       
   154                                     ERegisterR8,
       
   155                                     ERegisterR9,
       
   156                                     ERegisterR10,
       
   157                                     ERegisterR11,
       
   158                                     ERegisterR12,
       
   159                                     ERegisterR13,
       
   160                                     ERegisterR14,
       
   161                                     ERegisterR15,
       
   162                                     ERegisterCpsr,
       
   163                                     ERegisterR13Svc,
       
   164                                     ERegisterR14Svc,
       
   165                                     ERegisterSpsrSvc,
       
   166                                     ERegisterR13Abt,
       
   167                                     ERegisterR14Abt,
       
   168                                     ERegisterSpsrAbt,
       
   169                                     ERegisterR13Und,
       
   170                                     ERegisterR14Und,
       
   171                                     ERegisterSpsrUnd,
       
   172                                     ERegisterR13Irq,
       
   173                                     ERegisterR14Irq,
       
   174                                     ERegisterSpsrIrq,
       
   175                                     ERegisterR8Fiq,
       
   176                                     ERegisterR9Fiq,
       
   177                                     ERegisterR10Fiq,
       
   178                                     ERegisterR11Fiq,
       
   179                                     ERegisterR12Fiq,
       
   180                                     ERegisterR13Fiq,
       
   181                                     ERegisterR14Fiq,
       
   182                                     ERegisterSpsrFiq,
       
   183                                     ERegisterLast
       
   184                                                     };
       
   185 
       
   186     aRegisterList.Reset();
       
   187 
       
   188     TRegisterData reg;
       
   189     //core regs
       
   190     const TFunctionalityRegister* r;
       
   191     for(r = ids; *r != ERegisterLast; ++r)
       
   192     {
       
   193         reg.iRegClass  = 0; //Core
       
   194         reg.iId        = *r; // R0, ...  
       
   195         reg.iSubId     = 0; // not used for Core Regs
       
   196         reg.iSize      = 2;
       
   197         reg.iAvailable = ETrue;
       
   198         aRegisterList.AppendL( reg );
       
   199 
       
   200     }
       
   201 
       
   202     //copro regs
       
   203     for(TInt i = 0; i < KCoProRegsCount; ++i)
       
   204     {
       
   205         reg.iRegClass  = 1; //CoPro
       
   206         reg.iId        = i; // R0, ...  
       
   207         reg.iSubId     = KRegSubId + i; 
       
   208         reg.iSize      = i%4;
       
   209         reg.iAvailable = i < KCoProRegsCount/2 ? ETrue : EFalse; //half not available
       
   210         aRegisterList.AppendL( reg );
       
   211     }
       
   212 }
       
   213 
       
   214 void CTestCrashDataSource::ReadRegistersL( const TUint64 aThreadId, RRegisterList &aRegisterList )
       
   215 	{
       
   216 
       
   217 	//RDebug::Print( _L("CTestCrashDataSource::ReadRegisters( threadId=0x%X)\n"), I64LOW(aThreadId) );
       
   218 
       
   219 	if( aRegisterList.Count() )
       
   220 		{
       
   221 		RDebug::Printf( "Register list already supplied\n" );
       
   222         User::LeaveIfError(SetSimRegValues( aThreadId, aRegisterList ));
       
   223 		}
       
   224 	else
       
   225 		{
       
   226 		RDebug::Printf( "Creating register list\n" );
       
   227 	    GetRegisterListL( aRegisterList );
       
   228         User::LeaveIfError(SetSimRegValues( aThreadId, aRegisterList ));
       
   229 		}
       
   230 
       
   231 	PrintRegs( aRegisterList );
       
   232 
       
   233 	}
       
   234 
       
   235 
       
   236 
       
   237 void CTestCrashDataSource::ReadMemoryL(
       
   238                    const TUint64    aThreadId,
       
   239                    const TUint32    aAddress,
       
   240                    const TUint32    aLength,
       
   241                    TDes8          & aData )
       
   242 	{
       
   243 
       
   244 	RDebug::Print( _L("CCrashDataSource::ReadMemory( tId=0x%X, addr=0x%X, len=0x%X)\n"), 
       
   245 		aThreadId, aAddress, aLength );
       
   246 
       
   247 	for( TUint32 i = 0; i < aLength; i++ )
       
   248 		{
       
   249         aData.Append((TUint8*)&i, 1);
       
   250 		RDebug::Printf( " Memory[%d]=0x%X\n", i, aData[i] );
       
   251 		}
       
   252 	}
       
   253 
       
   254 
       
   255 
       
   256 
       
   257 void CTestCrashDataSource::GetProcessListL( RProcessPointerList & aProcList, 
       
   258 									        TUint & aTotalProcessListDescSize )
       
   259 	{
       
   260 
       
   261 	RDebug::Print( _L("CTestCrashDataSource::GetProcessList( )\n") );
       
   262 
       
   263     CProcessInfo *processInfo = CProcessInfo::NewL(KCrashPid, KCrashFileName );
       
   264 
       
   265     TInt err = aProcList.Append( processInfo ); 
       
   266     if(err != KErrNone)
       
   267         {
       
   268         delete processInfo;
       
   269         User::Leave(err);
       
   270         }
       
   271     }
       
   272 
       
   273 void CTestCrashDataSource::GetExecutableListL( RExecutablePointerList & aExecutableList, 
       
   274 									        TUint & aTotalExecutableListDescSize )
       
   275 	{
       
   276 
       
   277 	RDebug::Print( _L("CTestCrashDataSource::GetExecutableList( )\n") );
       
   278 
       
   279     CExecutableInfo *executableInfo = CExecutableInfo::NewL(KCrashFileName, EFalse, EFalse );
       
   280 
       
   281     TInt err = aExecutableList.Append( executableInfo ); 
       
   282     if(err != KErrNone)
       
   283         {
       
   284         delete executableInfo;
       
   285         User::Leave(err);
       
   286         }
       
   287     }
       
   288 
       
   289 void CTestCrashDataSource::GetThreadListL(	const TUint64 aProcessId, 
       
   290 									RThreadPointerList & aThreadList,
       
   291 									TUint & aTotalThreadListDescSize )
       
   292 	{
       
   293 	GetThreadListL( I64LOW( aProcessId ), aThreadList, aTotalThreadListDescSize );
       
   294 	}
       
   295 
       
   296 
       
   297 void CTestCrashDataSource::GetThreadListL( const TUint32 aProcessId, 
       
   298 									RThreadPointerList & aThreadList,
       
   299 									TUint & aTotalThreadListDescSize )
       
   300 	{
       
   301 
       
   302 	RDebug::Print( _L("CTestCrashDataSource::GetThreadList( pId=0x%X)\n"), aProcessId );
       
   303 
       
   304 
       
   305 
       
   306 	LOG_MSG2( "CTestCrashDataSource::GetThreadListL( pId=0x%X)\n", aProcessId );
       
   307 
       
   308 	aThreadList.ResetAndDestroy();
       
   309 	aTotalThreadListDescSize = 0;
       
   310 
       
   311         for(TInt i =0; i < KCrashThreadsCount; ++i)
       
   312         {
       
   313             CThreadInfo *thread = CThreadInfo::NewL( KCrashTid + i,
       
   314                                         KCrashThreadName,
       
   315                                         KCrashPid,
       
   316                                         KCrashThreadPriority + i,
       
   317                                         KCrashSvcStackPtr + i,
       
   318                                         KCrashSvcStackAddr + i,
       
   319                                         KCrashSvcStackSize + i,
       
   320                                         KCrashUsrStackAddr + i,
       
   321                                         KCrashUsrStackSize + i);
       
   322             aThreadList.Append(thread);
       
   323             //delete thread;
       
   324         }
       
   325 
       
   326 	}
       
   327 
       
   328 void CTestCrashDataSource::GetCodeSegmentsL( const TUint64 aTid, RCodeSegPointerList &aCodeSegs, TUint &aTotalCodeSegListDescSize )
       
   329 	{
       
   330 
       
   331 	RDebug::Printf( "CTestCrashDataSource::GetExecutableInfo(pId=0x%X)\n", aTid );
       
   332 	TInt err;
       
   333     
       
   334     TCodeSegInfo *segInfo;
       
   335 
       
   336     if(KCrashXIP)
       
   337         RDebug::Printf( " Exec info XIP == ETrue\n" );
       
   338     else
       
   339         RDebug::Printf( " Exec info XIP == EFalse\n" );
       
   340 
       
   341     
       
   342 	segInfo = new(ELeave) TCodeSegInfo;
       
   343 	segInfo->iName			 = KCrashFileName;
       
   344     segInfo->iXIP			 = ETrue;
       
   345     segInfo->iCodeSize       = KCrashCodeSize + aTid;
       
   346     segInfo->iCodeRunAddr    = KCrashCodeRunAddr + aTid;
       
   347     segInfo->iCodeLoadAddr   = KCrashCodeLoadAddr + aTid;
       
   348     segInfo->iRoDataSize     = KCrashRODataSize + aTid;
       
   349     segInfo->iRoDataRunAddr  = KCrashRODataRunAddr + aTid;
       
   350     segInfo->iRoDataLoadAddr = KCrashRODataLoadAddr + aTid;
       
   351     segInfo->iDataSize       = KCrashDataSize + aTid;
       
   352     segInfo->iDataRunAddr    = KCrashDataRunAddr + aTid;
       
   353     segInfo->iDataLoadAddr   = KCrashDataLoadAddr + aTid;
       
   354 	segInfo->iType			 = EExeCodeSegType;
       
   355     err = aCodeSegs.Append(segInfo);
       
   356 	if(err != KErrNone)
       
   357 		{
       
   358         delete segInfo;
       
   359         User::Leave(err);
       
   360         }
       
   361 	aTotalCodeSegListDescSize += sizeof(TCodeSegInfo);
       
   362 
       
   363 	segInfo = new(ELeave) TCodeSegInfo;
       
   364 	segInfo->iName			 = KLibName1;
       
   365     segInfo->iXIP			 = ETrue;
       
   366     segInfo->iCodeSize       = KCrashCodeSize + aTid + 1;
       
   367     segInfo->iCodeRunAddr    = KCrashCodeRunAddr + aTid + 1;
       
   368     segInfo->iCodeLoadAddr   = KCrashCodeLoadAddr + aTid + 1;
       
   369     segInfo->iRoDataSize     = KCrashRODataSize + aTid + 1;
       
   370     segInfo->iRoDataRunAddr  = KCrashRODataRunAddr + aTid + 1;
       
   371     segInfo->iRoDataLoadAddr = KCrashRODataLoadAddr + aTid + 1;
       
   372     segInfo->iDataSize       = KCrashDataSize + aTid + 1;
       
   373     segInfo->iDataRunAddr    = KCrashDataRunAddr + aTid + 1;
       
   374     segInfo->iDataLoadAddr   = KCrashDataLoadAddr + aTid + 1;
       
   375 	segInfo->iType			 = EDllCodeSegType;
       
   376     err = aCodeSegs.Append(segInfo);
       
   377 	if(err != KErrNone)
       
   378 		{
       
   379         delete segInfo;
       
   380         User::Leave(err);
       
   381         }
       
   382 	aTotalCodeSegListDescSize += sizeof(TCodeSegInfo);
       
   383 
       
   384 	segInfo = new(ELeave) TCodeSegInfo;
       
   385 	segInfo->iName			 = KLibName2;
       
   386     segInfo->iXIP			 = EFalse;
       
   387     segInfo->iCodeSize       = KCrashCodeSize + aTid + 2;
       
   388     segInfo->iCodeRunAddr    = KCrashCodeRunAddr + aTid + 2;
       
   389     segInfo->iCodeLoadAddr   = KCrashCodeLoadAddr + aTid + 2;
       
   390     segInfo->iRoDataSize     = KCrashRODataSize + aTid + 2;
       
   391     segInfo->iRoDataRunAddr  = KCrashRODataRunAddr + aTid + 2;
       
   392     segInfo->iRoDataLoadAddr = KCrashRODataLoadAddr + aTid + 2;
       
   393     segInfo->iDataSize       = KCrashDataSize + aTid + 2;
       
   394     segInfo->iDataRunAddr    = KCrashDataRunAddr + aTid + 2;
       
   395     segInfo->iDataLoadAddr   = KCrashDataLoadAddr + aTid + 2;
       
   396 	segInfo->iType			 = EDllCodeSegType;
       
   397     err = aCodeSegs.Append(segInfo);
       
   398 	if(err != KErrNone)
       
   399 		{
       
   400         delete segInfo;
       
   401         User::Leave(err);
       
   402         }
       
   403 	aTotalCodeSegListDescSize += sizeof(TCodeSegInfo);
       
   404 
       
   405 	}
       
   406 
       
   407 void CTestCrashDataSource::ReadTraceBufferL(TDes8 &aTraceData )
       
   408 	{
       
   409 	User::Leave(KErrNotSupported);
       
   410 	}
       
   411 
       
   412 void CTestCrashDataSource::GetLocksL(TSCMLockData& aLockData)
       
   413 	{
       
   414 	User::Leave(KErrNotSupported);
       
   415 	}
       
   416 
       
   417 void CTestCrashDataSource::GetROMBuildInfoL(TRomHeaderData& aRomHeader)
       
   418 	{
       
   419 	User::Leave(KErrNotSupported);
       
   420 	}
       
   421 
       
   422 TUint CTestCrashDataSource::GetExceptionStackSizeL(const Debug::TArmProcessorModes aMode)
       
   423 	{
       
   424 	User::Leave(KErrNotSupported);
       
   425 	return 0;
       
   426 	}
       
   427 
       
   428 void CTestCrashDataSource::GetExceptionStackL(const Debug::TArmProcessorModes aMode, TDes8& aStack, TUint aStartReadPoint)
       
   429 	{
       
   430 	User::Leave(KErrNotSupported);
       
   431 	}
       
   432 
       
   433 TInt CTestCrashDataSource::GetDataSourceFunctionality(TDes8& aFuncBuffer)
       
   434 	{
       
   435 	return KErrNotSupported;
       
   436 	}
       
   437 
       
   438 TInt CTestCrashDataSource::GetDataSourceFunctionalityBufSize(TUint& aBufSize)
       
   439 	{
       
   440 	return KErrNotSupported;
       
   441 	}
       
   442 
       
   443 TVersion CTestCrashDataSource::GetVersion() const
       
   444 	{
       
   445 	TVersion ver(2,0,0);
       
   446 	return ver;
       
   447 	}
       
   448 
       
   449 TInt CTestCrashDataSource::GetVariantSpecificDataSize(TUint& aDataSize)
       
   450 	{
       
   451 	aDataSize = 0;
       
   452 	return KErrNotSupported;
       
   453 	}
       
   454 
       
   455 TInt CTestCrashDataSource::GetVariantSpecificData(TDes8& aVarSpecData)
       
   456 	{
       
   457 	(void)aVarSpecData;
       
   458 	return KErrNotSupported;
       
   459 	}
       
   460 
       
   461 //eof
       
   462