|
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 parseAnalyzeArguments( vector<string>& vArgs, ARGUMENTS& args ); |
|
41 extern bool parseParseArguments( vector<string>& vArgs, ARGUMENTS& args ); |
|
42 |
|
43 //Helps. |
|
44 extern void print_help( void ); |
|
45 extern void print_syntax_examples( void ); |
|
46 |
|
47 //AT Library check functions |
|
48 extern bool CheckATLibrariesArmv5( string sEpocRoot ); |
|
49 extern bool CheckATLibrariesArmv5Abiv2( string sEpocRoot ); |
|
50 extern bool CheckATLibrariesWinscw( string sEpocRoot ); |
|
51 |
|
52 //CLE version functions. |
|
53 extern int showVersionInfo( void ); |
|
54 |
|
55 //dbghelp.dll version function. |
|
56 extern int showDbgHelpVersionInfo( bool showVersion ); |
|
57 |
|
58 //Miscelllanaeous functions. |
|
59 extern bool CheckSBS2Folder( void ); |
|
60 |
|
61 const char DEBUG_PARAMETER_CONSOLE[] = "-debug"; |
|
62 const char DEBUG_PARAMETER_DBGVIEW[] = "-dbgview"; |
|
63 const char SBS2_PARAMETER[] = "-sbs2"; |
|
64 char g_cCurrentDir[MAX_LINE_LENGTH]; |
|
65 |
|
66 //Global compile class objects are neededif ctrl+c is pressed mmp file must be restored. |
|
67 CATProject project_module; |
|
68 |
|
69 //Parse object. |
|
70 CATParseTraceFile Parser; |
|
71 |
|
72 /** |
|
73 * Handle process control signals. |
|
74 */ |
|
75 BOOL WINAPI HandlerRoutine( DWORD dwCtrlType ) |
|
76 { |
|
77 //Run recovery and exit for project if user presses ctrl+c |
|
78 //or close signal is received. |
|
79 if( dwCtrlType == CTRL_C_EVENT || dwCtrlType == CTRL_CLOSE_EVENT ) |
|
80 { |
|
81 int iMode = project_module.GetMode(); |
|
82 if ( iMode == CATProject::COMPILE |
|
83 || iMode == CATProject::INSTRUMENT |
|
84 || iMode == CATProject::INSTRUMENT_CONSOLE ) |
|
85 project_module.RunRecoveryAndExit(); |
|
86 } |
|
87 //Return false so program execution is stopped. |
|
88 return false; |
|
89 } |
|
90 // TESTING |
|
91 int _tmain( int argc, _TCHAR* argv[] ) |
|
92 { |
|
93 #ifdef MEM_LEAK_CHECK |
|
94 _CrtSetDbgFlag ( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF ); |
|
95 #endif |
|
96 try { |
|
97 //Set function to handle process control signals. |
|
98 SetConsoleCtrlHandler( HandlerRoutine, true ); |
|
99 vector<string> vArguments; |
|
100 for( int i = 1 ; i < argc ; i++ ) |
|
101 { |
|
102 vArguments.push_back( argv[i] ); |
|
103 } |
|
104 //Help variables. |
|
105 string sEpocRoot(""); |
|
106 //Parse base arguments. |
|
107 ARGUMENTS args; |
|
108 parseBaseArguments( vArguments, args ); |
|
109 |
|
110 // Debugging messages. |
|
111 if ( args.bDebugConsole == true ) |
|
112 g_bDebugConsole = true; |
|
113 if ( args.bDebugDbgView == true ) |
|
114 g_bDebugDbgView = true; |
|
115 if ( args.bDebugLowLevel == true ) |
|
116 g_bDebugLowLevel = true; |
|
117 |
|
118 //According to main switch parse rest arguments. |
|
119 switch( args.eMainSwitch ) |
|
120 { |
|
121 case SWITCH_UNKNOWN: |
|
122 print_help(); |
|
123 return AT_RETURN_CODE::INVALID_ARGUMENT_ERROR; |
|
124 case SWITCH_ANALYZE: |
|
125 if ( ! parseAnalyzeArguments( vArguments, args ) ) |
|
126 return AT_RETURN_CODE::INVALID_ARGUMENT_ERROR; |
|
127 // Get epocroot |
|
128 if( ! CATBase::GetEpocRoot( sEpocRoot ) ) |
|
129 return AT_RETURN_CODE::CANNOT_FIND_EPOCROOT; |
|
130 project_module.SetEpocRoot( sEpocRoot ); |
|
131 // project not uninstrumented run it first. |
|
132 if ( ! project_module.IsUninstrumented() ) |
|
133 { |
|
134 project_module.SetMode( CATProject::UNINSTRUMENT_CONSOLE ); |
|
135 project_module.Run(); |
|
136 } |
|
137 // Set mode. |
|
138 project_module.SetMode( CATProject::ANALYZE ); |
|
139 project_module.SetLogLevel( args.ANALYZE.iLoggingLevel ); |
|
140 project_module.SetDataFile( args.ANALYZE.sDataFile ); |
|
141 if ( args.ANALYZE.bSymbolFile ) |
|
142 project_module.SetRomSymbolFiles( args.ANALYZE.vSymbolFiles ); |
|
143 project_module.SetDataFileOutput( args.ANALYZE.sOutputFile); |
|
144 return project_module.Run(); |
|
145 case SWITCH_HOOK: |
|
146 // Parse arguments related to hooking. |
|
147 if ( ! parseHookArguments( vArguments, args ) ) |
|
148 return AT_RETURN_CODE::INVALID_ARGUMENT_ERROR; |
|
149 // Set variables for project. |
|
150 if ( ! project_module.SetArguments( args ) ) |
|
151 return AT_RETURN_CODE::INVALID_ARGUMENT_ERROR; |
|
152 // Get epocroot |
|
153 if( ! CATBase::GetEpocRoot( sEpocRoot ) ) |
|
154 return AT_RETURN_CODE::CANNOT_FIND_EPOCROOT; |
|
155 project_module.SetEpocRoot( sEpocRoot ); |
|
156 // Check AnalyzeTool libraries |
|
157 if ( _stricmp( args.HOOK.sPlatform.c_str(), "winscw") == 0 ) |
|
158 { |
|
159 // Emulator winscw platform |
|
160 if ( ! CheckATLibrariesWinscw(sEpocRoot) ) |
|
161 return AT_RETURN_CODE::AT_LIBS_MISSING; |
|
162 } |
|
163 else |
|
164 { |
|
165 // Armv5 |
|
166 if ( args.HOOK.iBuildSystem == 2 ) |
|
167 { |
|
168 // Abiv2 |
|
169 if ( ! CheckATLibrariesArmv5Abiv2(sEpocRoot) ) |
|
170 return AT_RETURN_CODE::AT_LIBS_MISSING; |
|
171 } |
|
172 else |
|
173 { |
|
174 // Abiv1 |
|
175 if( ! CheckATLibrariesArmv5(sEpocRoot) ) |
|
176 return AT_RETURN_CODE::AT_LIBS_MISSING; |
|
177 } |
|
178 } |
|
179 // Run hooking. |
|
180 return project_module.Run(); |
|
181 //Uninstrument |
|
182 case SWITCH_UNHOOK: |
|
183 // Set variables for project. |
|
184 if ( ! project_module.SetArguments( args ) ) |
|
185 return AT_RETURN_CODE::INVALID_ARGUMENT_ERROR; |
|
186 // Get epocroot |
|
187 if( ! CATBase::GetEpocRoot( sEpocRoot ) ) |
|
188 return AT_RETURN_CODE::CANNOT_FIND_EPOCROOT; |
|
189 project_module.SetEpocRoot( sEpocRoot ); |
|
190 return project_module.Run(); |
|
191 case SWITCH_VERSION: |
|
192 return showVersionInfo(); |
|
193 case SWITCH_DBGHELP_VERSION: |
|
194 return showDbgHelpVersionInfo( true ); |
|
195 case SWITCH_CLEAN: |
|
196 project_module.SetMode( CATProject::CLEAN ); |
|
197 if ( CheckSBS2Folder() ) |
|
198 project_module.SetBuildSystem( CATProject::SBS_V2 ); |
|
199 else |
|
200 project_module.SetBuildSystem( CATProject::SBS_V1 ); |
|
201 return project_module.Run(); |
|
202 case SWITCH_PARSE_TRACE: |
|
203 if ( ! parseParseArguments( vArguments, args ) ) |
|
204 return AT_RETURN_CODE::INVALID_ARGUMENT_ERROR; |
|
205 if ( CATBase::IsDataFile( args.PARSE.sDataFile ) ) |
|
206 { |
|
207 cout << AT_MSG << "Error, " << args.PARSE.sDataFile << " is already parsed." << endl; |
|
208 return AT_RETURN_CODE::INVALID_ARGUMENT_ERROR; |
|
209 } |
|
210 else if( CATBase::IsBinaryLogFile( args.PARSE.sDataFile ) ) |
|
211 { |
|
212 cout << AT_MSG << "Error, " << args.PARSE.sDataFile << " is binary log file." << endl; |
|
213 return AT_RETURN_CODE::INVALID_ARGUMENT_ERROR; |
|
214 } |
|
215 |
|
216 if ( args.PARSE.bOutputFile ) |
|
217 { |
|
218 //Save data with name in arguments[3] |
|
219 Parser.StartParse( args.PARSE.sDataFile.c_str(), args.PARSE.sOutputFile.c_str() ); |
|
220 } |
|
221 else |
|
222 { |
|
223 Parser.StartParse( args.PARSE.sDataFile.c_str(), NULL ); |
|
224 } |
|
225 return AT_RETURN_CODE::OK; |
|
226 case SWITCH_HELP: |
|
227 print_help(); |
|
228 print_syntax_examples(); |
|
229 return AT_RETURN_CODE::OK; |
|
230 default: |
|
231 cout << AT_MSG << "Invalid parameters." << endl; |
|
232 return AT_RETURN_CODE::INVALID_ARGUMENT_ERROR; |
|
233 } |
|
234 |
|
235 } catch(...) |
|
236 { |
|
237 cout << AT_MSG << "Error, unhandled exception." << endl; |
|
238 return AT_RETURN_CODE::UNHANDLED_EXCEPTION; |
|
239 } |
|
240 } |
|
241 |
|
242 //EOF |