memspy/Engine/Source/Helpers/MemSpyEngineHelperCodeSegment.cpp
changeset 51 98307c651589
parent 42 0ff24a8f6ca2
child 52 c2f44e33b468
equal deleted inserted replaced
42:0ff24a8f6ca2 51:98307c651589
     1 /*
       
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). 
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:
       
    15 *
       
    16 */
       
    17 
       
    18 #include <memspy/engine/memspyenginehelpercodesegment.h>
       
    19 
       
    20 // System includes
       
    21 #include <e32capability.h>
       
    22 #include <f32file.h>
       
    23 #include <babitflags.h>
       
    24 
       
    25 // Driver includes
       
    26 #include <memspy/driver/memspydriverclient.h>
       
    27 
       
    28 // User includes
       
    29 #include <memspy/engine/memspyengine.h>
       
    30 #include <memspy/engine/memspyengineutils.h>
       
    31 #include <memspy/engine/memspyengineoutputsink.h>
       
    32 #include <memspy/engine/memspyengineobjectthread.h>
       
    33 #include <memspy/engine/memspyengineobjectprocess.h>
       
    34 
       
    35 // Constants
       
    36 const TInt KMemSpyEngineMaxCodeSegmentCount = 512;
       
    37 
       
    38 // Literal constants
       
    39 _LIT( KMemSpyEngineCodeSegListOutputComma, ", " );
       
    40 
       
    41 
       
    42 
       
    43 CMemSpyEngineHelperCodeSegment::CMemSpyEngineHelperCodeSegment( CMemSpyEngine& aEngine )
       
    44 :   iEngine( aEngine )
       
    45     {
       
    46     }
       
    47 
       
    48     
       
    49 CMemSpyEngineHelperCodeSegment::~CMemSpyEngineHelperCodeSegment()
       
    50     {
       
    51     }
       
    52 
       
    53 
       
    54 void CMemSpyEngineHelperCodeSegment::ConstructL()
       
    55     {
       
    56     }
       
    57 
       
    58 
       
    59 CMemSpyEngineHelperCodeSegment* CMemSpyEngineHelperCodeSegment::NewL( CMemSpyEngine& aEngine )
       
    60     {
       
    61     CMemSpyEngineHelperCodeSegment* self = new(ELeave) CMemSpyEngineHelperCodeSegment( aEngine );
       
    62     CleanupStack::PushL( self );
       
    63     self->ConstructL();
       
    64     CleanupStack::Pop( self );
       
    65     return self;
       
    66     }
       
    67 
       
    68 
       
    69 EXPORT_C void CMemSpyEngineHelperCodeSegment::OutputCodeSegmentsL( TUint aPid, TDes& aLine, const TDesC& aPrefix, TChar aSectionUnderlineCharacter, TBool aLowerCaseSectionHeading)
       
    70     {
       
    71 	_LIT(KHeaderLC, "Code Segments");
       
    72 	_LIT(KHeaderUC, "CODE SEGMENTS");
       
    73 
       
    74 	_LIT(KFmtOverflow, "Only first %d code segments displayed");
       
    75 	_LIT(KFmtMod, "%S%08X-%08X %S");
       
    76 
       
    77 	const TInt KMaxCount = 256;
       
    78 	TAny* handles[KMaxCount];
       
    79 	TInt c = KMaxCount;
       
    80 
       
    81 	TInt r = iEngine.Driver().GetCodeSegs(aPid, handles, c);
       
    82 	if  ( r == KErrNone )
       
    83     	{
       
    84         if  ( c > 0 )
       
    85             {
       
    86             if  ( aLowerCaseSectionHeading )
       
    87                 {
       
    88                 iEngine.Sink().OutputSectionHeadingL( KHeaderLC, aSectionUnderlineCharacter );
       
    89                 }
       
    90             else
       
    91                 {
       
    92             	iEngine.Sink().OutputSectionHeadingL( KHeaderUC, aSectionUnderlineCharacter );
       
    93                 }
       
    94 
       
    95         	if (c > KMaxCount)
       
    96         		{
       
    97         		c = KMaxCount;
       
    98         		aLine.Format(KFmtOverflow, c);
       
    99         		iEngine.Sink().OutputLineL( aLine );
       
   100         		}
       
   101 
       
   102         	TBuf<KMaxFileName> path;
       
   103         	TMemSpyDriverCodeSegInfo info;
       
   104         	for (TInt i=0; i<c; i++)
       
   105         		{
       
   106         		r = iEngine.Driver().GetCodeSegInfo(handles[i], aPid, info);
       
   107                 //
       
   108         		if  ( r == KErrNone )
       
   109         			{
       
   110         			path.Copy( info.iCreateInfo.iFileName );
       
   111         			aLine.Format(KFmtMod, &aPrefix, info.iMemoryInfo.iCodeBase,info.iMemoryInfo.iCodeBase + info.iMemoryInfo.iCodeSize, &path);
       
   112         			iEngine.Sink().OutputLineL( aLine );
       
   113         			}
       
   114         		}
       
   115             }
       
   116         }
       
   117    }
       
   118 
       
   119 
       
   120 EXPORT_C CMemSpyEngineCodeSegList* CMemSpyEngineHelperCodeSegment::CodeSegmentListL()
       
   121     {
       
   122     RArray<TAny*> handles( 16 );
       
   123     CleanupClosePushL( handles );
       
   124 
       
   125     // Get everything
       
   126     GetCodeSegmentHandlesL( handles, NULL, EFalse );
       
   127     CMemSpyEngineCodeSegList* list = ListFromHandlesLC( handles );
       
   128     //
       
   129     CleanupStack::Pop( list );
       
   130     CleanupStack::PopAndDestroy( &handles );
       
   131     //
       
   132     return list;
       
   133     }
       
   134 
       
   135 
       
   136 CMemSpyEngineCodeSegList* CMemSpyEngineHelperCodeSegment::CodeSegmentListRamLoadedL()
       
   137     {
       
   138     RArray<TAny*> handles( 16 );
       
   139     CleanupClosePushL( handles );
       
   140 
       
   141     // Get just RAM-loaded
       
   142     GetCodeSegmentHandlesL( handles, NULL, ETrue );
       
   143     CMemSpyEngineCodeSegList* list = ListFromHandlesLC( handles );
       
   144     //
       
   145     CleanupStack::Pop( list );
       
   146     CleanupStack::PopAndDestroy( &handles );
       
   147     //
       
   148     return list;
       
   149     }
       
   150 
       
   151 
       
   152 EXPORT_C CMemSpyEngineCodeSegList* CMemSpyEngineHelperCodeSegment::CodeSegmentListL( TProcessId aProcess )
       
   153     {
       
   154     TUint processId = aProcess;
       
   155     //
       
   156     RArray<TAny*> handles( 16 );
       
   157     CleanupClosePushL( handles );
       
   158     
       
   159     // Get process-specific list
       
   160     GetCodeSegmentHandlesL( handles, &processId, EFalse );
       
   161     CMemSpyEngineCodeSegList* list = ListFromHandlesLC( handles );
       
   162     //
       
   163     CleanupStack::Pop( list );
       
   164     CleanupStack::PopAndDestroy( &handles );
       
   165     //
       
   166     return list;
       
   167     }
       
   168 
       
   169 
       
   170 void CMemSpyEngineHelperCodeSegment::GetCodeSegmentHandlesL( RArray<TAny*>& aHandles, TUint* aProcessId, TBool aRamOnly ) const
       
   171     {
       
   172 	TAny* handles[ KMemSpyEngineMaxCodeSegmentCount ];
       
   173 	TInt count = KMemSpyEngineMaxCodeSegmentCount;
       
   174 
       
   175 	TInt r = KErrNone;
       
   176 	
       
   177 	if  ( aProcessId == NULL )
       
   178     	{
       
   179 	    r = iEngine.Driver().GetCodeSegs( handles, count, aRamOnly );
       
   180 	    }
       
   181     else
       
   182 	    {
       
   183 	    r = iEngine.Driver().GetCodeSegs( *aProcessId, handles, count );
       
   184 	    }
       
   185 
       
   186 	if  ( r == KErrNone )
       
   187     	{
       
   188         TInt index;
       
   189         TLinearOrder< TAny* > comparer( SortByAddress );
       
   190         
       
   191         // Remove duplicates - since we reqested code segments for all processes, there
       
   192         // might be some dupes.
       
   193         count = Min( count, KMemSpyEngineMaxCodeSegmentCount );
       
   194         for( index = 0; index < count; index++ )
       
   195             {
       
   196             TAny* handle = handles[ index ];
       
   197             const TInt error = aHandles.InsertInOrder( handle, comparer );
       
   198             //
       
   199             if  ( ! (error == KErrNone || error == KErrAlreadyExists ) )
       
   200                 {
       
   201                 User::Leave( error );
       
   202                 }
       
   203             }
       
   204         }
       
   205     }
       
   206 
       
   207 
       
   208 CMemSpyEngineCodeSegList* CMemSpyEngineHelperCodeSegment::ListFromHandlesLC( RArray<TAny*>& aHandles ) const
       
   209     {
       
   210     CMemSpyEngineCodeSegList* list = CMemSpyEngineCodeSegList::NewLC( iEngine );
       
   211     //
       
   212     TMemSpyDriverCodeSegInfo info;
       
   213     const TInt count = aHandles.Count();
       
   214     //
       
   215     for (TInt i=0; i<count; i++)
       
   216         {
       
   217         TAny* handle = aHandles[ i ];
       
   218         const TInt err = iEngine.Driver().GetCodeSegInfo( handle, 0, info );
       
   219         //
       
   220         if  ( err == KErrNone )
       
   221         	{
       
   222             // Create item
       
   223             CMemSpyEngineCodeSegEntry* entry = CMemSpyEngineCodeSegEntry::NewLC( handle, info.iSize, info.iCreateInfo, info.iMemoryInfo );
       
   224             list->AddItemL( entry );
       
   225             CleanupStack::Pop( entry );
       
   226         	}
       
   227         }
       
   228     //
       
   229     return list;
       
   230     }
       
   231 
       
   232 
       
   233 TInt CMemSpyEngineHelperCodeSegment::SortByAddress( TAny* const& aLeft, TAny* const& aRight )
       
   234     {
       
   235     TInt ret = 1;
       
   236     //
       
   237     if  ( aLeft < aRight )
       
   238         {
       
   239         ret = -1;
       
   240         }
       
   241     else if ( aLeft == aRight )
       
   242         {
       
   243         ret = 0;
       
   244         }
       
   245     //
       
   246     return ret;
       
   247     }
       
   248 
       
   249 
       
   250 
       
   251 
       
   252 
       
   253 
       
   254 
       
   255 
       
   256 
       
   257 
       
   258 
       
   259 
       
   260 
       
   261 
       
   262 
       
   263 
       
   264 
       
   265 
       
   266 
       
   267 
       
   268 
       
   269 
       
   270 
       
   271 
       
   272 
       
   273 
       
   274 
       
   275 
       
   276 
       
   277 
       
   278 
       
   279 CMemSpyEngineCodeSegList::CMemSpyEngineCodeSegList( CMemSpyEngine& aEngine )
       
   280 :   CMemSpyEngineTwiddlableItemArray<CMemSpyEngineCodeSegEntry>( aEngine )
       
   281     {
       
   282     }
       
   283 
       
   284 
       
   285 void CMemSpyEngineCodeSegList::ConstructL()
       
   286     {
       
   287     }
       
   288 
       
   289 
       
   290 CMemSpyEngineCodeSegList* CMemSpyEngineCodeSegList::NewLC( CMemSpyEngine& aEngine )
       
   291     {
       
   292     CMemSpyEngineCodeSegList* self = new(ELeave) CMemSpyEngineCodeSegList( aEngine );
       
   293     CleanupStack::PushL( self );
       
   294     self->ConstructL();
       
   295     return self;
       
   296     }
       
   297 
       
   298     
       
   299 EXPORT_C TInt CMemSpyEngineCodeSegList::IndexByHandle( TAny* aHandle ) const
       
   300     {
       
   301     TInt index = KErrNotFound;
       
   302     //
       
   303     const TInt count = Count();
       
   304     for(TInt i=0; i<count; i++)
       
   305         {
       
   306         const CMemSpyEngineCodeSegEntry& entry = At( i );
       
   307         if  ( entry.Handle() == aHandle )
       
   308             {
       
   309             index = i;
       
   310             break;
       
   311             }
       
   312         }
       
   313     //
       
   314     return index;
       
   315     }
       
   316 
       
   317 
       
   318 EXPORT_C void CMemSpyEngineCodeSegList::SortByFileNameL()
       
   319     {
       
   320     TLinearOrder< CMemSpyEngineCodeSegEntry > comparer( CompareByFileName );
       
   321     Sort( comparer );
       
   322     }
       
   323 
       
   324 
       
   325 EXPORT_C void CMemSpyEngineCodeSegList::SortByCodeSizeL()
       
   326     {
       
   327     TLinearOrder< CMemSpyEngineCodeSegEntry > comparer( CompareByCodeSize );
       
   328     Sort( comparer );
       
   329     }
       
   330 
       
   331 
       
   332 EXPORT_C void CMemSpyEngineCodeSegList::SortByDataSizeL()
       
   333     {
       
   334     TLinearOrder< CMemSpyEngineCodeSegEntry > comparer( CompareByDataSize );
       
   335     Sort( comparer );
       
   336     }
       
   337 
       
   338 
       
   339 EXPORT_C void CMemSpyEngineCodeSegList::SortByUidsL()
       
   340     {
       
   341     TLinearOrder< CMemSpyEngineCodeSegEntry > comparer( CompareByUid );
       
   342     Sort( comparer );
       
   343     }
       
   344 
       
   345 
       
   346 EXPORT_C void CMemSpyEngineCodeSegList::ShowOnlyEntriesWithGlobalDataL()
       
   347     {
       
   348     TMemSpyEngineVisibiltyFunction< CMemSpyEngineCodeSegEntry > function( VisibilityFunctionGlobalData, NULL );
       
   349     ShowL( function );
       
   350     SortByDataSizeL();
       
   351     }
       
   352 
       
   353 
       
   354 EXPORT_C void CMemSpyEngineCodeSegList::OutputDataColumnsL( CMemSpyEngine& aEngine )
       
   355     {
       
   356     HBufC* columns = HBufC::NewLC( 1500 );
       
   357     TPtr pColumns( columns->Des() );
       
   358 
       
   359     //
       
   360     _LIT(KCol1, "Name");
       
   361     pColumns.Append( KCol1 );
       
   362     pColumns.Append( KMemSpyEngineCodeSegListOutputComma );
       
   363 
       
   364     //
       
   365     _LIT(KCol2, "Uid %d");
       
   366     pColumns.AppendFormat( KCol2, 1 );
       
   367     pColumns.Append( KMemSpyEngineCodeSegListOutputComma );
       
   368     pColumns.AppendFormat( KCol2, 2 );
       
   369     pColumns.Append( KMemSpyEngineCodeSegListOutputComma );
       
   370     pColumns.AppendFormat( KCol2, 3 );
       
   371     pColumns.Append( KMemSpyEngineCodeSegListOutputComma );
       
   372 
       
   373     //
       
   374     _LIT(KCol3, "Module Version");
       
   375     pColumns.Append( KCol3 );
       
   376     pColumns.Append( KMemSpyEngineCodeSegListOutputComma );
       
   377 
       
   378     //
       
   379     _LIT(KCol4, "SID");
       
   380     pColumns.Append( KCol4 );
       
   381     pColumns.Append( KMemSpyEngineCodeSegListOutputComma );
       
   382 
       
   383     //
       
   384     _LIT(KCol5, "VID");
       
   385     pColumns.Append( KCol5 );
       
   386     pColumns.Append( KMemSpyEngineCodeSegListOutputComma );
       
   387 
       
   388     //
       
   389     _LIT(KCol6, "Code Size");
       
   390     pColumns.Append( KCol6 );
       
   391     pColumns.Append( KMemSpyEngineCodeSegListOutputComma );
       
   392 
       
   393     //
       
   394     _LIT(KCol7, "Text Size");
       
   395     pColumns.Append( KCol7 );
       
   396     pColumns.Append( KMemSpyEngineCodeSegListOutputComma );
       
   397 
       
   398     //
       
   399     _LIT(KCol8, "Data Size");
       
   400     pColumns.Append( KCol8 );
       
   401     pColumns.Append( KMemSpyEngineCodeSegListOutputComma );
       
   402 
       
   403     //
       
   404     _LIT(KCol9, "BSS Size");
       
   405     pColumns.Append( KCol9 );
       
   406     pColumns.Append( KMemSpyEngineCodeSegListOutputComma );
       
   407 
       
   408     //
       
   409     _LIT(KCol10, "Total Data Size");
       
   410     pColumns.Append( KCol10 );
       
   411     pColumns.Append( KMemSpyEngineCodeSegListOutputComma );
       
   412 
       
   413     //
       
   414     _LIT(KCol11, "Entrypoint Veneer");
       
   415     pColumns.Append( KCol11 );
       
   416     pColumns.Append( KMemSpyEngineCodeSegListOutputComma );
       
   417 
       
   418     //
       
   419     _LIT(KCol12, "File Entrypoint");
       
   420     pColumns.Append( KCol12 );
       
   421     pColumns.Append( KMemSpyEngineCodeSegListOutputComma );
       
   422 
       
   423     //
       
   424     _LIT(KCol13, "Dependency Count");
       
   425     pColumns.Append( KCol13 );
       
   426     pColumns.Append( KMemSpyEngineCodeSegListOutputComma );
       
   427 
       
   428     //
       
   429     _LIT(KCol14, "ROM Code Load Address");
       
   430     pColumns.Append( KCol14 );
       
   431     pColumns.Append( KMemSpyEngineCodeSegListOutputComma );
       
   432 
       
   433     //
       
   434     _LIT(KCol15, "Data Load Address");
       
   435     pColumns.Append( KCol15 );
       
   436 
       
   437     //
       
   438     _LIT(KCol16, "Capabilities...");
       
   439     pColumns.Append( KCol16 );
       
   440 
       
   441     //
       
   442     aEngine.Sink().OutputLineL( pColumns );
       
   443     CleanupStack::PopAndDestroy( columns );
       
   444     }
       
   445 
       
   446 
       
   447 EXPORT_C TInt CMemSpyEngineCodeSegList::MdcaCount() const
       
   448     {
       
   449     return Count();
       
   450     }
       
   451 
       
   452 
       
   453 EXPORT_C TPtrC CMemSpyEngineCodeSegList::MdcaPoint( TInt aIndex ) const
       
   454     {
       
   455     const CMemSpyEngineCodeSegEntry& item = At( aIndex );
       
   456     return TPtrC( item.Caption() );
       
   457     }
       
   458 
       
   459 
       
   460 TInt CMemSpyEngineCodeSegList::IndexByName( const TDesC& aName ) const
       
   461     {
       
   462     TInt index = KErrNotFound;
       
   463     //
       
   464     const TInt count = Count();
       
   465     for(TInt i=0; i<count; i++)
       
   466         {
       
   467         const CMemSpyEngineCodeSegEntry& entry = At( i );
       
   468         if  ( entry.FileName().FindF( aName ) >= 0 )
       
   469             {
       
   470             index = i;
       
   471             break;
       
   472             }
       
   473         }
       
   474     //
       
   475     return index;
       
   476     }
       
   477 
       
   478 
       
   479 TInt CMemSpyEngineCodeSegList::CompareByFileName( const CMemSpyEngineCodeSegEntry& aLeft, const CMemSpyEngineCodeSegEntry& aRight )
       
   480     {
       
   481     const TInt ret = aLeft.FileName().CompareF( aRight.FileName() );
       
   482     return ret;
       
   483     }
       
   484 
       
   485 
       
   486 TInt CMemSpyEngineCodeSegList::CompareByCodeSize( const CMemSpyEngineCodeSegEntry& aLeft, const CMemSpyEngineCodeSegEntry& aRight )
       
   487     {
       
   488     TInt ret = -1;
       
   489     //
       
   490     if  ( aLeft.CreateInfo().iCodeSize < aRight.CreateInfo().iCodeSize )
       
   491         {
       
   492         ret = 1;
       
   493         }
       
   494     else if ( aLeft.CreateInfo().iCodeSize == aRight.CreateInfo().iCodeSize )
       
   495         {
       
   496         ret = 0;
       
   497         }
       
   498     //
       
   499     return ret;
       
   500     }
       
   501 
       
   502 
       
   503 TInt CMemSpyEngineCodeSegList::CompareByDataSize( const CMemSpyEngineCodeSegEntry& aLeft, const CMemSpyEngineCodeSegEntry& aRight )
       
   504     {
       
   505     TInt ret = -1;
       
   506     //
       
   507     if  ( aLeft.CreateInfo().iTotalDataSize < aRight.CreateInfo().iTotalDataSize )
       
   508         {
       
   509         ret = 1;
       
   510         }
       
   511     else if ( aLeft.CreateInfo().iTotalDataSize == aRight.CreateInfo().iTotalDataSize )
       
   512         {
       
   513         ret = 0;
       
   514         }
       
   515     //
       
   516     return ret;
       
   517     }
       
   518 
       
   519 
       
   520 TInt CMemSpyEngineCodeSegList::CompareByUid( const CMemSpyEngineCodeSegEntry& aLeft, const CMemSpyEngineCodeSegEntry& aRight )
       
   521     {
       
   522     TInt ret = -1;
       
   523     //
       
   524     if  ( aLeft.CreateInfo().iUids.MostDerived().iUid < aRight.CreateInfo().iUids.MostDerived().iUid )
       
   525         {
       
   526         ret = 1;
       
   527         }
       
   528     else if ( aLeft.CreateInfo().iUids.MostDerived().iUid == aRight.CreateInfo().iUids.MostDerived().iUid )
       
   529         {
       
   530         ret = 0;
       
   531         }
       
   532     //
       
   533     return ret;
       
   534     }
       
   535 
       
   536 
       
   537 TBool CMemSpyEngineCodeSegList::VisibilityFunctionGlobalData( const CMemSpyEngineCodeSegEntry*& aItem, TAny* /*aRune*/ )
       
   538     {
       
   539     const TBool hasGlobalData = ( aItem->CreateInfo().iTotalDataSize > 0 );
       
   540     return hasGlobalData;
       
   541     }
       
   542 
       
   543 
       
   544 
       
   545 
       
   546 
       
   547 
       
   548 
       
   549 
       
   550 
       
   551 
       
   552 
       
   553 
       
   554 
       
   555 
       
   556 
       
   557 
       
   558 
       
   559 
       
   560 CMemSpyEngineCodeSegEntry::CMemSpyEngineCodeSegEntry( TAny* aHandle, TInt aSize, const TCodeSegCreateInfo& aCreateInfo, const TProcessMemoryInfo& aMemoryInfo )
       
   561 :   CDesCArrayFlat( 10 ), iHandle( aHandle ), iSize( aSize ), iCreateInfo( aCreateInfo ), iMemoryInfo( aMemoryInfo )
       
   562     {
       
   563     }
       
   564 
       
   565 
       
   566 EXPORT_C CMemSpyEngineCodeSegEntry::~CMemSpyEngineCodeSegEntry()
       
   567     {
       
   568     delete iCaption;
       
   569     delete iFileName;
       
   570     }
       
   571 
       
   572 
       
   573 void CMemSpyEngineCodeSegEntry::ConstructL()
       
   574     {
       
   575     iFileName = HBufC::NewL( iCreateInfo.iFileName.Length() );
       
   576     iFileName->Des().Copy( iCreateInfo.iFileName );
       
   577 
       
   578     // Make caption
       
   579     TParsePtrC parser( *iFileName );
       
   580     const TPtrC pFileNameWithoutPath( parser.NameAndExt() );
       
   581     TBuf<KMaxFullName + 128> item;
       
   582     //
       
   583     _LIT(KCodeSegFormat, "\t%S\t\t%S code");
       
   584     const TMemSpySizeText codeSize( MemSpyEngineUtils::FormatSizeText( iCreateInfo.iCodeSize ) );
       
   585     item.Format( KCodeSegFormat, &pFileNameWithoutPath, &codeSize );
       
   586     if  ( iCreateInfo.iDataSize > 0 )
       
   587         {
       
   588         _LIT(KCodeSegFormatAdditionalData, ", %S data");
       
   589         const TMemSpySizeText dataSize( MemSpyEngineUtils::FormatSizeText( iCreateInfo.iTotalDataSize ) );
       
   590         item.AppendFormat( KCodeSegFormatAdditionalData, &dataSize );
       
   591         }
       
   592     iCaption = item.AllocL();
       
   593 
       
   594     //
       
   595     _LIT(KItem0, "\tName\t\t%S");
       
   596     item.Format( KItem0, &pFileNameWithoutPath );
       
   597     AppendL( item );
       
   598 
       
   599     // Uids
       
   600     const TUidType uids( iCreateInfo.iUids );
       
   601     for( TInt i=0; i<KMaxCheckedUid; i++ )
       
   602         {
       
   603         _LIT(KItem1, "\tUid #%d\t\t0x%08x");
       
   604         const TUid uidValue( uids[ i ] );
       
   605         //
       
   606         item.Format( KItem1, i+1, uidValue.iUid );
       
   607         AppendL( item );
       
   608         }
       
   609     //
       
   610     if  ( iCreateInfo.iModuleVersion == KModuleVersionWild )
       
   611         {
       
   612         _LIT(KItem12, "\tModule Version\t\t[Wild]");
       
   613         AppendL( KItem12 );
       
   614         }
       
   615     else if ( iCreateInfo.iModuleVersion == KModuleVersionNull )
       
   616         {
       
   617         _LIT(KItem12, "\tModule Version\t\t[Null]");
       
   618         AppendL( KItem12 );
       
   619         }
       
   620     else
       
   621         {
       
   622         _LIT(KItem12, "\tModule Version\t\t0x%08x");
       
   623         item.Format( KItem12, iCreateInfo.iModuleVersion );
       
   624         AppendL( item );
       
   625         }
       
   626 
       
   627     //
       
   628     _LIT(KItem13, "\tSID\t\t0x%08x");
       
   629     item.Format( KItem13, iCreateInfo.iS.iSecureId );
       
   630     AppendL( item );
       
   631 
       
   632     //
       
   633     _LIT(KItem14, "\tVID\t\t0x%08x");
       
   634     item.Format( KItem14, iCreateInfo.iS.iVendorId );
       
   635     AppendL( item );
       
   636 
       
   637     //
       
   638     if  ( iCreateInfo.iCodeSize > 0 )
       
   639         {
       
   640         _LIT(KItem2, "\tCode Size\t\t%d");
       
   641         item.Format( KItem2, iCreateInfo.iCodeSize );
       
   642         AppendL( item );
       
   643         }
       
   644 
       
   645     //
       
   646     if  ( iCreateInfo.iTotalDataSize > 0 )
       
   647         {
       
   648         _LIT(KItem6, "\tTotal Data Size\t\t%d");
       
   649         item.Format( KItem6, iCreateInfo.iTotalDataSize );
       
   650         AppendL( item );
       
   651         }
       
   652 
       
   653     //
       
   654     if  ( iCreateInfo.iTextSize > 0 )
       
   655         {
       
   656         _LIT(KItem3, "\tText Size\t\t%d");
       
   657         item.Format( KItem3, iCreateInfo.iTextSize );
       
   658         AppendL( item );
       
   659         }
       
   660 
       
   661     //
       
   662     if  ( iCreateInfo.iDataSize > 0 )
       
   663         {
       
   664         _LIT(KItem4, "\tData Size\t\t%d");
       
   665         item.Format( KItem4, iCreateInfo.iDataSize );
       
   666         AppendL( item );
       
   667         }
       
   668 
       
   669     //
       
   670     if  ( iCreateInfo.iBssSize > 0 )
       
   671         {
       
   672         _LIT(KItem5, "\tBSS Size\t\t%d");
       
   673         item.Format( KItem5, iCreateInfo.iBssSize );
       
   674         AppendL( item );
       
   675         }
       
   676 
       
   677     //
       
   678     _LIT(KItem7, "\tEntrypoint Veneer\t\t0x%08x");
       
   679     item.Format( KItem7, iCreateInfo.iEntryPtVeneer );
       
   680     AppendL( item );
       
   681 
       
   682     //
       
   683     _LIT(KItem8, "\tFile Entrypoint\t\t0x%08x");
       
   684     item.Format( KItem8, iCreateInfo.iFileEntryPoint );
       
   685     AppendL( item );
       
   686 
       
   687     //
       
   688     _LIT(KItem9, "\tDependency Count\t\t%d");
       
   689     item.Format( KItem9, iCreateInfo.iDepCount );
       
   690     AppendL( item );
       
   691 
       
   692     //
       
   693     if  ( iCreateInfo.iCodeLoadAddress != 0 )
       
   694         {
       
   695         _LIT(KItem10, "\tROM Code Load Addr.\t\t0x%08x");
       
   696         item.Format( KItem10, iCreateInfo.iCodeLoadAddress );
       
   697         AppendL( item );
       
   698         }
       
   699     else
       
   700         {
       
   701         _LIT(KItem10, "\tROM Code Load Addr.\t\t[RAM Loaded]");
       
   702         AppendL( KItem10 );
       
   703         }
       
   704 
       
   705     //
       
   706     if  ( iCreateInfo.iDataLoadAddress != 0 )
       
   707         {
       
   708         _LIT(KItem11, "\tData Load Addr.\t\t0x%08x");
       
   709         item.Format( KItem11, iCreateInfo.iDataLoadAddress );
       
   710         AppendL( item );
       
   711         }
       
   712 
       
   713     //
       
   714     AddCapabilityItemsL();
       
   715     }
       
   716 
       
   717 
       
   718 CMemSpyEngineCodeSegEntry* CMemSpyEngineCodeSegEntry::NewLC( TAny* aHandle, TInt aSize, const TCodeSegCreateInfo& aCreateInfo, const TProcessMemoryInfo& aMemoryInfo )
       
   719     {
       
   720     CMemSpyEngineCodeSegEntry* self = new(ELeave) CMemSpyEngineCodeSegEntry( aHandle, aSize, aCreateInfo, aMemoryInfo );
       
   721     CleanupStack::PushL( self );
       
   722     self->ConstructL();
       
   723     return self;
       
   724     }
       
   725 
       
   726 
       
   727 EXPORT_C TBool CMemSpyEngineCodeSegEntry::HasCapability( TCapability aCapability ) const
       
   728     {
       
   729     TBool hasCap = EFalse;
       
   730     //
       
   731     for( TInt i=0; i<SCapabilitySet::ENCapW && !hasCap; i++ )
       
   732         {
       
   733         const TUint32 capsRawValue = iCreateInfo.iS.iCaps[i];
       
   734         const TBitFlags flags( capsRawValue );
       
   735         //
       
   736         hasCap = flags.IsSet( aCapability );
       
   737         }
       
   738     //
       
   739     return hasCap;
       
   740     }
       
   741 
       
   742 
       
   743 EXPORT_C void CMemSpyEngineCodeSegEntry::OutputDataL( CMemSpyEngineHelperCodeSegment& aHelper ) const
       
   744     {
       
   745     _LIT(KHexFormat, "0x%08x");
       
   746 
       
   747     HBufC* columns = HBufC::NewLC( 4096 );
       
   748     TPtr pColumns( columns->Des() );
       
   749 
       
   750     // Name
       
   751     TParsePtrC parser( *iFileName );
       
   752     const TPtrC pFileNameWithoutPath( parser.NameAndExt() );
       
   753     pColumns.Append( pFileNameWithoutPath );
       
   754     pColumns.Append( KMemSpyEngineCodeSegListOutputComma );
       
   755 
       
   756     // Uids
       
   757     const TUidType uids( iCreateInfo.iUids );
       
   758     for( TInt i=0; i<KMaxCheckedUid; i++ )
       
   759         {
       
   760         const TUid uidValue( uids[ i ] );
       
   761         //
       
   762         pColumns.AppendFormat( KHexFormat, uidValue.iUid );
       
   763         pColumns.Append( KMemSpyEngineCodeSegListOutputComma );
       
   764         }
       
   765 
       
   766     // Module version
       
   767     if  ( iCreateInfo.iModuleVersion == KModuleVersionWild )
       
   768         {
       
   769         _LIT( KCaption, "Wild");
       
   770         pColumns.Append( KCaption );
       
   771         }
       
   772     else if ( iCreateInfo.iModuleVersion == KModuleVersionNull )
       
   773         {
       
   774         _LIT( KCaption, "Null");
       
   775         pColumns.Append( KCaption );
       
   776         }
       
   777     else
       
   778         {
       
   779         pColumns.AppendFormat( KHexFormat, iCreateInfo.iModuleVersion );
       
   780         }
       
   781     pColumns.Append( KMemSpyEngineCodeSegListOutputComma );
       
   782 
       
   783     // SID
       
   784     pColumns.AppendFormat( KHexFormat, iCreateInfo.iS.iSecureId );
       
   785     pColumns.Append( KMemSpyEngineCodeSegListOutputComma );
       
   786 
       
   787     // VID
       
   788     pColumns.AppendFormat( KHexFormat, iCreateInfo.iS.iVendorId );
       
   789     pColumns.Append( KMemSpyEngineCodeSegListOutputComma );
       
   790 
       
   791     // Code size
       
   792     if  ( iCreateInfo.iCodeSize > 0 )
       
   793         {
       
   794         pColumns.AppendNum( iCreateInfo.iCodeSize, EDecimal );
       
   795         }
       
   796     pColumns.Append( KMemSpyEngineCodeSegListOutputComma );
       
   797 
       
   798     // Text size
       
   799     if  ( iCreateInfo.iTextSize > 0 )
       
   800         {
       
   801         pColumns.AppendNum( iCreateInfo.iTextSize, EDecimal );
       
   802         }
       
   803     pColumns.Append( KMemSpyEngineCodeSegListOutputComma );
       
   804 
       
   805     // Data size
       
   806     if  ( iCreateInfo.iDataSize > 0 )
       
   807         {
       
   808         pColumns.AppendNum( iCreateInfo.iDataSize, EDecimal );
       
   809         }
       
   810     pColumns.Append( KMemSpyEngineCodeSegListOutputComma );
       
   811 
       
   812     // BSS
       
   813     if  ( iCreateInfo.iBssSize > 0 )
       
   814         {
       
   815         pColumns.AppendNum( iCreateInfo.iBssSize, EDecimal );
       
   816         }
       
   817     pColumns.Append( KMemSpyEngineCodeSegListOutputComma );
       
   818 
       
   819     // Total data size
       
   820     if  ( iCreateInfo.iTotalDataSize > 0 )
       
   821         {
       
   822         pColumns.AppendNum( iCreateInfo.iTotalDataSize, EDecimal );
       
   823         }
       
   824     pColumns.Append( KMemSpyEngineCodeSegListOutputComma );
       
   825 
       
   826     // Entrypoint veneer
       
   827     pColumns.AppendFormat( KHexFormat, iCreateInfo.iEntryPtVeneer );
       
   828     pColumns.Append( KMemSpyEngineCodeSegListOutputComma );
       
   829 
       
   830     // File Entrypoint
       
   831     pColumns.AppendFormat( KHexFormat, iCreateInfo.iFileEntryPoint );
       
   832     pColumns.Append( KMemSpyEngineCodeSegListOutputComma );
       
   833 
       
   834     // Dependency Count
       
   835     pColumns.AppendNum( iCreateInfo.iDepCount, EDecimal );
       
   836     pColumns.Append( KMemSpyEngineCodeSegListOutputComma );
       
   837 
       
   838     // ROM Code Load Address
       
   839     if  ( iCreateInfo.iCodeLoadAddress != 0 )
       
   840         {
       
   841         pColumns.AppendFormat( KHexFormat, iCreateInfo.iCodeLoadAddress );
       
   842         }
       
   843     else
       
   844         {
       
   845         _LIT(KCaption, "N.A. - RAM Loaded");
       
   846         pColumns.Append( KCaption );
       
   847         }
       
   848     pColumns.Append( KMemSpyEngineCodeSegListOutputComma );
       
   849 
       
   850     // Data Load Address
       
   851     if  ( iCreateInfo.iDataLoadAddress != 0 )
       
   852         {
       
   853         pColumns.AppendFormat( KHexFormat, iCreateInfo.iDataLoadAddress );
       
   854         }
       
   855     pColumns.Append( KMemSpyEngineCodeSegListOutputComma );
       
   856 
       
   857     // Capabilities
       
   858     CDesCArray* capabilities = CapabilityStringsLC();
       
   859     const TInt count = capabilities->Count();
       
   860     //
       
   861     for( TInt j=0; j<count; j++ )
       
   862         {
       
   863         const TPtrC capabilityName( (*capabilities)[ j ] );
       
   864         //
       
   865         pColumns.Append( capabilityName );
       
   866         if  ( j < count-1 )
       
   867             {
       
   868             pColumns.Append( KMemSpyEngineCodeSegListOutputComma );
       
   869             }
       
   870         }
       
   871     //
       
   872     CleanupStack::PopAndDestroy( capabilities );
       
   873 
       
   874     aHelper.Engine().Sink().OutputLineL( pColumns );
       
   875 
       
   876     CleanupStack::PopAndDestroy( columns );
       
   877     }
       
   878 
       
   879 
       
   880 void CMemSpyEngineCodeSegEntry::AddCapabilityItemsL()
       
   881     {
       
   882     _LIT(KCapFormat, "\tCapability #%3d\t\t%S");
       
   883     TBuf<128> item;
       
   884     //
       
   885     CDesCArray* capabilities = CapabilityStringsLC();
       
   886     const TInt count = capabilities->Count();
       
   887     //
       
   888     for( TInt i=0; i<count; i++ )
       
   889         {
       
   890         const TPtrC capabilityName( (*capabilities)[ i ] );
       
   891         item.Format( KCapFormat, i+1, &capabilityName );
       
   892         AppendL( item );
       
   893         }
       
   894     //
       
   895     CleanupStack::PopAndDestroy( capabilities );
       
   896     }
       
   897 
       
   898 
       
   899 CDesCArray* CMemSpyEngineCodeSegEntry::CapabilityStringsLC() const
       
   900     {
       
   901     CDesCArrayFlat* array = new(ELeave) CDesCArrayFlat( ECapability_Limit );
       
   902     CleanupStack::PushL( array );
       
   903     //
       
   904     const TInt KCapabilityCountPer32Bits = 32;
       
   905     //
       
   906     for( TInt i=0; i<SCapabilitySet::ENCapW; i++ )
       
   907         {
       
   908         const TUint32 caps = iCreateInfo.iS.iCaps[i];
       
   909         //
       
   910         AddCapabilitiesL( caps, i * KCapabilityCountPer32Bits, *array );
       
   911         }
       
   912     //
       
   913     return array;
       
   914     }
       
   915 
       
   916 
       
   917 void CMemSpyEngineCodeSegEntry::AddCapabilitiesL( TUint32 aCaps, TInt aCapCount, CDesCArray& aArray ) const
       
   918     {
       
   919     TBitFlags flags( aCaps );
       
   920     TBuf<128> capabilityName;
       
   921     //
       
   922     for( TInt i=aCapCount; i<aCapCount + 32 && i<ECapability_Limit; i++ )
       
   923         {
       
   924         const TBool isSet = flags.IsSet( i );
       
   925         //
       
   926         if  ( isSet )
       
   927             {
       
   928             // Get capability name
       
   929             const TCapability capability = static_cast< TCapability >( i );
       
   930             MemSpyEngineUtils::GetCapabilityName( capabilityName, capability );
       
   931 
       
   932             // Make a capability entry for this item
       
   933             aArray.AppendL( capabilityName );
       
   934             }
       
   935         }
       
   936     }
       
   937 
       
   938 
       
   939 
       
   940 
       
   941 
       
   942 
       
   943 
       
   944 
       
   945 
       
   946 
       
   947 
       
   948 
       
   949 
       
   950