OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 #include <stdlib.h> | 5 #include <stdlib.h> |
6 #include <string.h> | 6 #include <string.h> |
7 #include <stdio.h> | 7 #include <stdio.h> |
8 | 8 |
9 #include "include/dart_api.h" | 9 #include "include/dart_api.h" |
10 #include "include/dart_debugger_api.h" | 10 #include "include/dart_debugger_api.h" |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
105 if (*arg != '\0') { | 105 if (*arg != '\0') { |
106 return false; | 106 return false; |
107 } | 107 } |
108 has_verbose_option = true; | 108 has_verbose_option = true; |
109 return true; | 109 return true; |
110 } | 110 } |
111 | 111 |
112 | 112 |
113 static bool ProcessBreakpointOption(const char* funcname) { | 113 static bool ProcessBreakpointOption(const char* funcname) { |
114 ASSERT(funcname != NULL); | 114 ASSERT(funcname != NULL); |
| 115 if (*funcname == '\0') { |
| 116 return false; |
| 117 } |
115 breakpoint_at = funcname; | 118 breakpoint_at = funcname; |
116 return true; | 119 return true; |
117 } | 120 } |
118 | 121 |
119 | 122 |
120 static bool ProcessPackageRootOption(const char* arg) { | 123 static bool ProcessPackageRootOption(const char* arg) { |
121 ASSERT(arg != NULL); | 124 ASSERT(arg != NULL); |
| 125 if (*arg == '\0' || *arg == '-') { |
| 126 return false; |
| 127 } |
122 package_root = arg; | 128 package_root = arg; |
123 return true; | 129 return true; |
124 } | 130 } |
125 | 131 |
126 | 132 |
127 static bool ProcessCompileAllOption(const char* arg) { | 133 static bool ProcessCompileAllOption(const char* arg) { |
128 ASSERT(arg != NULL); | 134 ASSERT(arg != NULL); |
129 if (*arg != '\0') { | 135 if (*arg != '\0') { |
130 return false; | 136 return false; |
131 } | 137 } |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
190 if (*arg != '\0') { | 196 if (*arg != '\0') { |
191 return false; | 197 return false; |
192 } | 198 } |
193 has_print_script = true; | 199 has_print_script = true; |
194 return true; | 200 return true; |
195 } | 201 } |
196 | 202 |
197 | 203 |
198 static bool ProcessVmStatsRootOption(const char* arg) { | 204 static bool ProcessVmStatsRootOption(const char* arg) { |
199 ASSERT(arg != NULL); | 205 ASSERT(arg != NULL); |
| 206 if (*arg == '\0') { |
| 207 return false; |
| 208 } |
200 vmstats_root = arg; | 209 vmstats_root = arg; |
201 return true; | 210 return true; |
202 } | 211 } |
203 | 212 |
204 | 213 |
205 static bool ProcessGenScriptSnapshotOption(const char* filename) { | 214 static bool ProcessGenScriptSnapshotOption(const char* filename) { |
206 if (filename != NULL && strlen(filename) != 0) { | 215 if (filename != NULL && strlen(filename) != 0) { |
207 // Ensure that are already running using a full snapshot. | 216 // Ensure that are already running using a full snapshot. |
208 if (snapshot_buffer == NULL) { | 217 if (snapshot_buffer == NULL) { |
209 Log::PrintErr("Script snapshots cannot be generated in this version of" | 218 Log::PrintErr("Script snapshots cannot be generated in this version of" |
210 " dart\n"); | 219 " dart\n"); |
211 return false; | 220 return false; |
212 } | 221 } |
213 snapshot_file = File::Open(filename, File::kWriteTruncate); | 222 snapshot_file = File::Open(filename, File::kWriteTruncate); |
214 if (snapshot_file == NULL) { | 223 if (snapshot_file == NULL) { |
215 Log::PrintErr("Unable to open file %s for writing the snapshot\n", | 224 Log::PrintErr("Unable to open file %s for writing the snapshot\n", |
216 filename); | 225 filename); |
217 return false; | 226 return false; |
218 } | 227 } |
219 generate_script_snapshot = true; | 228 generate_script_snapshot = true; |
| 229 return true; |
220 } | 230 } |
221 return true; | 231 return false; |
222 } | 232 } |
223 | 233 |
224 | 234 |
225 static struct { | 235 static struct { |
226 const char* option_name; | 236 const char* option_name; |
227 bool (*process)(const char* option); | 237 bool (*process)(const char* option); |
228 } main_options[] = { | 238 } main_options[] = { |
229 // Standard options shared with dart2js. | 239 // Standard options shared with dart2js. |
230 { "--version", ProcessVersionOption }, | 240 { "--version", ProcessVersionOption }, |
231 { "--help", ProcessHelpOption }, | 241 { "--help", ProcessHelpOption }, |
232 { "-h", ProcessHelpOption }, | 242 { "-h", ProcessHelpOption }, |
233 { "--verbose", ProcessVerboseOption }, | 243 { "--verbose", ProcessVerboseOption }, |
234 { "-v", ProcessVerboseOption }, | 244 { "-v", ProcessVerboseOption }, |
235 { "--package-root=", ProcessPackageRootOption }, | 245 { "--package-root=", ProcessPackageRootOption }, |
236 { "-p", ProcessPackageRootOption }, | |
237 // VM specific options to the standalone dart program. | 246 // VM specific options to the standalone dart program. |
238 { "--break_at=", ProcessBreakpointOption }, | 247 { "--break-at=", ProcessBreakpointOption }, |
239 { "--compile_all", ProcessCompileAllOption }, | 248 { "--compile_all", ProcessCompileAllOption }, |
240 { "--debug", ProcessDebugOption }, | 249 { "--debug", ProcessDebugOption }, |
241 { "--generate-script-snapshot=", ProcessGenScriptSnapshotOption }, | 250 { "--snapshot=", ProcessGenScriptSnapshotOption }, |
242 { "--stats-root=", ProcessVmStatsRootOption }, | 251 { "--stats-root=", ProcessVmStatsRootOption }, |
243 { "--stats", ProcessVmStatsOption }, | 252 { "--stats", ProcessVmStatsOption }, |
244 { "--print-script", ProcessPrintScriptOption }, | 253 { "--print-script", ProcessPrintScriptOption }, |
245 { "--check-function-fingerprints", ProcessFingerprintedFunctions }, | 254 { "--check-function-fingerprints", ProcessFingerprintedFunctions }, |
246 { NULL, NULL } | 255 { NULL, NULL } |
247 }; | 256 }; |
248 | 257 |
249 | 258 |
250 static bool ProcessMainOptions(const char* option) { | 259 static bool ProcessMainOptions(const char* option) { |
251 int i = 0; | 260 int i = 0; |
252 const char* name = main_options[0].option_name; | 261 const char* name = main_options[0].option_name; |
| 262 int option_length = strlen(option); |
253 while (name != NULL) { | 263 while (name != NULL) { |
254 int length = strlen(name); | 264 int length = strlen(name); |
255 if (strncmp(option, name, length) == 0) { | 265 if ((option_length >= length) && (strncmp(option, name, length) == 0)) { |
256 return main_options[i].process(option + length); | 266 if (!main_options[i].process(option + length)) { |
| 267 Log::PrintErr("Invalid option specification : '%s'\n", option); |
| 268 } |
| 269 return true; |
257 } | 270 } |
258 i += 1; | 271 i += 1; |
259 name = main_options[i].option_name; | 272 name = main_options[i].option_name; |
260 } | 273 } |
261 return false; | 274 return false; |
262 } | 275 } |
263 | 276 |
264 | 277 |
265 // Convert all the arguments to UTF8. On Windows, the arguments are | 278 // Convert all the arguments to UTF8. On Windows, the arguments are |
266 // encoded in the current code page and not UTF8. | 279 // encoded in the current code page and not UTF8. |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
298 | 311 |
299 // Start the rest after the executable name. | 312 // Start the rest after the executable name. |
300 int i = 1; | 313 int i = 1; |
301 | 314 |
302 // Parse out the vm options. | 315 // Parse out the vm options. |
303 while (i < argc) { | 316 while (i < argc) { |
304 if (ProcessMainOptions(argv[i])) { | 317 if (ProcessMainOptions(argv[i])) { |
305 i++; | 318 i++; |
306 } else { | 319 } else { |
307 // Check if this flag is a potentially valid VM flag. | 320 // Check if this flag is a potentially valid VM flag. |
308 if (!IsValidFlag(argv[i], kPrefix, kPrefixLen)) { | 321 const char* kChecked = "-c"; |
| 322 const char* kPackageRoot = "-p"; |
| 323 if (strncmp(argv[i], kPackageRoot, strlen(kPackageRoot)) == 0) { |
| 324 if (!ProcessPackageRootOption(argv[i] + strlen(kPackageRoot))) { |
| 325 i++; |
| 326 if (!ProcessPackageRootOption(argv[i])) { |
| 327 Log::PrintErr("Invalid option specification : '%s'\n", argv[i - 1]); |
| 328 i++; |
| 329 break; |
| 330 } |
| 331 } |
| 332 } else if (strncmp(argv[i], kChecked, strlen(kChecked)) == 0) { |
| 333 vm_options->AddArgument("--checked"); |
| 334 } else if (!IsValidFlag(argv[i], kPrefix, kPrefixLen)) { |
309 break; | 335 break; |
310 } | 336 } |
311 const char* kPrintFlags1 = "--print-flags"; | 337 const char* kPrintFlags1 = "--print-flags"; |
312 const char* kPrintFlags2 = "--print_flags"; | 338 const char* kPrintFlags2 = "--print_flags"; |
313 if ((strncmp(argv[i], kPrintFlags1, strlen(kPrintFlags1)) == 0) || | 339 if ((strncmp(argv[i], kPrintFlags1, strlen(kPrintFlags1)) == 0) || |
314 (strncmp(argv[i], kPrintFlags2, strlen(kPrintFlags2)) == 0)) { | 340 (strncmp(argv[i], kPrintFlags2, strlen(kPrintFlags2)) == 0)) { |
315 *print_flags_seen = true; | 341 *print_flags_seen = true; |
316 } | 342 } |
317 const char* kVerboseDebug = "--verbose_debug"; | 343 const char* kVerboseDebug = "--verbose_debug"; |
318 if (strncmp(argv[i], kVerboseDebug, strlen(kVerboseDebug)) == 0) { | 344 if (strncmp(argv[i], kVerboseDebug, strlen(kVerboseDebug)) == 0) { |
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
532 "--help\n" | 558 "--help\n" |
533 " Display this message (add --verbose for information about all VM options).\n" | 559 " Display this message (add --verbose for information about all VM options).\n" |
534 "\n" | 560 "\n" |
535 "--package-root=<path>\n" | 561 "--package-root=<path>\n" |
536 " Where to find packages, that is, \"package:...\" imports.\n" | 562 " Where to find packages, that is, \"package:...\" imports.\n" |
537 "\n" | 563 "\n" |
538 "--debug[:<port number>]\n" | 564 "--debug[:<port number>]\n" |
539 " enables debugging and listens on specified port for debugger connections\n" | 565 " enables debugging and listens on specified port for debugger connections\n" |
540 " (default port number is 5858)\n" | 566 " (default port number is 5858)\n" |
541 "\n" | 567 "\n" |
542 "--break_at=<location>\n" | 568 "--break-at=<location>\n" |
543 " sets a breakpoint at specified location where <location> is one of :\n" | 569 " sets a breakpoint at specified location where <location> is one of :\n" |
544 " url:<line_num> e.g. test.dart:10\n" | 570 " url:<line_num> e.g. test.dart:10\n" |
545 " [<class_name>.]<function_name> e.g. B.foo\n" | 571 " [<class_name>.]<function_name> e.g. B.foo\n" |
546 "\n" | 572 "\n" |
547 "--generate-script-snapshot=<file_name>\n" | 573 "--snapshot=<file_name>\n" |
548 " loads Dart script and generates a snapshot in the specified file\n" | 574 " loads Dart script and generates a snapshot in the specified file\n" |
549 "\n" | 575 "\n" |
550 "--print-script\n" | 576 "--print-script\n" |
551 " generates Dart source code back and prints it after parsing a Dart script\n" | 577 " generates Dart source code back and prints it after parsing a Dart script\n" |
552 "\n" | 578 "\n" |
553 "--stats[:<port number>]\n" | 579 "--stats[:<port number>]\n" |
554 " enables VM stats service and listens on specified port for HTTP requests\n" | 580 " enables VM stats service and listens on specified port for HTTP requests\n" |
555 " (default port number is dynamically assigned)\n" | 581 " (default port number is dynamically assigned)\n" |
556 "\n" | 582 "\n" |
557 "--stats-root=<path>\n" | 583 "--stats-root=<path>\n" |
(...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
845 | 871 |
846 return Process::GlobalExitCode(); | 872 return Process::GlobalExitCode(); |
847 } | 873 } |
848 | 874 |
849 } // namespace bin | 875 } // namespace bin |
850 } // namespace dart | 876 } // namespace dart |
851 | 877 |
852 int main(int argc, char** argv) { | 878 int main(int argc, char** argv) { |
853 return dart::bin::main(argc, argv); | 879 return dart::bin::main(argc, argv); |
854 } | 880 } |
OLD | NEW |