|
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: Defines the entry point for the console application. |
|
15 * |
|
16 */ |
|
17 |
|
18 // Includes. |
|
19 #include "../inc/ATCommonDefines.h" |
|
20 #include "../inc/CATDatParser.h" |
|
21 #include "../inc/CATParseTraceFile.h" |
|
22 #include "../inc/CATProject.h" |
|
23 |
|
24 //Debug logging parameters |
|
25 //To enable debugging as argument to atool.exe use: |
|
26 //--show_debug / -show_debug : Normal logging in console. |
|
27 //--show_debug_all / -show_debug_all : Log all (low level functions also) to console. |
|
28 //--show_dbgview / -show_dbgview : Normal logging to windows debug messages. |
|
29 //--show_dbgview_all / -show_dbgview_all : Log all (low level functions also) to windows debug messages. |
|
30 |
|
31 //Return codes (errorlevel) defined in AT_RETURN_CODE structure see ATCommonDefines.h. |
|
32 |
|
33 extern bool g_bDebugConsole = false; |
|
34 extern bool g_bDebugDbgView = false; |
|
35 extern bool g_bDebugLowLevel = false; |
|
36 |
|
37 //Argument parsing. |
|
38 extern bool parseBaseArguments( vector<string>& vArgs, ARGUMENTS& args ); |
|
39 extern bool parseHookArguments( vector<string>& vArgs, ARGUMENTS& args ); |
|
40 extern bool parseOldHookArguments( vector<string>& vArgs, ARGUMENTS& args ); |
|
41 extern bool parseAnalyzeArguments( vector<string>& vArgs, ARGUMENTS& args ); |
|
42 extern bool parseHtiArguments( vector<string>& vArgs, ARGUMENTS& args ); |
|
43 extern bool parseParseArguments( vector<string>& vArgs, ARGUMENTS& args ); |
|
44 |
|
45 //Helps. |
|
46 extern void print_help( void ); |
|
47 extern void print_syntax_examples( void ); |
|
48 |
|
49 //AT Library check functions |
|
50 extern bool CheckATLibrariesArmv5( string sEpocRoot ); |
|
51 extern bool CheckATLibrariesArmv5Abiv2( string sEpocRoot ); |
|
52 extern bool CheckATLibrariesWinscw( string sEpocRoot ); |
|
53 |
|
54 //Hti functions. |
|
55 #ifdef HTI_SUPPORT |
|
56 extern int htiGetReport( int argc, _TCHAR* argv[] ); |
|
57 extern int htiDeleteFile( int argc, _TCHAR* argv[] ); |
|
58 #endif |
|
59 |
|
60 //CLE version functions. |
|
61 extern int showVersionInfo( void ); |
|
62 |
|
63 //Miscelllanaeous functions. |
|
64 extern bool CheckSBS2Folder( void ); |
|
65 |
|
66 const char DEBUG_PARAMETER_CONSOLE[] = "-debug"; |
|
67 const char DEBUG_PARAMETER_DBGVIEW[] = "-dbgview"; |
|
68 const char SBS2_PARAMETER[] = "-sbs2"; |
|
69 char g_cCurrentDir[MAX_LINE_LENGTH]; |
|
70 |
|
71 //Global compile class objects are neededif ctrl+c is pressed mmp file must be restored. |
|
72 CATProject project_module; |
|
73 |
|
74 //Parse object. |
|
75 CATParseTraceFile Parser; |
|
76 |
|
77 /** |
|
78 * Handle process control signals. |
|
79 */ |
|
80 BOOL WINAPI HandlerRoutine( DWORD dwCtrlType ) |
|
81 { |
|
82 //Run recovery and exit for project if user presses ctrl+c |
|
83 //or close signal is received. |
|
84 if( dwCtrlType == CTRL_C_EVENT || dwCtrlType == CTRL_CLOSE_EVENT ) |
|
85 { |
|
86 int iMode = project_module.GetMode(); |
|
87 if ( iMode == CATProject::COMPILE |
|
88 || iMode == CATProject::INSTRUMENT |
|
89 || iMode == CATProject::INSTRUMENT_CONSOLE ) |
|
90 project_module.RunRecoveryAndExit(); |
|
91 } |
|
92 //Return false so program execution is stopped. |
|
93 return false; |
|
94 } |
|
95 // TESTING |
|
96 int _tmain( int argc, _TCHAR* argv[] ) |
|
97 { |
|
98 #ifdef MEM_LEAK_CHECK |
|
99 _CrtSetDbgFlag ( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF ); |
|
100 #endif |
|
101 try { |
|
102 //Set function to handle process control signals. |
|
103 SetConsoleCtrlHandler( HandlerRoutine, true ); |
|
104 vector<string> vArguments; |
|
105 for( int i = 1 ; i < argc ; i++ ) |
|
106 { |
|
107 vArguments.push_back( argv[i] ); |
|
108 } |
|
109 //Help variables. |
|
110 string sEpocRoot(""); |
|
111 //Parse base arguments. |
|
112 ARGUMENTS args; |
|
113 parseBaseArguments( vArguments, args ); |
|
114 |
|
115 // Debugging messages. |
|
116 if ( args.bDebugConsole == true ) |
|
117 g_bDebugConsole = true; |
|
118 if ( args.bDebugDbgView == true ) |
|
119 g_bDebugDbgView = true; |
|
120 if ( args.bDebugLowLevel == true ) |
|
121 g_bDebugLowLevel = true; |
|
122 |
|
123 //According to main switch parse rest arguments. |
|
124 switch( args.eMainSwitch ) |
|
125 { |
|
126 case SWITCH_UNKNOWN: |
|
127 print_help(); |
|
128 return AT_RETURN_CODE::INVALID_ARGUMENT_ERROR; |
|
129 case SWITCH_ANALYZE: |
|
130 if ( ! parseAnalyzeArguments( vArguments, args ) ) |
|
131 return AT_RETURN_CODE::INVALID_ARGUMENT_ERROR; |
|
132 // Get epocroot |
|
133 if( ! CATBase::GetEpocRoot( sEpocRoot ) ) |
|
134 return AT_RETURN_CODE::CANNOT_FIND_EPOCROOT; |
|
135 project_module.SetEpocRoot( sEpocRoot ); |
|
136 // project not uninstrumented run it first. |
|
137 if ( ! project_module.IsUninstrumented() ) |
|
138 { |
|
139 project_module.SetMode( CATProject::UNINSTRUMENT_CONSOLE ); |
|
140 project_module.Run(); |
|
141 } |
|
142 // Set mode. |
|
143 project_module.SetMode( CATProject::ANALYZE ); |
|
144 project_module.SetLogLevel( args.ANALYZE.iLoggingLevel ); |
|
145 project_module.SetDataFile( args.ANALYZE.sDataFile ); |
|
146 if ( args.ANALYZE.bSymbolFile ) |
|
147 project_module.SetRomSymbolFiles( args.ANALYZE.vSymbolFiles ); |
|
148 project_module.SetDataFileOutput( args.ANALYZE.sOutputFile); |
|
149 return project_module.Run(); |
|
150 case SWITCH_HOOK: |
|
151 // Parse arguments related to hooking. |
|
152 if ( ! parseHookArguments( vArguments, args ) ) |
|
153 return AT_RETURN_CODE::INVALID_ARGUMENT_ERROR; |
|
154 // Set variables for project. |
|
155 if ( ! project_module.SetArguments( args ) ) |
|
156 return AT_RETURN_CODE::INVALID_ARGUMENT_ERROR; |
|
157 // Get epocroot |
|
158 if( ! CATBase::GetEpocRoot( sEpocRoot ) ) |
|
159 return AT_RETURN_CODE::CANNOT_FIND_EPOCROOT; |
|
160 project_module.SetEpocRoot( sEpocRoot ); |
|
161 // Check AnalyzeTool libraries |
|
162 if ( _stricmp( args.HOOK.sPlatform.c_str(), "winscw") == 0 ) |
|
163 { |
|
164 // Emulator winscw platform |
|
165 if ( ! CheckATLibrariesWinscw(sEpocRoot) ) |
|
166 return AT_RETURN_CODE::AT_LIBS_MISSING; |
|
167 } |
|
168 else |
|
169 { |
|
170 // Armv5 |
|
171 if ( args.HOOK.iBuildSystem == 2 ) |
|
172 { |
|
173 // Abiv2 |
|
174 if ( ! CheckATLibrariesArmv5Abiv2(sEpocRoot) ) |
|
175 return AT_RETURN_CODE::AT_LIBS_MISSING; |
|
176 } |
|
177 else |
|
178 { |
|
179 // Abiv1 |
|
180 if( ! CheckATLibrariesArmv5(sEpocRoot) ) |
|
181 return AT_RETURN_CODE::AT_LIBS_MISSING; |
|
182 } |
|
183 } |
|
184 // Run hooking. |
|
185 return project_module.Run(); |
|
186 //Uninstrument |
|
187 case SWITCH_UNHOOK: |
|
188 // Set variables for project. |
|
189 if ( ! project_module.SetArguments( args ) ) |
|
190 return AT_RETURN_CODE::INVALID_ARGUMENT_ERROR; |
|
191 // Get epocroot |
|
192 if( ! CATBase::GetEpocRoot( sEpocRoot ) ) |
|
193 return AT_RETURN_CODE::CANNOT_FIND_EPOCROOT; |
|
194 project_module.SetEpocRoot( sEpocRoot ); |
|
195 return project_module.Run(); |
|
196 //Support for old extensions. |
|
197 case SWITCH_OLD_HOOK: |
|
198 // Parse old style arguments related to hooking. |
|
199 if ( ! parseOldHookArguments( vArguments, args ) ) |
|
200 return AT_RETURN_CODE::INVALID_ARGUMENT_ERROR; |
|
201 // Set mode for project. |
|
202 if( args.eHookSwitch == HOOK_OLD_EXTENSION_INSTRUMENT ) |
|
203 project_module.SetMode( CATProject::INSTRUMENT ); |
|
204 else if( args.eHookSwitch == HOOK_OLD_EXTENSION_UNINSTRUMENT ) |
|
205 project_module.SetMode( CATProject::UNINSTRUMENT ); |
|
206 else if( args.eHookSwitch == HOOK_OLD_EXTENSION_FAILED ) |
|
207 project_module.SetMode( CATProject::UNINSTRUMENT_FAILED ); |
|
208 else |
|
209 return AT_RETURN_CODE::INVALID_ARGUMENT_ERROR; |
|
210 |
|
211 // Get epocroot |
|
212 if( ! CATBase::GetEpocRoot( sEpocRoot ) ) |
|
213 return AT_RETURN_CODE::CANNOT_FIND_EPOCROOT; |
|
214 project_module.SetEpocRoot( sEpocRoot ); |
|
215 |
|
216 // Check AnalyzeTool libraries |
|
217 if ( _stricmp( args.HOOK.sPlatform.c_str(), "winscw") == 0 ) |
|
218 { |
|
219 // Emulator winscw platform |
|
220 if ( ! CheckATLibrariesWinscw(sEpocRoot) ) |
|
221 return AT_RETURN_CODE::AT_LIBS_MISSING; |
|
222 } |
|
223 else |
|
224 { |
|
225 // Armv5 |
|
226 if ( args.bEnableSbs2 == true ) |
|
227 { |
|
228 // Abiv2 |
|
229 if ( ! CheckATLibrariesArmv5Abiv2(sEpocRoot) ) |
|
230 return AT_RETURN_CODE::AT_LIBS_MISSING; |
|
231 } |
|
232 else |
|
233 { |
|
234 // Abiv1 |
|
235 if( ! CheckATLibrariesArmv5(sEpocRoot) ) |
|
236 return AT_RETURN_CODE::AT_LIBS_MISSING; |
|
237 } |
|
238 } |
|
239 |
|
240 // In uninstrument we check folder otherwise the switch for sbs version. |
|
241 if ( project_module.GetMode() == CATProject::UNINSTRUMENT ) |
|
242 { |
|
243 if ( CheckSBS2Folder() ) |
|
244 project_module.SetBuildSystem( CATProject::SBS_V2 ); |
|
245 else |
|
246 project_module.SetBuildSystem( CATProject::SBS_V1 ); |
|
247 } |
|
248 else |
|
249 { |
|
250 if ( args.bEnableSbs2 == true ) |
|
251 project_module.SetBuildSystem( CATProject::SBS_V2 ); |
|
252 else |
|
253 project_module.SetBuildSystem( CATProject::SBS_V1 ); |
|
254 } |
|
255 // platform |
|
256 project_module.SetPlatform( args.HOOK.sPlatform ); |
|
257 |
|
258 // build type |
|
259 if ( !_stricmp( args.HOOK.sBuildType.c_str(), "urel" ) ) |
|
260 project_module.SetBuildType( CATProject::UREL ); |
|
261 else if ( !_stricmp( args.HOOK.sBuildType.c_str(), "udeb" ) ) |
|
262 project_module.SetBuildType( CATProject::UDEB ); |
|
263 |
|
264 // Variant |
|
265 project_module.SetVariant( args.HOOK.sFeatureVariant ); |
|
266 |
|
267 // If selected modules to be compiled |
|
268 project_module.SetTargetModules( args.HOOK.vTargetPrograms ); |
|
269 |
|
270 // S60 data file name |
|
271 if ( args.HOOK.bDataFileName ) |
|
272 project_module.SetS60FileName( args.HOOK.sDataFileName ); |
|
273 |
|
274 // logging mode |
|
275 if ( args.HOOK.iLoggingMode == 2 ) |
|
276 project_module.SetLoggingMode( CATProject::S60 ); |
|
277 else |
|
278 project_module.SetLoggingMode( CATProject::XTI ); |
|
279 // run |
|
280 return project_module.Run(); |
|
281 case SWITCH_VERSION: |
|
282 return showVersionInfo(); |
|
283 case SWITCH_CLEAN: |
|
284 project_module.SetMode( CATProject::CLEAN ); |
|
285 if ( CheckSBS2Folder() ) |
|
286 project_module.SetBuildSystem( CATProject::SBS_V2 ); |
|
287 else |
|
288 project_module.SetBuildSystem( CATProject::SBS_V1 ); |
|
289 return project_module.Run(); |
|
290 case SWITCH_PARSE_TRACE: |
|
291 if ( ! parseParseArguments( vArguments, args ) ) |
|
292 return AT_RETURN_CODE::INVALID_ARGUMENT_ERROR; |
|
293 if ( CATBase::IsDataFile( args.PARSE.sDataFile ) ) |
|
294 { |
|
295 cout << AT_MSG << "Error, " << args.PARSE.sDataFile << " is already parsed." << endl; |
|
296 return AT_RETURN_CODE::INVALID_ARGUMENT_ERROR; |
|
297 } |
|
298 if ( args.PARSE.bOutputFile ) |
|
299 { |
|
300 //Save data with name in arguments[3] |
|
301 Parser.StartParse( args.PARSE.sDataFile.c_str(), args.PARSE.sOutputFile.c_str() ); |
|
302 } |
|
303 else |
|
304 { |
|
305 Parser.StartParse( args.PARSE.sDataFile.c_str(), NULL ); |
|
306 } |
|
307 return AT_RETURN_CODE::OK; |
|
308 #ifdef HTI_SUPPORT |
|
309 case SWITCH_HTI_DELETE: |
|
310 return htiDeleteFile( argc, argv ); |
|
311 case SWITCH_HTI_GET: |
|
312 return htiGetReport( argc, argv ); |
|
313 #endif |
|
314 case SWITCH_HELP: |
|
315 print_help(); |
|
316 print_syntax_examples(); |
|
317 return AT_RETURN_CODE::OK; |
|
318 default: |
|
319 cout << AT_MSG << "Invalid parameters." << endl; |
|
320 return AT_RETURN_CODE::INVALID_ARGUMENT_ERROR; |
|
321 } |
|
322 |
|
323 } catch(...) |
|
324 { |
|
325 cout << AT_MSG << "Error, unhandled exception." << endl; |
|
326 return AT_RETURN_CODE::UNHANDLED_EXCEPTION; |
|
327 } |
|
328 } |
|
329 |
|
330 //EOF |