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