|
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 Appdep |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #ifndef __APPDEP_HPP__ |
|
20 #define __APPDEP_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 APPDEP_VERSION "2.2" |
|
60 #define APPDEP_DATE "27th Nov 2009" |
|
61 #define APPDEP_COPYRIGHT_YEARS "2001-2009" |
|
62 #define CACHE_ST_FILENAME "appdep-cache_symbol_tables.txt" |
|
63 #define CACHE_DEP_FILENAME "appdep-cache_dependencies.txt" |
|
64 #define CACHE_ST_HEADER "appdep symbol tables cache version: 101" |
|
65 #define CACHE_DEP_HEADER "appdep dependencies cache version: 101" |
|
66 #define CACHE_FOOTER "#end" |
|
67 #define CACHE_COMMENT_CHAR '#' |
|
68 #define CACHE_SEP "|" |
|
69 #define TEMP_FILENAME "appdep-temp.txt" |
|
70 #define SIS_TEMP_DIR "sistemp" |
|
71 #define UNKNOWN "unknown" |
|
72 #define NOT_VALID "not valid" |
|
73 |
|
74 #ifdef WIN32 |
|
75 #define DIR_SEPARATOR "\\" |
|
76 #define DIR_SEPARATOR2 '\\' |
|
77 #define DEFAULT_CACHE_DIR "epoc32\\tools\\s60rndtools\\appdep\\cache\\" |
|
78 #define DUMPSIS_LOCATION "epoc32\\tools\\dumpsis.exe" |
|
79 #define PETRAN_LOCATION "epoc32\\tools\\petran.exe" // used for GCC toolchain |
|
80 #define ELFTRAN_LOCATION "epoc32\\tools\\elftran.exe" // used for other toolchains |
|
81 #define EPOC32_RELEASE "epoc32\\release\\" |
|
82 #define GCC_NM_EXE "nm.exe" |
|
83 #define GCCE_NM_EXE "arm-none-symbianelf-nm.exe" |
|
84 #define GCCE_READELF_EXE "arm-none-symbianelf-readelf.exe" |
|
85 #define GCCE_CFILT_EXE "arm-none-symbianelf-c++filt.exe" |
|
86 #define RVCT_ARMAR_EXE "armar.exe" |
|
87 #define RVCT_FROMELF_EXE "fromelf.exe" |
|
88 #define CERR_TO_NULL "2>NUL" |
|
89 #define DIR_COMMAND "dir /b" |
|
90 #define DEL_ALL_COMMAND "del /F /S /Q" |
|
91 #else |
|
92 #define DIR_SEPARATOR "/" |
|
93 #define DIR_SEPARATOR2 '/' |
|
94 #define DEFAULT_CACHE_DIR "epoc32/tools/s60rndtools/appdep/cache/" |
|
95 #define DUMPSIS_LOCATION "epoc32/tools/dumpsis" |
|
96 #define PETRAN_LOCATION "epoc32/tools/petran" // used for GCC toolchain |
|
97 #define ELFTRAN_LOCATION "epoc32/tools/elftran" // used for other toolchains |
|
98 #define EPOC32_RELEASE "epoc32/release/" |
|
99 #define GCC_NM_EXE "nm" |
|
100 #define GCCE_NM_EXE "arm-none-symbianelf-nm" |
|
101 #define GCCE_READELF_EXE "arm-none-symbianelf-readelf" |
|
102 #define GCCE_CFILT_EXE "arm-none-symbianelf-c++filt" |
|
103 #define RVCT_ARMAR_EXE "armar" |
|
104 #define RVCT_FROMELF_EXE "fromelf" |
|
105 #define CERR_TO_NULL "2>/dev/null" |
|
106 #define DIR_COMMAND "ls --format=single-column" |
|
107 #define DEL_ALL_COMMAND "rm -f -R" |
|
108 #define _mkdir(X) mkdir(X, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH) |
|
109 #define _rmdir rmdir |
|
110 #define _unlink unlink |
|
111 #define _popen popen |
|
112 #define _pclose pclose |
|
113 #endif |
|
114 |
|
115 enum ExitStates |
|
116 { |
|
117 EXIT_NORMAL = 0, |
|
118 EXIT_INVALID_ARGUMENT, |
|
119 EXIT_NO_TARGETS, |
|
120 EXIT_WRONG_USAGE, |
|
121 EXIT_CANNOT_CREATE_OUTPUT_FILE, |
|
122 EXIT_TOOLCHAIN_NOT_FOUND, |
|
123 EXIT_TARGETDIR_NOT_FOUND, |
|
124 EXIT_CFILT_NOT_FOUND, |
|
125 EXIT_PETRAN_NOT_FOUND, |
|
126 EXIT_TOOLCHAIN_NOT_FOUND_FROM_PATH, |
|
127 EXIT_PATH_VARIABLE_NOT_FOUND, |
|
128 EXIT_ONLY_SUPPORTED_IN_WIN32, |
|
129 EXIT_CANNOT_WRITE_TO_TEMP_FILE, |
|
130 EXIT_ORDINAL_LIST_CORRUPTED, |
|
131 EXIT_COMPONENT_NOT_FOUND, |
|
132 EXIT_INVALID_ORDINAL, |
|
133 EXIT_CANNOT_WRITE_TO_CACHE_FILE, |
|
134 EXIT_CANNOT_OPEN_STATIC_DEPENDENCIES_TXT, |
|
135 EXIT_OPENED_STATIC_DEPENDENCIES_TXT_NOT_SUPPORTED, |
|
136 EXIT_DUMPSIS_NOT_FOUND, |
|
137 EXIT_SIS_FILE_NOT_FOUND, |
|
138 EXIT_SIS_FILE_NOT_SUPPORTED, |
|
139 EXIT_NOT_SIS_FILE, |
|
140 EXIT_SIS_FILE_CANNOT_OPEN_FOR_READING, |
|
141 EXIT_TEMP_SIS_FILE_CANNOT_OPEN_FOR_WRITING, |
|
142 EXIT_NO_PKG_FILE_FOUND, |
|
143 EXIT_PKG_FILE_CANNOT_OPEN_FOR_READING, |
|
144 EXIT_PKG_FORMAT_NOT_SUPPORTED |
|
145 }; |
|
146 |
|
147 struct ordinal |
|
148 { |
|
149 unsigned int funcpos; |
|
150 string funcname; |
|
151 |
|
152 ordinal(unsigned int fp, string fn) |
|
153 { |
|
154 funcpos = fp; |
|
155 funcname = fn; |
|
156 } |
|
157 }; |
|
158 |
|
159 struct import |
|
160 { |
|
161 unsigned int funcpos; |
|
162 string funcname; |
|
163 bool is_vtable; |
|
164 unsigned int vtable_offset; |
|
165 }; |
|
166 |
|
167 struct dependency |
|
168 { |
|
169 string filename; |
|
170 vector<import> imports; |
|
171 }; |
|
172 |
|
173 struct binary_info |
|
174 { |
|
175 string directory; |
|
176 string filename; |
|
177 string binary_format; |
|
178 unsigned long file_size; |
|
179 string uid1; |
|
180 string uid2; |
|
181 string uid3; |
|
182 string secureid; |
|
183 string vendorid; |
|
184 unsigned long capabilities; |
|
185 unsigned long min_heap_size; |
|
186 unsigned long max_heap_size; |
|
187 unsigned long stack_size; |
|
188 time_t mod_time; |
|
189 vector<dependency> dependencies; |
|
190 }; |
|
191 |
|
192 struct import_library_info |
|
193 { |
|
194 string directory; |
|
195 string filename; |
|
196 time_t mod_time; |
|
197 vector<string> symbol_table; |
|
198 }; |
|
199 |
|
200 struct target |
|
201 { |
|
202 string name; |
|
203 string release_dir; |
|
204 string release_lib_dir; |
|
205 string release_bin_dir; |
|
206 string cache_dir; |
|
207 string st_cache_path; |
|
208 string dep_cache_path; |
|
209 bool cache_files_valid; |
|
210 vector<string> lib_files; |
|
211 vector<string> bin_files; |
|
212 vector<import_library_info> import_libraries; |
|
213 vector<binary_info> binaries; |
|
214 }; |
|
215 |
|
216 |
|
217 // global variables |
|
218 extern bool _cl_use_gcc; |
|
219 extern bool _cl_use_gcce; |
|
220 extern bool _cl_use_rvct; |
|
221 extern bool _cl_generate_clean_cache; |
|
222 extern bool _cl_update_cache; |
|
223 extern bool _cl_use_libs; |
|
224 extern bool _cl_show_ordinals; |
|
225 extern bool _cl_use_udeb; |
|
226 extern bool _cl_print_debug; |
|
227 extern bool _some_cache_needs_update; |
|
228 |
|
229 extern string _cl_toolsdir; |
|
230 extern string _cl_cachedir; |
|
231 extern string _cl_releasedir; |
|
232 extern string _cl_targets; |
|
233 extern string _cl_cfiltloc; |
|
234 extern string _cl_outputfile; |
|
235 extern string _cl_configfile; |
|
236 extern string _cl_sisfiles; |
|
237 extern string _cl_usestaticdepstxt; |
|
238 extern string _cl_properties; |
|
239 extern string _cl_staticdeps; |
|
240 extern string _cl_dependson; |
|
241 extern string _cl_showfunctions; |
|
242 extern string _cl_usesfunction; |
|
243 |
|
244 extern string _gcc_nm_location; |
|
245 extern string _gcce_nm_location; |
|
246 extern string _gcce_readelf_location; |
|
247 extern string _gcce_cfilt_location; |
|
248 extern string _rvct_armar_location; |
|
249 extern string _rvct_fromelf_location; |
|
250 extern string _rvct_cfilt_location; |
|
251 extern string _petran_location; |
|
252 extern string _dumpsis_location; |
|
253 extern string _tempfile_location; |
|
254 extern string _target_mode; |
|
255 |
|
256 extern vector<target> _targets; |
|
257 extern vector<binary_info> _all_binary_infos; |
|
258 extern vector<import_library_info> _all_import_library_infos; |
|
259 extern vector<import_library_info> _changed_import_libraries; |
|
260 extern vector<string> _sisfiles; |
|
261 |
|
262 extern unsigned int _current_progress; |
|
263 extern unsigned int _current_progress_percentage; |
|
264 extern unsigned int _max_progress; |
|
265 |
|
266 extern ofstream _outputf; |
|
267 |
|
268 |
|
269 // from appdep_otherfunc.cpp |
|
270 void ParseCommandLineParameters(int argc, char* argv[]); |
|
271 void ShowCommandLineOptionsAndExit(); |
|
272 void DoInitialChecksAndPreparations(); |
|
273 void ParseTargets(); |
|
274 void DoCacheGenerationChecksAndPreparations(); |
|
275 void GetToolsPathFromEnvironmentVariable(); |
|
276 void FindImportLibrariesAndBinariesFromReleases(); |
|
277 void GetFileNamesFromDirectory(const string& directory, const string& filter, vector<string>& resultset); |
|
278 void SetAndCheckPetranPath(); |
|
279 |
|
280 // from appdep_utils.cpp |
|
281 void PrintOutputLn(const string& s); |
|
282 void MakeSureTrailingDirectoryMarkerExists(string& path); |
|
283 bool FileExists(const string& path); |
|
284 bool DirectoryExists(const string& path); |
|
285 bool RemoveFile(const string& path); |
|
286 bool RemoveDirectoryWithAllFiles(const string& path); |
|
287 string LowerCase(const string& s); |
|
288 string Int2Str(int value); |
|
289 int Str2Int(const string& s); |
|
290 void MkDirAll(const string& path); |
|
291 string& TrimRight(string& s); |
|
292 string& TrimLeft(string& s); |
|
293 string& TrimAll(string& s); |
|
294 int StringICmp(const string& s1, const string& s2); |
|
295 int StringICmpFileNamesWithoutExtension(const string& s1, const string& s2); |
|
296 void InsertQuotesToFilePath(string& s); |
|
297 bool ExecuteCommand(const string& command, vector<string>& resultset); |
|
298 bool TimestampsMatches(const time_t& orginal_time, const time_t& new_time); |
|
299 void ShowProgressInfo(unsigned int& current_progress_percentage, unsigned int& current_progress, unsigned int& max_progress, bool print_initial_value); |
|
300 |
|
301 // from appdep_getters.cpp |
|
302 void GetImportTableWithPetran(const string& petran_location, binary_info& b_info); |
|
303 bool ImportFunctionsHasSameOrdinal(import imp1, import imp2); |
|
304 void GetSymbolTableWithNM(const string& nm_location, const string& lib_directory, const string& lib_name, vector<string>& symbol_table); |
|
305 void GetSymbolTableWithReadelf(const string& readelf_location, const string& cfilt_location, const string& lib_directory, const string& lib_name, vector<string>& symbol_table); |
|
306 void GetSymbolTableWithArmar(const string& armar_location, const string& cfilt_location, const string& lib_directory, const string& lib_name, vector<string>& symbol_table); |
|
307 void GetSymbolTableWithFromelf(const string& fromelf_location, const string& cfilt_location, const string& lib_directory, const string& lib_name, vector<string>& symbol_table); |
|
308 void ConvertOrdinalListIntoSymbolTable(const vector<ordinal>& ordinals, vector<string>& symbol_table, const string& lib_path); |
|
309 void DemangleOrdinalsInSymbolTable(const string& cfilt_location, vector<string>& symbol_table); |
|
310 bool OrdinalCompare(const ordinal& left, const ordinal& right); |
|
311 |
|
312 // from appdep_cache.cpp |
|
313 void ReadDataFromSymbolTablesCache(target& a_target); |
|
314 void ReadDataFromDependenciesCache(target& a_target); |
|
315 void GetDataFromImportTables(target& a_target); |
|
316 void GetDataFromBinaries(target& a_target); |
|
317 void WriteDataToSymbolTableCacheFile(const target& a_target); |
|
318 void WriteDataToDependenciesCacheFile(const target& a_target); |
|
319 |
|
320 // from appdep_statdeps.cpp |
|
321 void GetDataFromStaticDependenciesTxt(); |
|
322 |
|
323 // from appdep_sisfiles.cpp |
|
324 void DoInitialChecksAndPreparationsForSisFiles(); |
|
325 void AnalyseSisFiles(); |
|
326 |
|
327 // from appdep_analysis.cpp |
|
328 void DisplayProperties(const string& binary_name); |
|
329 void DisplayStaticDependencies(const string& binary_name); |
|
330 void DisplayDependents(const string& binary_name); |
|
331 void DisplayFunctions(const string& binary_name); |
|
332 void DisplayUsesFunction(const string& function_name); |
|
333 |
|
334 |
|
335 #endif // __APPDEP_HPP__ |