apicompatanamdw/compatanalysercmd/libraryanalyser/inc/la.hpp
changeset 0 638b9c697799
child 3 ebe3f8f03b59
equal deleted inserted replaced
-1:000000000000 0:638b9c697799
       
     1 /*
       
     2 * Copyright (c) 2007-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:  Header file of LibraryAnalyser
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #ifndef __LA_HPP__
       
    20 #define __LA_HPP__
       
    21 
       
    22 
       
    23 #if (defined(_MSC_VER) && (_MSC_VER < 1400))
       
    24   #error "ERROR: Minimum supported version of Visual C++ is 8.0 (2005)."
       
    25 #endif
       
    26 
       
    27 #ifdef _MSC_VER
       
    28   #pragma message("IMPORTANT: You can use Visual C++ to aid development, but please compile the releasable executable with MinGW/MSYS !!!")
       
    29   #pragma warning(disable:4267) // 'var' : conversion from 'size_t' to 'type', possible loss of data
       
    30   #pragma warning(disable:4996) // 'function': was declared deprecated
       
    31   #define _CRT_SECURE_NO_DEPRECATE
       
    32   #ifndef WIN32
       
    33     #error "ERROR: Only Win32 target supported!"
       
    34   #endif
       
    35 #endif
       
    36 
       
    37 
       
    38 #include <algorithm>
       
    39 #include <string>
       
    40 #include <cctype>
       
    41 #include <fstream>
       
    42 #include <iostream>
       
    43 #include <vector>
       
    44 #include <sstream>
       
    45 #include <time.h>
       
    46 #include <sys/stat.h>
       
    47 #include <stdio.h>
       
    48 #include <boost/regex.hpp>
       
    49 
       
    50 #ifdef _MSC_VER
       
    51   #include <direct.h>
       
    52   #define S_ISDIR(m)  ((m) & S_IFDIR)
       
    53 #else
       
    54   #include <dirent.h>
       
    55 #endif
       
    56 
       
    57 using namespace std;
       
    58 
       
    59 #define LA_VERSION "3.3.2"
       
    60 #define LA_DATE "1st December 2009"
       
    61 #define LA_REPORT_FORMAT_VERSION "1.1"
       
    62 #define TEMP_FILENAME "la-temp.txt"
       
    63 #define REPORT_TAB_CHAR '\t'
       
    64 
       
    65 #ifdef WIN32
       
    66   #define DIR_SEPARATOR "\\"
       
    67   #define DIR_SEPARATOR2 '\\'
       
    68   #define GCC_NM_EXE "nm.exe"
       
    69   #define GCCE_NM_EXE "arm-none-symbianelf-nm.exe"
       
    70   #define GCCE_READELF_EXE "arm-none-symbianelf-readelf.exe"
       
    71   #define GCCE_CFILT_EXE "arm-none-symbianelf-c++filt.exe"
       
    72   #define RVCT_ARMAR_EXE "armar.exe"
       
    73   #define RVCT_FROMELF_EXE "fromelf.exe"
       
    74   #define CERR_TO_NULL "2>NUL"
       
    75   #define DIR_COMMAND "dir /b"
       
    76 #else
       
    77   #define DIR_SEPARATOR "/"
       
    78   #define DIR_SEPARATOR2 '/'
       
    79   #define GCC_NM_EXE "nm"
       
    80   #define GCCE_NM_EXE "arm-none-symbianelf-nm"
       
    81   #define GCCE_READELF_EXE "arm-none-symbianelf-readelf"
       
    82   #define GCCE_CFILT_EXE "arm-none-symbianelf-c++filt"
       
    83   #define RVCT_ARMAR_EXE "armar"
       
    84   #define RVCT_FROMELF_EXE "fromelf"
       
    85   #define CERR_TO_NULL "2>/dev/null"
       
    86   #define DIR_COMMAND "ls --format=single-column"
       
    87   #define _mkdir(X) mkdir(X, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH)
       
    88   #define _rmdir rmdir
       
    89   #define _unlink unlink
       
    90   #define _popen popen
       
    91   #define _pclose pclose
       
    92 #endif
       
    93 
       
    94 
       
    95 enum ReportIssues 
       
    96 {
       
    97     ISSUE_ONLY_IN_BASELINEDIR = 1,
       
    98     ISSUE_ONLY_IN_CURRENTDIR,
       
    99     ISSUE_MOVED,
       
   100     ISSUE_REMOVED,
       
   101     ISSUE_INSERTED,
       
   102     ISSUE_MODIFIED,
       
   103     ISSUE_ADDED,
       
   104 	DLL_TARGET_TYPE_CHANGED,
       
   105 	DLL_UID2_CHANGED,
       
   106 	DLL_UID3_CHANGED,
       
   107 	DLL_SID_CHANGED,
       
   108   	DLL_CAPABILITY_CHANGED,
       
   109 	DLL_CURRENT_MISSING,
       
   110     DLL_BASELINE_MISSING
       
   111 };
       
   112 
       
   113 enum TypeOfSeverity
       
   114 {
       
   115 	CONFIRMED_BC_BREAK = 1,
       
   116 	POSSIBLE_BC_BREAK,
       
   117 	CONFIRMED_SC_BREAK,
       
   118 	POSSIBLE_SC_BREAK,
       
   119 	CONFIRMED_BC_AND_SC_BREAK,
       
   120 	POSSIBLE_BC_SC_BREAK,
       
   121 	CONFIRMED_BC_POSSIBLE_SC_BREAK,
       
   122 	POSSIBLE_BC_CONFIRMED_SC_BREAK,
       
   123 	BC_INFORMATIVE,
       
   124 	SC_INFORMATIVE,
       
   125 	BC_SC_INFORMATIVE,
       
   126 	NO_BREAK
       
   127 };
       
   128 
       
   129 enum ExitStates 
       
   130 {
       
   131     EXIT_NORMAL = 0,
       
   132     EXIT_INVALID_ARGUMENT,
       
   133     EXIT_WRONG_USAGE,
       
   134     EXIT_BASELINEDIR_NOT_FOUND,
       
   135     EXIT_CURRENTDIR_NOT_FOUND,
       
   136     EXIT_TOOLCHAIN_NOT_FOUND_FROM_PATH,
       
   137     EXIT_PATH_VARIABLE_NOT_FOUND,
       
   138     EXIT_TEMP_VARIABLE_NOT_FOUND,
       
   139     EXIT_TEMP_DIRECTORY_DOES_NOT_EXIST,
       
   140     EXIT_ONLY_SUPPORTED_IN_WIN32,
       
   141     EXIT_TOOLCHAIN_NOT_FOUND,
       
   142     EXIT_CFILT_NOT_FOUND,
       
   143     EXIT_CANNOT_WRITE_TO_TEMP_FILE,
       
   144     EXIT_SET_FILE_NOT_FOUND,
       
   145     EXIT_CANNOT_OPEN_SET_FILE,
       
   146     EXIT_CANNOT_WRITE_TO_REPORT_FILE,
       
   147     EXIT_GCC_NOT_SUPPORTED,
       
   148 	  EXIT_CANNOT_OPEN_FILE,
       
   149 	  EXIT_BASELINEDLLDIR_NOT_FOUND,
       
   150     EXIT_CURRENTDLLDIR_NOT_FOUND
       
   151 };
       
   152 
       
   153 
       
   154 struct ordinal
       
   155 {
       
   156     unsigned int funcpos;
       
   157     string funcname;
       
   158     
       
   159     ordinal(unsigned int fp, string fn) 
       
   160     {
       
   161        funcpos = fp;
       
   162        funcname = fn;
       
   163     }
       
   164 };
       
   165 
       
   166 struct issue
       
   167 {
       
   168     unsigned int i_typeid;
       
   169     string i_funcname;
       
   170     string i_newfuncname;
       
   171     unsigned int i_funcpos;
       
   172     unsigned int i_newfuncpos;
       
   173 	string i_BC_severity;
       
   174 	string i_SC_severity;
       
   175 	
       
   176 };
       
   177 
       
   178 struct dll_issue
       
   179 {
       
   180 	string l_dllname;
       
   181 	vector<unsigned int> i_list_typeid;
       
   182 };
       
   183 
       
   184 
       
   185 // global variables
       
   186 extern bool _cl_use_gcc;
       
   187 extern bool _cl_use_gcce;
       
   188 extern bool _cl_use_rvct;
       
   189 extern bool _cl_use_libs;
       
   190 extern bool _cl_print_debug;
       
   191 
       
   192 extern string _cl_baselinelibdir;
       
   193 extern string _cl_currentlibdir;
       
   194 extern string _cl_baselineversion;
       
   195 extern string _cl_currentversion;
       
   196 extern string _cl_reportfile;
       
   197 extern string _cl_toolsdir;
       
   198 extern string _cl_tempdir;
       
   199 extern string _cl_cfiltloc;
       
   200 extern string _cl_set;
       
   201 extern string _cl_baselinedlldir;
       
   202 extern string _cl_currentdlldir;
       
   203 
       
   204 extern string _gcc_nm_location;
       
   205 extern string _gcce_nm_location;
       
   206 extern string _gcce_readelf_location;
       
   207 extern string _gcce_cfilt_location;
       
   208 extern string _rvct_armar_location;
       
   209 extern string _rvct_fromelf_location;
       
   210 extern string _rvct_cfilt_location;
       
   211 extern string _tempfile_location;
       
   212 extern string _lib_extension;
       
   213 extern string _toolchain_name;
       
   214 extern string _baselinedllfile;
       
   215 extern string _currentdllfile;
       
   216 
       
   217 extern vector<string> _lib_files_baseline;
       
   218 extern vector<string> _lib_files_current;
       
   219 extern vector<string> _lib_dirs_baseline;
       
   220 extern vector<string> _lib_dirs_current;
       
   221 extern vector<string> _dll_dirs_baseline;
       
   222 extern vector<string> _dll_dirs_current;
       
   223 extern vector<dll_issue> _dll_issuelist;
       
   224 
       
   225 #define DLL_ENTRY_SIZE 5
       
   226 #define UID1_OFFSET           0x00
       
   227 #define UID2_OFFSET           0x04
       
   228 #define UID3_OFFSET           0x08
       
   229 #define SID_OFFSET            0x80
       
   230 #define CAPABILITY_OFFSET     0x88
       
   231 
       
   232 
       
   233 extern ofstream _reportf; 
       
   234 extern struct tm* _timenow;
       
   235 
       
   236 // from oc_otherfunc.cpp
       
   237 void ParseCommandLineParameters(int argc, char* argv[]);
       
   238 void ShowCommandLineOptionsAndExit();
       
   239 void DoInitialChecksAndPreparations();
       
   240 void GetListsOfImportLibraries();
       
   241 void FilterListsOfImportLibraries();
       
   242 void DoPreAnalysisChecks();
       
   243 void GetToolsPathFromEnvironmentVariable();
       
   244 void GetTempPathFromEnvironmentVariable();
       
   245 void GetFileNamesFromDirectory(const vector<string>& directory, const string& filter, vector<string>& resultset);
       
   246 void DoFinalTasks();
       
   247 void CreateDllDataFile(string dllDataFile, vector<string>& dllPath, string type);
       
   248 void GetDllDataFiles();
       
   249     
       
   250 // from oc_utils.cpp
       
   251 void MakeSureTrailingDirectoryMarkerExists(string& path);
       
   252 bool FileExists(const string& path);
       
   253 bool DirectoryExists(const string& path);
       
   254 bool RemoveFile(const string& path);
       
   255 string LowerCase(const string& s);
       
   256 string Int2Str(int value);
       
   257 int Str2Int(const string& s);
       
   258 void MkDirAll(const string& path);
       
   259 string& TrimRight(string& s);
       
   260 string& TrimLeft(string& s);
       
   261 string& TrimAll(string& s);
       
   262 int StringICmp(const string& s1, const string& s2);
       
   263 int StringICmpFileNamesWithoutExtension(const string& s1, const string& s2);
       
   264 void InsertQuotesToFilePath(string& s);
       
   265 bool ExecuteCommand(const string& command, vector<string>& resultset);
       
   266 const string getFilename( const string& path);
       
   267 vector<string> splitString(const string& str, char separator);
       
   268 const string getPlatform(const string& path);
       
   269 string CharToHex(char* buf);
       
   270 string HexValueAt(fstream& f, const int offset);
       
   271 
       
   272 // from oc_getters.cpp
       
   273 void GetSymbolTableWithNM(const string& nm_location, const string& lib_directory, vector<string>& symbol_table);
       
   274 void GetSymbolTableWithReadelf(const string& readelf_location, const string& cfilt_location, const string& lib_directory, vector<string>& symbol_table);
       
   275 void GetSymbolTableWithArmar(const string& armar_location, const string& cfilt_location, const string& lib_directory, vector<string>& symbol_table);
       
   276 void GetSymbolTableWithFromelf(const string& fromelf_location, const string& cfilt_location, const string& lib_directory, vector<string>& symbol_table);
       
   277 void ConvertOrdinalListIntoSymbolTable(const vector<ordinal>& ordinals, vector<string>& symbol_table, const string& lib_path);
       
   278 void DemangleOrdinalsInSymbolTable(const string& cfilt_location, vector<string>& symbol_table);
       
   279 bool OrdinalCompare(const ordinal& left, const ordinal& right);
       
   280 
       
   281 // from oc_analysis.cpp
       
   282 void WriteReportHeader();
       
   283 void GenerateAndWriteIssueList();
       
   284 void WriteReportFooter();
       
   285 void AppendToIssueListCaseMoved(vector<issue>& issueList, const string& funcname, int funcpos, int newfuncpos,TypeOfSeverity severity);
       
   286 void AppendToIssueListCaseRemoved(vector<issue>& issueList, const string& funcname, int funcpos,TypeOfSeverity severity);
       
   287 void AppendToIssueListCaseInserted(vector<issue>& issueList, const string& newfuncname, int newfuncpos,TypeOfSeverity severity);
       
   288 void AppendToIssueListCaseModified(vector<issue>& issueList, const string& funcname, const string& newfuncname, int funcpos,TypeOfSeverity severity);
       
   289 void AppendToIssueListCaseAdded(vector<issue>& issueList, const string& newfuncname, int newfuncpos,TypeOfSeverity severity);
       
   290 bool IssueCompare(const issue& left, const issue& right);
       
   291 void WriteXMLLineOpenClosed(ofstream& f, unsigned int tabstops, const string& element, const string& data);
       
   292 void WriteXMLLineOpeningTag(ofstream& f, unsigned int tabstops, const string& element);
       
   293 void WriteXMLLineClosingTag(ofstream& f, unsigned int tabstops, const string& element);
       
   294 void WriteXMLIssueOnlyInBaselineDir(ofstream& f, const string& libname, dll_issue& dllIssue);
       
   295 void WriteXMLIssueOnlyInCurrentDir(ofstream& f, const string& libname);
       
   296 void WriteIssueListToXML(ofstream& f, const string& libname, const string& curlibname,vector<issue>& issue_list, dll_issue& dllIssue);
       
   297 
       
   298 // from oc_functionanalysis.cpp
       
   299 TypeOfSeverity AreFunctionsCompatible(const string& baselineFunc, const string& currentFunc);
       
   300 void getSeverityString(TypeOfSeverity severity, string& bc_severity, string& sc_severity);
       
   301 
       
   302 //------------------------------------ For executable analysis -------------------------------------------- 
       
   303 //file parsing and comparison between baseline and current xml file with executable info
       
   304 void ParseAndCompareDLLXmlFiles(const string& abaselineXmlFile,const string& acurrentXmlFile,
       
   305 								vector<string> lib_files_baseline);
       
   306 
       
   307 //Function to fill Executable issue with name and typeid corresponding to feature breaks ( i.e UID1,UID2,UID3,SID,capability)
       
   308 void fillDllIssue ( char* dllMember ,  unsigned int& typeId);
       
   309 
       
   310 //Function to initialize struct exe_issue
       
   311 void intializeDllIssue(dll_issue& aIssue);
       
   312 
       
   313 // Function to parse hex value and change it to decimal value (unsigned long)
       
   314 int parseHex(const char* hex);
       
   315 
       
   316 // Get DLL break type info in a string depending on type id
       
   317 string GetDllBreakTypeInfoString(int typeID);
       
   318 
       
   319 
       
   320 #endif // __LA_HPP__