crashanalysercmd/UI/CrashServer/Engine/CACmdLineEngine.cs
changeset 2 0c91f0baec58
parent 0 818e61de6cd1
child 3 045ade241ef5
equal deleted inserted replaced
1:7a31f7298d8f 2:0c91f0baec58
    41 using SymbianDebugLib.Engine;
    41 using SymbianDebugLib.Engine;
    42 using SymbianDebugLib.Entity;
    42 using SymbianDebugLib.Entity;
    43 using SymbianUtils;
    43 using SymbianUtils;
    44 using SymbianUtils.Tracer;
    44 using SymbianUtils.Tracer;
    45 using CrashItemLib.Crash.InfoSW;
    45 using CrashItemLib.Crash.InfoSW;
       
    46 using MobileCrashLib;
       
    47 using MobileCrashLib.Parser;
       
    48 using MobileCrashLib.Structures.Items;
       
    49 using MobileCrashLib.Structures;
    46 
    50 
    47 namespace CrashAnalyserServerExe.Engine
    51 namespace CrashAnalyserServerExe.Engine
    48 {
    52 {
    49     internal class CACmdLineEngine : DisposableObject, ITracer, ICIEngineUI
    53     internal class CACmdLineEngine : DisposableObject, ITracer, ICIEngineUI
    50 	{
    54 	{
    90                 // create all the needed Crash Item Source objects for each input file.
    94                 // create all the needed Crash Item Source objects for each input file.
    91                 // Any inputs which we don't support will not have an associated source and
    95                 // Any inputs which we don't support will not have an associated source and
    92                 // will be flagged accordingly within the CACmdLineFileSource object.
    96                 // will be flagged accordingly within the CACmdLineFileSource object.
    93                 TryToPrimeSources();
    97                 TryToPrimeSources();
    94 
    98 
       
    99                 // Try to the ROM ID and file type (i.e. crash, 
       
   100                 // registration msg, report) out of the crash files. This information is
       
   101                 // used in later phases (e.g. if there are only registration messages in 
       
   102                 // source files then we do not have to load symbol files).
       
   103                 TryToGetCrashInformation();
       
   104 
    95                 // Next, prime the debug engine will all the debug meta-data inputs.
   105                 // Next, prime the debug engine will all the debug meta-data inputs.
    96                 // Again, individual error messages will be associated with each meta-data
   106                 // Again, individual error messages will be associated with each meta-data
    97                 // input.
   107                 // input.
    98                 TryToPrimeDbgEngine();
   108 
       
   109               //  if (SymbolFilesNeeded())
       
   110                 {
       
   111                     TryToPrimeDbgEngine();
       
   112                 }
    99 
   113 
   100                 // Next, we invoke the crash engine to process all the crash item sources we
   114                 // Next, we invoke the crash engine to process all the crash item sources we
   101                 // created during the prime step. Exceptions are caught and associated 
   115                 // created during the prime step. Exceptions are caught and associated 
   102                 // messages & diagnostics are created at the input-file level.
   116                 // messages & diagnostics are created at the input-file level.
   103                 TryToIdentifyCrashes();
   117                 TryToIdentifyCrashes();
   123             }
   137             }
   124             
   138             
   125             Trace( "[CA Cmd] - operation complete: " + error );
   139             Trace( "[CA Cmd] - operation complete: " + error );
   126             return error;
   140             return error;
   127         }
   141         }
       
   142 
   128         #endregion
   143         #endregion
   129 
   144 
   130 		#region Properties
   145 		#region Properties
   131         public string CommandLineArguments
   146         public string CommandLineArguments
   132         {
   147         {
   206         }
   221         }
   207         #endregion
   222         #endregion
   208 
   223 
   209         #region Internal constants
   224         #region Internal constants
   210         private const string KCrashItemSinkName = "CRASH INFO FILE";
   225         private const string KCrashItemSinkName = "CRASH INFO FILE";
       
   226         private const string KXmlCrashItemSinkName = "XML CRASH FILE";
   211         private const string KParamProgress = "-PROGRESS";
   227         private const string KParamProgress = "-PROGRESS";
   212         #endregion
   228         #endregion
   213 
   229 
   214         #region Internal methods
   230         #region Internal methods
   215         private bool CheckForProgressParameter()
   231         private bool CheckForProgressParameter()
   216         {
   232         {
   217             bool report = this.CommandLineArguments.Contains( KParamProgress );
   233             bool report = this.CommandLineArguments.Contains( KParamProgress );
   218             return report;
   234             return report;
   219         }
   235         }
   220 
   236 
   221         private CISink FindSink()
   237         private CISink FindSink(bool aUseXmlSink)
   222         {
   238         {
   223             Trace( "[CA Cmd] FindSink() - START" );
   239             Trace( "[CA Cmd] FindSink() - START" );
   224             CISink ret = null;
   240             CISink ret = null;
   225             //
   241             //
       
   242             string sinkToUse = KCrashItemSinkName;
       
   243             if (aUseXmlSink)
       
   244             {
       
   245                 sinkToUse = KXmlCrashItemSinkName;
       
   246             }
       
   247 
   226             CISinkManager sinkManager = iCrashItemEngine.SinkManager;
   248             CISinkManager sinkManager = iCrashItemEngine.SinkManager;
   227             foreach ( CISink sink in sinkManager )
   249             foreach ( CISink sink in sinkManager )
   228             {
   250             {
   229                 Trace( "[CA Cmd] FindSink() - found sink: " + sink.Name );
   251                 Trace( "[CA Cmd] FindSink() - found sink: " + sink.Name );
   230 
   252 
   231                 if ( sink.Name.ToUpper().Contains( KCrashItemSinkName ) )
   253                 if ( sink.Name.ToUpper().Contains( sinkToUse ) )
   232                 {
   254                 {
   233                     ret = sink;
   255                     ret = sink;
   234                     break;
   256                     break;
   235                 }
   257                 }
   236             }
   258             }
   290 
   312 
   291             AssociateInputFilesWithCrashItemSources();
   313             AssociateInputFilesWithCrashItemSources();
   292             Trace( "[CA Cmd] TryToPrimeSources() - END" );
   314             Trace( "[CA Cmd] TryToPrimeSources() - END" );
   293         }
   315         }
   294 
   316 
       
   317         /**
       
   318          * Get important data (i.e. RomId and content type)
       
   319          */
       
   320         private void TryToGetCrashInformation()
       
   321         {
       
   322             Trace("[CA Cmd] TryToGetCrashInformation() - START");
       
   323 
       
   324             foreach (CACmdLineFileSource file in iInputs.SourceFiles)
       
   325             {
       
   326                 if (file.Source != null)
       
   327                 {
       
   328                     byte[] bytes = File.ReadAllBytes(file.File.FullName);
       
   329                     MobileCrashBin bin = new MobileCrashBin(bytes);
       
   330                     MobileCrashData data = new MobileCrashData();
       
   331                     MobileCrashParser parser = new MobileCrashParser(bin, data);
       
   332                     parser.Parse(TSynchronicity.ESynchronous);
       
   333                     data = parser.MobileCrashData;
       
   334                     file.RomId = data.ItemById<MobileCrashItemUint32>(TMobileCrashId.EMobileCrashId_ROMID);
       
   335                     file.ContentType = data.ContentType;
       
   336                 }
       
   337             }
       
   338 
       
   339             Trace("[CA Cmd] TryToGetCrashInformation() - END");
       
   340 
       
   341         }
       
   342 
   295         private void TryToPrimeDbgEngine()
   343         private void TryToPrimeDbgEngine()
   296         {
   344         {
   297             DbgEngine debugEngine = iDebugEngine;
   345             DbgEngine debugEngine = iDebugEngine;
   298             //
   346             //
   299             Exception primerException = null;
   347             Exception primerException = null;
   300             CACmdLineFSEntityList<CACmdLineFSEntity> metaDataFiles = iInputs.MetaDataFiles;
   348             CACmdLineFSEntityList<CACmdLineFSEntity> metaDataFiles = iInputs.MetaDataFiles;
   301             //
   349             //
   302             try
   350             try
   303             {
   351             {
   304                 debugEngine.Clear();
   352                 debugEngine.Clear();
       
   353 
       
   354                 foreach (CACmdLineFileSource file in iInputs.SourceFiles)
       
   355                 {
       
   356                     if (file.RomId != null)
       
   357                         debugEngine.AddActiveRomId(file.RomId.Value);
       
   358                 }
   305 
   359 
   306                 foreach ( CACmdLineFSEntity entry in metaDataFiles )
   360                 foreach ( CACmdLineFSEntity entry in metaDataFiles )
   307                 {
   361                 {
   308                     Trace( "[CA Cmd] Seeding debug meta engine with entry: " + entry.Name );
   362                     Trace( "[CA Cmd] Seeding debug meta engine with entry: " + entry.Name );
   309                     DbgEntity entity = debugEngine.Add( entry.Name );
   363                     DbgEntity entity = debugEngine.Add( entry.Name );
   446 
   500 
   447         private void TryToCreateOutput()
   501         private void TryToCreateOutput()
   448         {
   502         {
   449             CACmdLineFSEntityList<CACmdLineFileSource> inputFiles = iInputs.SourceFiles;
   503             CACmdLineFSEntityList<CACmdLineFileSource> inputFiles = iInputs.SourceFiles;
   450             //
   504             //
   451             CISink sink = FindSink();
   505             CISink sink = FindSink(iInputs.UseXmlSink);
   452             if ( sink == null )
   506             if ( sink == null )
   453             {
   507             {
   454                 throw new CACmdLineException( "CI Output Plugin Not Available", CACmdLineException.KErrSinkNotAvailable );
   508                 throw new CACmdLineException( "CI Output Plugin Not Available", CACmdLineException.KErrSinkNotAvailable );
   455             }
   509             }
   456   
   510   
   744 
   798 
   745             foreach (CIMessage message in aContainer.Messages)
   799             foreach (CIMessage message in aContainer.Messages)
   746             {
   800             {
   747                 if (message.Title == "MobileCrash content type")
   801                 if (message.Title == "MobileCrash content type")
   748                 {
   802                 {
       
   803                     /* We could also decode registrations without but that will cause server to have
       
   804                      * lots of registration only sw versions
   749                     if (message.Description.Trim() == "registration")
   805                     if (message.Description.Trim() == "registration")
   750                     {
   806                     {
   751                         retval = true;
   807                         retval = true;
   752                     }
   808                     }
   753                     else if (message.Description.Trim() == "alive")
   809                     else if (message.Description.Trim() == "alive")
   754                     {
   810                     {
   755                         retval = true;
   811                         retval = true;
   756                     }
   812                     }
   757                     else if (message.Description.Trim() == "report")
   813                     else */
       
   814 
       
   815                     if (message.Description.Trim() == "report")
   758                     {
   816                     {
   759                         retval = true;
   817                         retval = true;
   760                     }
   818                     }
   761                 }
   819                 }
   762             }
   820             }
   848             }
   906             }
   849 
   907 
   850 
   908 
   851         }
   909         }
   852 
   910 
       
   911         private bool SymbolFilesNeeded()
       
   912         {
       
   913             foreach (CACmdLineFileSource file in iInputs.SourceFiles)
       
   914             {
       
   915                 if (file.ContentType == TMobileCrashContentType.EContentTypeException ||
       
   916                     file.ContentType == TMobileCrashContentType.EContentTypePanic)
       
   917                     return true;
       
   918             }
       
   919             return false;
       
   920         }
       
   921 
   853         #endregion
   922         #endregion
   854 
   923 
   855         #region Output methods
   924         #region Output methods
   856         public void Print( string aMessage )
   925         public void Print( string aMessage )
   857         {
   926         {
   860         #endregion
   929         #endregion
   861 
   930 
   862         #region From ITracer
   931         #region From ITracer
   863         public void Trace( string aMessage )
   932         public void Trace( string aMessage )
   864         {
   933         {
   865             System.Console.WriteLine("MANUAL TRACE:" +aMessage);
   934             //System.Console.WriteLine("MANUAL TRACE:" +aMessage);
   866             iDebugEngine.Trace( aMessage );
   935             iDebugEngine.Trace( aMessage );
   867         }
   936         }
   868 
   937 
   869         public void Trace( string aFormat, params object[] aParams )
   938         public void Trace( string aFormat, params object[] aParams )
   870         {
   939         {