memana/analyzetoolclient/commandlineengine/internal/inc/CATDatParser.h
changeset 0 f0f2b8682603
equal deleted inserted replaced
-1:000000000000 0:f0f2b8682603
       
     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:  Class responsible to parse data files
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #ifndef __CATDatParser_H__
       
    20 #define __CATDatParser_H__
       
    21 
       
    22 // Includes.
       
    23 #include "ATCommonDefines.h"
       
    24 #include "CATBase.h"
       
    25 #include "CATDataSaver.h"
       
    26 
       
    27 // Forward declarations.
       
    28 class CATModule2;
       
    29 class CATMemoryAddress;
       
    30 class CATRomSymbol;
       
    31 
       
    32 /**
       
    33 * CATDatParser creates analysis report from AnalyzeTool data file.
       
    34 * This class is used from CATProject/CATFindSourceline classes.
       
    35 * Uses either CATFindSourceLine/CATModule2's to locate memory addresses to codelines.
       
    36 * Uses CATDataSaver to store report data to basic and xml output.
       
    37 */
       
    38 class CATDatParser : public CATBase
       
    39 {
       
    40 
       
    41 public:
       
    42 	// enumeration representing the "mode" depending on build system
       
    43 	enum ANALYZE_MODE
       
    44 	{
       
    45 		SBS_1 = 0,
       
    46 		SBS_2 = 1
       
    47 	};
       
    48 	// Representing current process state
       
    49 	enum PROCESS_STATE
       
    50 	{
       
    51 		not_started = 0,
       
    52 		ongoing = 1,
       
    53 		stopped = 2
       
    54 	};
       
    55 
       
    56 	/**
       
    57 	* Constructor.
       
    58 	*/
       
    59 	CATDatParser();
       
    60 
       
    61 #ifndef MODULE_TEST
       
    62 private:
       
    63 #endif
       
    64 	/**
       
    65 	* Real constructor.
       
    66 	*/
       
    67 	void Construct();
       
    68 	
       
    69 	/**
       
    70 	* Prevent copy
       
    71 	*/
       
    72 	CATDatParser& operator =( const CATDatParser& /*other*/ ) { }
       
    73 	CATDatParser( const CATDatParser& /*other*/ ) { }
       
    74 	
       
    75 public:
       
    76 	/**
       
    77 	* Constructor for SBS2
       
    78 	* @param pModules pointer to vector containing project modules
       
    79 	*/
       
    80 	CATDatParser( vector<CATModule2*>* pModules );
       
    81 
       
    82 	/**
       
    83 	* Destructor
       
    84 	*/
       
    85 	~CATDatParser();
       
    86 
       
    87 	/**
       
    88 	* Set offset to be used with mapfiles
       
    89 	* @param iOffSet
       
    90 	*/
       
    91 	void SetOffSet( int iOffSet );
       
    92 
       
    93 	/**
       
    94 	* Get offset value
       
    95 	* @return int
       
    96 	*/
       
    97 	int GetOffSet( ) const;
       
    98 	
       
    99 	/**
       
   100 	* Analyze data file set
       
   101 	* This method includes try/catch in parsing
       
   102 	* @return int error codes specified in CATProject (0=OK)
       
   103 	*/
       
   104 	int Analyze();
       
   105 
       
   106 	/**
       
   107 	* Set log level
       
   108 	* @param iLogLevel
       
   109 	*/
       
   110 	void SetLogLevel(int iLogLevel);
       
   111 	/**
       
   112 	* Get Log level
       
   113 	* @return int
       
   114 	*/
       
   115 	int GetLogLevel() const ;
       
   116 
       
   117 	/**
       
   118 	* Set data file to be analyzed
       
   119 	* @param sInputFile
       
   120 	*/
       
   121 	void SetInputFile(const string& sInputFile);
       
   122 
       
   123 	/**
       
   124 	* Set output file
       
   125 	* @param sOutputFile
       
   126 	*/
       
   127 	void SetOutputFile(const string& sOutputFile);
       
   128 
       
   129 	/**
       
   130 	* Set rom symbol file(s).
       
   131 	* @param sRomSymbolFile
       
   132 	*/
       
   133 	void SetRomSymbolFiles(const vector<string>& vRomSymbolFile);
       
   134 
       
   135 	/**
       
   136 	* Set print flag
       
   137 	* @param pPringFlag
       
   138 	*/
       
   139 	void SetPringFlag( bool bPrintFlag );
       
   140 
       
   141 	/**
       
   142 	* Set addr2line.exe pinpoint state
       
   143 	* @param bInput
       
   144 	*/
       
   145 	void SetAddr2lineExeState( bool bInput );
       
   146 
       
   147 	/**
       
   148 	* Set project platform.
       
   149 	* @param sPlatform platform.
       
   150 	*/
       
   151 	void SetProjectPlatform( const string& sPlatform );
       
   152 
       
   153 	/**
       
   154 	* Set projects build type. Use enumeration defined in CATProject.
       
   155 	* @param eBuildType.
       
   156 	*/
       
   157 	void SetProjectBuildType( int eBuildType );
       
   158 
       
   159 	//Define this class as a friend class for test class.
       
   160 	friend class CATTester;
       
   161 #ifndef MODULE_TEST
       
   162 private:
       
   163 #endif
       
   164 
       
   165 	/**
       
   166 	* Start parsing datafile
       
   167 	* @return error codes defined in CATProject
       
   168 	*/
       
   169 	int Parse();
       
   170 	
       
   171 	/**
       
   172 	* Helper functio to print header of report
       
   173 	*/
       
   174 	void Header();
       
   175 
       
   176 	/**
       
   177 	* Helper functio to print footer of report
       
   178 	*/
       
   179 	void Footer();
       
   180 
       
   181 	/**
       
   182 	* Helper function reseting/clearing all
       
   183 	* member variables related to parsing
       
   184 	*/
       
   185 	void ClearParsingVariables();
       
   186 
       
   187 	// Helpers for data file tags
       
   188 	bool ParseProcessStart( string& sLine );
       
   189 	bool ParseDllLoad( string& sLine );
       
   190 	bool ParseDllUnload( string& sLine );
       
   191 	bool ParseMemLeak( string& sLine );
       
   192 	bool ParseProcessEnd( string& sLine );
       
   193 	bool ParseHandleLeak( string& sLine );
       
   194 	bool ParseTestStart( string& sLine );
       
   195 	bool ParseTestEnd( string& sLine );
       
   196 	bool ParseLoggingCancelled( string& sLine );
       
   197 	bool ParseErrorOccured( string& sLine );
       
   198 
       
   199 	void PrintMemLeak(const string& sTime,
       
   200 					   const string& sLeakSize,
       
   201 					   const string& sLeakAddr,
       
   202 					   const string& sModuleName);
       
   203 
       
   204 	// Utilities
       
   205 	string ConvertTimeToLocalTime( string sInputTime );
       
   206 
       
   207 	/**
       
   208 	* Create a winscw module into pModules vector.
       
   209 	* Used when we have dll load of module not in project to create them
       
   210 	* after this they are used in locating code lines.
       
   211 	* @param sBinaryName name of the binary with extension.
       
   212 	* @return true if successful.
       
   213 	*/
       
   214 	bool CreateWinscwModule( const string& sBinaryName );
       
   215 
       
   216 #ifndef MODULE_TEST
       
   217 private:
       
   218 #endif
       
   219 	vector<string> ParseStringToVector( const string& sInput, char separator );
       
   220 	void CleanMemoryAddresses();
       
   221 
       
   222 	// Members
       
   223 	unsigned int m_iDataVersion; // Version of data file.
       
   224 	int m_eProcess_state; // is process started, etc..
       
   225 	bool m_bProcessStartFound;
       
   226 	bool m_bDllLoadFound;
       
   227 	int m_iLogLevel; // specified logging level
       
   228 	string m_sInputFile; // input file
       
   229 	vector<string> m_vRomSymbolFiles; // Rom symbol file.
       
   230 	string m_sOutputFile; // output file
       
   231 	string m_sInputFileTemp; // temporary input file (parsed from trace)
       
   232 	ifstream m_In; // Handle to input file
       
   233 	// Datasaver
       
   234 	CATDataSaver m_DataSaver;
       
   235 
       
   236 	// Modules to be used in pinpointing
       
   237 	vector<CATModule2*>* m_pModules;
       
   238 
       
   239 	// Rom symbol file.
       
   240 	CATRomSymbol* m_pRomSymbol;
       
   241 
       
   242 	// Build type from dat.
       
   243 	int m_eBuildType;
       
   244 	// Build type from project.
       
   245 	int m_eProjectBuildType;
       
   246 	// Offset of map file.
       
   247 	int m_iOffSet;
       
   248 	// Platform of project.
       
   249 	string m_sProjectPlatform;
       
   250 
       
   251 	// Process related
       
   252 	unsigned long m_iCurrentProcessId;
       
   253 	string m_sCurrentProcessName;
       
   254 	int m_iTotalRuns;
       
   255 	int m_iSuccesfullRuns;
       
   256 	
       
   257 	// Leak counting related
       
   258 	int m_iTotalNumberOfLeaks;
       
   259 	bool m_bSubtestOnGoing;
       
   260 	int m_iPinPointedLeaks;
       
   261 	int m_iPinPointedSubTestLeaks;
       
   262 	int m_iLeakNumber;
       
   263 	
       
   264 	// Handle count related
       
   265 	int m_iSubtestStartHandleCount;
       
   266 	vector<string> m_vHandleLeaks;
       
   267 
       
   268 	// Module related
       
   269 	vector<DLL_LOAD_INFO> m_vDllLoadModList;
       
   270 	vector<DLL_LOAD_INFO> m_vDllLoadModListSubTest;
       
   271 	
       
   272 	// Sbs 1 support functions
       
   273 	int FindModuleUsingAddress( unsigned long iAddress ) const;
       
   274 	//int FindModuleUsingPID( unsigned long iPID ) const;
       
   275 	int FindModuleUsingName( const char* pModName );
       
   276 
       
   277 	// Memory addresses
       
   278 	vector<CATMemoryAddress*> m_vMemoryAddress;
       
   279 
       
   280 };
       
   281 #endif
       
   282 //EOF