memspy/Engine/Source/Helpers/MemSpyEngineHelperFbServ.cpp
branchRCL_3
changeset 21 52e343bb8f80
parent 20 ca8a1b6995f6
equal deleted inserted replaced
20:ca8a1b6995f6 21:52e343bb8f80
   298     HBufC8* heapCellData = NULL;
   298     HBufC8* heapCellData = NULL;
   299 
   299 
   300     // Get the heap info - we need this for verification purposes
   300     // Get the heap info - we need this for verification purposes
   301     TMemSpyHeapInfo info;
   301     TMemSpyHeapInfo info;
   302     TInt err = iEngine.Driver().GetHeapInfoUser( info, aFbServThread.Id() );
   302     TInt err = iEngine.Driver().GetHeapInfoUser( info, aFbServThread.Id() );
   303     if ( err == KErrNone && info.Type() == TMemSpyHeapInfo::ETypeUnknown )
   303     if ( err == KErrNone && info.Type() != TMemSpyHeapInfo::ETypeRHeap )
   304         {
   304         {
   305         err = KErrNotSupported;
   305         err = KErrNotSupported;
   306         }
   306         }
   307     User::LeaveIfError( err );
   307     User::LeaveIfError( err );
       
   308     TRACE( RDebug::Printf("CMemSpyEngineHelperFbServ::LocateCFbTopHeapCellDataLC() - allocated cell header length is: %d", info.AsRHeap().MetaData().HeaderSizeAllocated() ));
   308 
   309 
   309     // Now walk the heap!
   310     // Now walk the heap!
   310     err = iEngine.Driver().WalkHeapInit( aFbServThread.Id() );
   311     err = iEngine.Driver().WalkHeapInit( aFbServThread.Id() );
   311     if  ( err == KErrNone )
   312     if  ( err == KErrNone )
   312         {
   313         {
   321         for( TInt cellIndex = KFbServWillingToStartAtCellIndex; err == KErrNone && cellIndex < KFbServWillingToSearchUntilCellIndex; cellIndex++ )
   322         for( TInt cellIndex = KFbServWillingToStartAtCellIndex; err == KErrNone && cellIndex < KFbServWillingToSearchUntilCellIndex; cellIndex++ )
   322             {
   323             {
   323             err = iEngine.Driver().WalkHeapNextCell( aFbServThread.Id(), cellType, cellAddress, cellLength, cellNestingLevel, cellAllocationNumber, cellHeaderSize, cellPayloadAddress );
   324             err = iEngine.Driver().WalkHeapNextCell( aFbServThread.Id(), cellType, cellAddress, cellLength, cellNestingLevel, cellAllocationNumber, cellHeaderSize, cellPayloadAddress );
   324             TRACE( RDebug::Printf("CMemSpyEngineHelperFbServ::LocateCFbTopHeapCellDataLC() - cellIndex[%d] err: %d, cellLength: %d, cellAllocationNumber: %d, cellType: %d", cellIndex, err, cellLength, cellAllocationNumber, cellType));
   325             TRACE( RDebug::Printf("CMemSpyEngineHelperFbServ::LocateCFbTopHeapCellDataLC() - cellIndex[%d] err: %d, cellLength: %d, cellAllocationNumber: %d, cellType: %d", cellIndex, err, cellLength, cellAllocationNumber, cellType));
   325 
   326 
   326             if  ( err == KErrNone && (cellType & EMemSpyDriverAllocatedCellMask))
   327             if  ( err == KErrNone && cellType == EMemSpyDriverGoodAllocatedCell )
   327                 {
   328                 {
   328                 // We know we are looking for a relatively large *allocated* cell.
   329                 // We know we are looking for a relatively large *allocated* cell.
   329                 if  ( cellLength >= KFbServExpectedMinimumCellSize && cellLength <= KFbServExpectedMaximumCellSize )
   330                 if  ( cellLength >= KFbServExpectedMinimumCellSize && cellLength <= KFbServExpectedMaximumCellSize && cellType == EMemSpyDriverGoodAllocatedCell )
   330                     {
   331                     {
   331                     const TInt payloadLength = cellLength;
   332                     const TInt payloadLength = cellLength - info.AsRHeap().MetaData().HeaderSizeAllocated();
       
   333                     TRACE( RDebug::Printf("CMemSpyEngineHelperFbServ::LocateCFbTopHeapCellDataLC() - cell was long enough. Full cell len: %d, header: %d, therefore dataLen: %d", cellLength, info.AsRHeap().MetaData().HeaderSizeAllocated(), payloadLength));
   332 
   334 
   333                     // This is *probably* the right cell. Let's get the data and check.
   335                     // This is *probably* the right cell. Let's get the data and check.
   334                     HBufC8* data = HBufC8::NewLC( payloadLength );
   336                     HBufC8* data = HBufC8::NewLC( payloadLength );
   335                     TPtr8 pData( data->Des() );
   337                     TPtr8 pData( data->Des() );
   336                     //
   338                     //
   341                         {
   343                         {
   342                         //_LIT(KHeapDumpDataFormat, "%S");
   344                         //_LIT(KHeapDumpDataFormat, "%S");
   343                         //iEngine.Sink().OutputBinaryDataL( KHeapDumpDataFormat, pData.Ptr(), (const TUint8*) cellAddress, pData.Length() );
   345                         //iEngine.Sink().OutputBinaryDataL( KHeapDumpDataFormat, pData.Ptr(), (const TUint8*) cellAddress, pData.Length() );
   344                     
   346                     
   345                         // Check the data
   347                         // Check the data
   346                         const TUint heapMaxSize = info.AsRHeap().MetaData().iMaxHeapSize;
   348                         const TUint heapSize = info.AsRHeap().ObjectData().Size();
   347                         const TUint heapBaseAddress = (TUint) info.AsRHeap().MetaData().ChunkBaseAddress();
   349                         const TUint heapBaseAddress = (TUint) info.AsRHeap().ObjectData().Base();
   348                         const TBool correctHeapCellLocated = VerifyCorrectHeapCellL( *data, cellAddress, cellPayloadAddress, heapBaseAddress, heapMaxSize );
   350                         const TBool correctHeapCellLocated = VerifyCorrectHeapCellL( *data, cellAddress, cellPayloadAddress, heapBaseAddress, heapSize );
   349                         TRACE( RDebug::Printf("CMemSpyEngineHelperFbServ::LocateCFbTopHeapCellDataLC() - verified: %d", correctHeapCellLocated));
   351                         TRACE( RDebug::Printf("CMemSpyEngineHelperFbServ::LocateCFbTopHeapCellDataLC() - verified: %d", correctHeapCellLocated));
   350 
   352 
   351                         if  ( correctHeapCellLocated )
   353                         if  ( correctHeapCellLocated )
   352                             {
   354                             {
   353                             aCellAddress = cellAddress;
   355                             aCellAddress = cellAddress;
   400 
   402 
   401     // NOTE: this call may change the value of 'cellAddress'
   403     // NOTE: this call may change the value of 'cellAddress'
   402     TInt err = iEngine.Driver().WalkHeapGetCellInfo( aCellAddress, cellType, cellLength, cellNestingLevel, cellAllocationNumber, cellHeaderSize, cellPayloadAddress );
   404     TInt err = iEngine.Driver().WalkHeapGetCellInfo( aCellAddress, cellType, cellLength, cellNestingLevel, cellAllocationNumber, cellHeaderSize, cellPayloadAddress );
   403     TRACE( RDebug::Printf("CMemSpyEngineHelperFbServ::ReadCObjectConInfoL() - err: %d, cellAddress: 0x%08x, cellLength: %d, cellAllocationNumber: %d, cellType: %d", err, aCellAddress, cellLength, cellAllocationNumber, cellType));
   405     TRACE( RDebug::Printf("CMemSpyEngineHelperFbServ::ReadCObjectConInfoL() - err: %d, cellAddress: 0x%08x, cellLength: %d, cellAllocationNumber: %d, cellType: %d", err, aCellAddress, cellLength, cellAllocationNumber, cellType));
   404 
   406 
   405 	if (err == KErrNone && (cellType & EMemSpyDriverAllocatedCellMask))
   407     if  ( err == KErrNone && cellType == EMemSpyDriverGoodAllocatedCell )
   406         {
   408         {
   407         // Check that the cell size meets our expectations - it should be a CObjectCon cell.
   409         // Check that the cell size meets our expectations - it should be a CObjectCon cell.
   408         const TInt expectedCellSize = sizeof(CObjectCon*) + cellHeaderSize;
   410         const TInt expectedCellSize = sizeof(CObjectCon*) + cellHeaderSize;
   409         TRACE( RDebug::Printf("CMemSpyEngineHelperFbServ::ReadCObjectConInfoL() - expectedCellSize: %d, actual: %d, address: 0x%08x", expectedCellSize, cellLength, aCellAddress));
   411         TRACE( RDebug::Printf("CMemSpyEngineHelperFbServ::ReadCObjectConInfoL() - expectedCellSize: %d, actual: %d, address: 0x%08x", expectedCellSize, cellLength, aCellAddress));
   410 
   412 
   516 
   518 
   517     // NOTE: this call may change the value of 'cellAddress'
   519     // NOTE: this call may change the value of 'cellAddress'
   518     TInt err = iEngine.Driver().WalkHeapGetCellInfo( aArrayCellAddress, cellType, cellLength, cellNestingLevel, cellAllocationNumber, cellHeaderSize, cellPayloadAddress );
   520     TInt err = iEngine.Driver().WalkHeapGetCellInfo( aArrayCellAddress, cellType, cellLength, cellNestingLevel, cellAllocationNumber, cellHeaderSize, cellPayloadAddress );
   519     TRACE( RDebug::Printf("CMemSpyEngineHelperFbServ::LocateCFbTopHeapCellDataLC() - err: %d, cellAddress: 0x%08x, cellLength: %d, cellAllocationNumber: %d, cellType: %d", err, aArrayCellAddress, cellLength, cellAllocationNumber, cellType));
   521     TRACE( RDebug::Printf("CMemSpyEngineHelperFbServ::LocateCFbTopHeapCellDataLC() - err: %d, cellAddress: 0x%08x, cellLength: %d, cellAllocationNumber: %d, cellType: %d", err, aArrayCellAddress, cellLength, cellAllocationNumber, cellType));
   520 
   522 
   521     if (err == KErrNone && (cellType & EMemSpyDriverAllocatedCellMask))
   523     if  ( err == KErrNone && cellType == EMemSpyDriverGoodAllocatedCell )
   522         {
   524         {
   523         // Check that the cell size meets our expectations. 
   525         // Check that the cell size meets our expectations. 
   524         // The cell should be a very specific length
   526         // The cell should be a very specific length
   525         const TInt expectedCellSize = (sizeof(CBase*) * aArrayAllocCount) + cellHeaderSize;
   527         const TInt expectedCellSize = (sizeof(CBase*) * aArrayAllocCount) + cellHeaderSize;
   526         TRACE( RDebug::Printf("CMemSpyEngineHelperFbServ::LocateBitmapArrayHeapCellDataLC() - expectedCellSize: %d, actual: %d, address: 0x%08x", expectedCellSize, cellLength, aArrayCellAddress));
   528         TRACE( RDebug::Printf("CMemSpyEngineHelperFbServ::LocateBitmapArrayHeapCellDataLC() - expectedCellSize: %d, actual: %d, address: 0x%08x", expectedCellSize, cellLength, aArrayCellAddress));
   573     // Tidy up
   575     // Tidy up
   574     CleanupStack::PopAndDestroy( &stream );
   576     CleanupStack::PopAndDestroy( &stream );
   575     }
   577     }
   576 
   578 
   577 
   579 
   578 TBool CMemSpyEngineHelperFbServ::VerifyCorrectHeapCellL( const TDesC8& aData, TAny* aCellAddress, TAny* aPayloadAddress, TUint aHeapStartingAddress, TUint aHeapMaxSize )
   580 TBool CMemSpyEngineHelperFbServ::VerifyCorrectHeapCellL( const TDesC8& aData, TAny* aCellAddress, TAny* aPayloadAddress, TUint aHeapStartingAddress, TUint aHeapSize )
   579     {
   581     {
   580     (void) aPayloadAddress;
   582     (void) aPayloadAddress;
   581     (void) aCellAddress;
   583     (void) aCellAddress;
   582     TRACE( RDebug::Printf("CMemSpyEngineHelperFbServ::VerifyCorrectHeapCellL() - START - aDataLen: %d, aCellAddress: 0x%08x, aPayloadAddress: 0x%08x, aHeapStartingAddress: 0x%08x, aHeapSize: %d", aData.Length(), aCellAddress, aPayloadAddress, aHeapStartingAddress, aHeapMaxSize ));
   584     TRACE( RDebug::Printf("CMemSpyEngineHelperFbServ::VerifyCorrectHeapCellL() - START - aDataLen: %d, aCellAddress: 0x%08x, aPayloadAddress: 0x%08x, aHeapStartingAddress: 0x%08x, aHeapSize: %d", aData.Length(), aCellAddress, aPayloadAddress, aHeapStartingAddress, aHeapSize ));
   583 
   585 
   584     const TUint KFbServHeapCeilingAddress = aHeapStartingAddress + aHeapMaxSize;
   586     const TUint KFbServHeapCeilingAddress = aHeapStartingAddress + aHeapSize;
   585 
   587 
   586     // Whether we can use this cell's data...
   588     // Whether we can use this cell's data...
   587     TBool correctCell = EFalse;
   589     TBool correctCell = EFalse;
   588 
   590 
   589     // We can use certain knowledge of the layout of the cell to work out
   591     // We can use certain knowledge of the layout of the cell to work out
   742 
   744 
   743     // NOTE: this call may change the value of 'cellAddress'
   745     // NOTE: this call may change the value of 'cellAddress'
   744     TInt err = iEngine.Driver().WalkHeapGetCellInfo( aCellAddress, cellType, cellLength, cellNestingLevel, cellAllocationNumber, cellHeaderSize, cellPayloadAddress );
   746     TInt err = iEngine.Driver().WalkHeapGetCellInfo( aCellAddress, cellType, cellLength, cellNestingLevel, cellAllocationNumber, cellHeaderSize, cellPayloadAddress );
   745     TRACE( RDebug::Printf("CMemSpyEngineHelperFbServ::GetBitmapObjectLC() - err: %d, cellAddress: 0x%08x, cellLength: %d, cellAllocationNumber: %d, cellType: %d", err, aCellAddress, cellLength, cellAllocationNumber, cellType));
   747     TRACE( RDebug::Printf("CMemSpyEngineHelperFbServ::GetBitmapObjectLC() - err: %d, cellAddress: 0x%08x, cellLength: %d, cellAllocationNumber: %d, cellType: %d", err, aCellAddress, cellLength, cellAllocationNumber, cellType));
   746 
   748 
   747     if (err == KErrNone && (cellType & EMemSpyDriverAllocatedCellMask))
   749     if  ( err == KErrNone && cellType == EMemSpyDriverGoodAllocatedCell )
   748         {
   750         {
   749         // Check that the cell size meets our expectations - it should be a CBitmapObject, but without the additional "this" pointer
   751         // Check that the cell size meets our expectations - it should be a CBitmapObject, but without the additional "this" pointer
   750         // which we have tacked onto the object.
   752         // which we have tacked onto the object.
   751         const TInt expectedCellSize = sizeof( CBitmapObject ) + cellHeaderSize - sizeof( CBitmapObject* );
   753         const TInt expectedCellSize = sizeof( CBitmapObject ) + cellHeaderSize - sizeof( CBitmapObject* );
   752         TRACE( RDebug::Printf("CMemSpyEngineHelperFbServ::GetBitmapObjectLC() - expectedCellSize: %d, actual: %d, address: 0x%08x", expectedCellSize, cellLength, aCellAddress));
   754         TRACE( RDebug::Printf("CMemSpyEngineHelperFbServ::GetBitmapObjectLC() - expectedCellSize: %d, actual: %d, address: 0x%08x", expectedCellSize, cellLength, aCellAddress));