Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(376)

Side by Side Diff: runtime/bin/main.cc

Issue 305473002: Add --observe flag alias (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 static bool IsValidFlag(const char* name, 78 static bool IsValidFlag(const char* name,
79 const char* prefix, 79 const char* prefix,
80 intptr_t prefix_length) { 80 intptr_t prefix_length) {
81 intptr_t name_length = strlen(name); 81 intptr_t name_length = strlen(name);
82 return ((name_length > prefix_length) && 82 return ((name_length > prefix_length) &&
83 (strncmp(name, prefix, prefix_length) == 0)); 83 (strncmp(name, prefix, prefix_length) == 0));
84 } 84 }
85 85
86 86
87 static bool has_version_option = false; 87 static bool has_version_option = false;
88 static bool ProcessVersionOption(const char* arg) { 88 static bool ProcessVersionOption(const char* arg,
89 CommandLineOptions* vm_options) {
89 if (*arg != '\0') { 90 if (*arg != '\0') {
90 return false; 91 return false;
91 } 92 }
92 has_version_option = true; 93 has_version_option = true;
93 return true; 94 return true;
94 } 95 }
95 96
96 97
97 static bool has_help_option = false; 98 static bool has_help_option = false;
98 static bool ProcessHelpOption(const char* arg) { 99 static bool ProcessHelpOption(const char* arg, CommandLineOptions* vm_options) {
99 if (*arg != '\0') { 100 if (*arg != '\0') {
100 return false; 101 return false;
101 } 102 }
102 has_help_option = true; 103 has_help_option = true;
103 return true; 104 return true;
104 } 105 }
105 106
106 107
107 static bool has_verbose_option = false; 108 static bool has_verbose_option = false;
108 static bool ProcessVerboseOption(const char* arg) { 109 static bool ProcessVerboseOption(const char* arg,
110 CommandLineOptions* vm_options) {
109 if (*arg != '\0') { 111 if (*arg != '\0') {
110 return false; 112 return false;
111 } 113 }
112 has_verbose_option = true; 114 has_verbose_option = true;
113 return true; 115 return true;
114 } 116 }
115 117
116 118
117 static bool ProcessBreakpointOption(const char* funcname) { 119 static bool ProcessBreakpointOption(const char* funcname,
120 CommandLineOptions* vm_options) {
118 ASSERT(funcname != NULL); 121 ASSERT(funcname != NULL);
119 if (*funcname == '\0') { 122 if (*funcname == '\0') {
120 return false; 123 return false;
121 } 124 }
122 breakpoint_at = funcname; 125 breakpoint_at = funcname;
123 return true; 126 return true;
124 } 127 }
125 128
126 129
127 static bool ProcessPackageRootOption(const char* arg) { 130 static bool ProcessPackageRootOption(const char* arg,
131 CommandLineOptions* vm_options) {
128 ASSERT(arg != NULL); 132 ASSERT(arg != NULL);
129 if (*arg == '\0' || *arg == '-') { 133 if (*arg == '\0' || *arg == '-') {
130 return false; 134 return false;
131 } 135 }
132 package_root = arg; 136 package_root = arg;
133 return true; 137 return true;
134 } 138 }
135 139
136 140
137 static void* GetHashmapKeyFromString(char* key) { 141 static void* GetHashmapKeyFromString(char* key) {
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 if (option_value[1 + n] == '\0') { 179 if (option_value[1 + n] == '\0') {
176 *out_ip = slash + 1; 180 *out_ip = slash + 1;
177 *out_port = port; 181 *out_port = port;
178 return true; 182 return true;
179 } 183 }
180 } 184 }
181 return false; 185 return false;
182 } 186 }
183 187
184 188
185 static bool ProcessEnvironmentOption(const char* arg) { 189 static bool ProcessEnvironmentOption(const char* arg,
190 CommandLineOptions* vm_options) {
186 ASSERT(arg != NULL); 191 ASSERT(arg != NULL);
187 if (*arg == '\0') { 192 if (*arg == '\0') {
188 // Ignore empty -D option. 193 // Ignore empty -D option.
189 Log::PrintErr("No arguments given to -D option\n"); 194 Log::PrintErr("No arguments given to -D option\n");
190 return true; 195 return true;
191 } 196 }
192 if (environment == NULL) { 197 if (environment == NULL) {
193 environment = new HashMap(&HashMap::SameStringValue, 4); 198 environment = new HashMap(&HashMap::SameStringValue, 4);
194 } 199 }
195 // Split the name=value part of the -Dname=value argument. 200 // Split the name=value part of the -Dname=value argument.
(...skipping 17 matching lines...) Expand all
213 value = strdup(equals_pos + 1); 218 value = strdup(equals_pos + 1);
214 } 219 }
215 HashMap::Entry* entry = environment->Lookup( 220 HashMap::Entry* entry = environment->Lookup(
216 GetHashmapKeyFromString(name), HashMap::StringHash(name), true); 221 GetHashmapKeyFromString(name), HashMap::StringHash(name), true);
217 ASSERT(entry != NULL); // Lookup adds an entry if key not found. 222 ASSERT(entry != NULL); // Lookup adds an entry if key not found.
218 entry->value = value; 223 entry->value = value;
219 return true; 224 return true;
220 } 225 }
221 226
222 227
223 static bool ProcessCompileAllOption(const char* arg) { 228 static bool ProcessCompileAllOption(const char* arg,
229 CommandLineOptions* vm_options) {
224 ASSERT(arg != NULL); 230 ASSERT(arg != NULL);
225 if (*arg != '\0') { 231 if (*arg != '\0') {
226 return false; 232 return false;
227 } 233 }
228 has_compile_all = true; 234 has_compile_all = true;
229 return true; 235 return true;
230 } 236 }
231 237
232 static bool ProcessDebugOption(const char* option_value) { 238 static bool ProcessDebugOption(const char* option_value,
239 CommandLineOptions* vm_options) {
233 ASSERT(option_value != NULL); 240 ASSERT(option_value != NULL);
234 if (!ExtractPortAndIP(option_value, &debug_port, &debug_ip, 241 if (!ExtractPortAndIP(option_value, &debug_port, &debug_ip,
235 DEFAULT_DEBUG_PORT, DEFAULT_DEBUG_IP)) { 242 DEFAULT_DEBUG_PORT, DEFAULT_DEBUG_IP)) {
236 Log::PrintErr("unrecognized --debug option syntax. " 243 Log::PrintErr("unrecognized --debug option syntax. "
237 "Use --debug[:<port number>[/<IPv4 address>]]\n"); 244 "Use --debug[:<port number>[/<IPv4 address>]]\n");
238 return false; 245 return false;
239 } 246 }
240 247
241 breakpoint_at = "main"; 248 breakpoint_at = "main";
242 start_debugger = true; 249 start_debugger = true;
243 return true; 250 return true;
244 } 251 }
245 252
246 253
247 static bool ProcessPrintScriptOption(const char* arg) { 254 static bool ProcessPrintScriptOption(const char* arg,
255 CommandLineOptions* vm_options) {
248 ASSERT(arg != NULL); 256 ASSERT(arg != NULL);
249 if (*arg != '\0') { 257 if (*arg != '\0') {
250 return false; 258 return false;
251 } 259 }
252 has_print_script = true; 260 has_print_script = true;
253 return true; 261 return true;
254 } 262 }
255 263
256 264
257 static bool ProcessGenScriptSnapshotOption(const char* filename) { 265 static bool ProcessGenScriptSnapshotOption(const char* filename,
266 CommandLineOptions* vm_options) {
258 if (filename != NULL && strlen(filename) != 0) { 267 if (filename != NULL && strlen(filename) != 0) {
259 // Ensure that are already running using a full snapshot. 268 // Ensure that are already running using a full snapshot.
260 if (snapshot_buffer == NULL) { 269 if (snapshot_buffer == NULL) {
261 Log::PrintErr("Script snapshots cannot be generated in this version of" 270 Log::PrintErr("Script snapshots cannot be generated in this version of"
262 " dart\n"); 271 " dart\n");
263 return false; 272 return false;
264 } 273 }
265 snapshot_file = File::Open(filename, File::kWriteTruncate); 274 snapshot_file = File::Open(filename, File::kWriteTruncate);
266 if (snapshot_file == NULL) { 275 if (snapshot_file == NULL) {
267 Log::PrintErr("Unable to open file %s for writing the snapshot\n", 276 Log::PrintErr("Unable to open file %s for writing the snapshot\n",
268 filename); 277 filename);
269 return false; 278 return false;
270 } 279 }
271 generate_script_snapshot = true; 280 generate_script_snapshot = true;
272 return true; 281 return true;
273 } 282 }
274 return false; 283 return false;
275 } 284 }
276 285
277 286
278 static bool ProcessEnableVmServiceOption(const char* option_value) { 287 static bool ProcessEnableVmServiceOption(const char* option_value,
288 CommandLineOptions* vm_options) {
279 ASSERT(option_value != NULL); 289 ASSERT(option_value != NULL);
280 290
281 if (!ExtractPortAndIP(option_value, 291 if (!ExtractPortAndIP(option_value,
282 &vm_service_server_port, 292 &vm_service_server_port,
283 &vm_service_server_ip, 293 &vm_service_server_ip,
284 DEFAULT_VM_SERVICE_SERVER_PORT, 294 DEFAULT_VM_SERVICE_SERVER_PORT,
285 DEFAULT_VM_SERVICE_SERVER_IP)) { 295 DEFAULT_VM_SERVICE_SERVER_IP)) {
286 Log::PrintErr("unrecognized --enable-vm-service option syntax. " 296 Log::PrintErr("unrecognized --enable-vm-service option syntax. "
bakster 2014/05/27 07:34:28 If this function is called from ProcessObserveOpti
287 "Use --enable-vm-service[:<port number>[/<IPv4 address>]]\n"); 297 "Use --enable-vm-service[:<port number>[/<IPv4 address>]]\n");
288 return false; 298 return false;
289 } 299 }
290 300
291 start_vm_service = true; 301 start_vm_service = true;
292 return true; 302 return true;
293 } 303 }
294 304
305 static bool ProcessObserveOption(const char* option_value,
306 CommandLineOptions* vm_options) {
307 ASSERT(option_value != NULL);
bakster 2014/05/27 07:34:28 The assert is not needed since ProcessEnableVmServ
308
309 if (!ProcessEnableVmServiceOption(option_value, vm_options)) {
310 return false;
311 }
312 vm_options->AddArgument("--pause-isolates-on-exit");
313 return true;
314 }
315
316
295 bool trace_debug_protocol = false; 317 bool trace_debug_protocol = false;
296 static bool ProcessTraceDebugProtocolOption(const char* arg) { 318 static bool ProcessTraceDebugProtocolOption(const char* arg,
319 CommandLineOptions* vm_options) {
297 if (*arg != '\0') { 320 if (*arg != '\0') {
298 return false; 321 return false;
299 } 322 }
300 trace_debug_protocol = true; 323 trace_debug_protocol = true;
301 return true; 324 return true;
302 } 325 }
303 326
304 327
305 static struct { 328 static struct {
306 const char* option_name; 329 const char* option_name;
307 bool (*process)(const char* option); 330 bool (*process)(const char* option, CommandLineOptions* vm_options);
308 } main_options[] = { 331 } main_options[] = {
309 // Standard options shared with dart2js. 332 // Standard options shared with dart2js.
310 { "--version", ProcessVersionOption }, 333 { "--version", ProcessVersionOption },
311 { "--help", ProcessHelpOption }, 334 { "--help", ProcessHelpOption },
312 { "-h", ProcessHelpOption }, 335 { "-h", ProcessHelpOption },
313 { "--verbose", ProcessVerboseOption }, 336 { "--verbose", ProcessVerboseOption },
314 { "-v", ProcessVerboseOption }, 337 { "-v", ProcessVerboseOption },
315 { "--package-root=", ProcessPackageRootOption }, 338 { "--package-root=", ProcessPackageRootOption },
316 { "-D", ProcessEnvironmentOption }, 339 { "-D", ProcessEnvironmentOption },
317 // VM specific options to the standalone dart program. 340 // VM specific options to the standalone dart program.
318 { "--break-at=", ProcessBreakpointOption }, 341 { "--break-at=", ProcessBreakpointOption },
319 { "--compile_all", ProcessCompileAllOption }, 342 { "--compile_all", ProcessCompileAllOption },
320 { "--debug", ProcessDebugOption }, 343 { "--debug", ProcessDebugOption },
321 { "--snapshot=", ProcessGenScriptSnapshotOption }, 344 { "--snapshot=", ProcessGenScriptSnapshotOption },
322 { "--print-script", ProcessPrintScriptOption }, 345 { "--print-script", ProcessPrintScriptOption },
323 { "--enable-vm-service", ProcessEnableVmServiceOption }, 346 { "--enable-vm-service", ProcessEnableVmServiceOption },
347 { "--observe", ProcessObserveOption },
324 { "--trace-debug-protocol", ProcessTraceDebugProtocolOption }, 348 { "--trace-debug-protocol", ProcessTraceDebugProtocolOption },
325 { NULL, NULL } 349 { NULL, NULL }
326 }; 350 };
327 351
328 352
329 static bool ProcessMainOptions(const char* option) { 353 static bool ProcessMainOptions(const char* option,
354 CommandLineOptions* vm_options) {
330 int i = 0; 355 int i = 0;
331 const char* name = main_options[0].option_name; 356 const char* name = main_options[0].option_name;
332 int option_length = strlen(option); 357 int option_length = strlen(option);
333 while (name != NULL) { 358 while (name != NULL) {
334 int length = strlen(name); 359 int length = strlen(name);
335 if ((option_length >= length) && (strncmp(option, name, length) == 0)) { 360 if ((option_length >= length) && (strncmp(option, name, length) == 0)) {
336 if (main_options[i].process(option + length)) { 361 if (main_options[i].process(option + length, vm_options)) {
337 return true; 362 return true;
338 } 363 }
339 } 364 }
340 i += 1; 365 i += 1;
341 name = main_options[i].option_name; 366 name = main_options[i].option_name;
342 } 367 }
343 return false; 368 return false;
344 } 369 }
345 370
346 371
(...skipping 28 matching lines...) Expand all
375 const intptr_t kPrefixLen = strlen(kPrefix); 400 const intptr_t kPrefixLen = strlen(kPrefix);
376 401
377 // Store the executable name. 402 // Store the executable name.
378 Platform::SetExecutableName(argv[0]); 403 Platform::SetExecutableName(argv[0]);
379 404
380 // Start the rest after the executable name. 405 // Start the rest after the executable name.
381 int i = 1; 406 int i = 1;
382 407
383 // Parse out the vm options. 408 // Parse out the vm options.
384 while (i < argc) { 409 while (i < argc) {
385 if (ProcessMainOptions(argv[i])) { 410 if (ProcessMainOptions(argv[i], vm_options)) {
386 i++; 411 i++;
387 } else { 412 } else {
388 // Check if this flag is a potentially valid VM flag. 413 // Check if this flag is a potentially valid VM flag.
389 const char* kChecked = "-c"; 414 const char* kChecked = "-c";
390 const char* kPackageRoot = "-p"; 415 const char* kPackageRoot = "-p";
391 if (strncmp(argv[i], kPackageRoot, strlen(kPackageRoot)) == 0) { 416 if (strncmp(argv[i], kPackageRoot, strlen(kPackageRoot)) == 0) {
392 if (!ProcessPackageRootOption(argv[i] + strlen(kPackageRoot))) { 417 if (!ProcessPackageRootOption(argv[i] + strlen(kPackageRoot),
418 vm_options)) {
393 i++; 419 i++;
394 if ((argv[i] == NULL) || !ProcessPackageRootOption(argv[i])) { 420 if ((argv[i] == NULL) ||
421 !ProcessPackageRootOption(argv[i], vm_options)) {
395 Log::PrintErr("Invalid option specification : '%s'\n", argv[i - 1]); 422 Log::PrintErr("Invalid option specification : '%s'\n", argv[i - 1]);
396 i++; 423 i++;
397 break; 424 break;
398 } 425 }
399 } 426 }
400 } else if (strncmp(argv[i], kChecked, strlen(kChecked)) == 0) { 427 } else if (strncmp(argv[i], kChecked, strlen(kChecked)) == 0) {
401 vm_options->AddArgument("--checked"); 428 vm_options->AddArgument("--checked");
402 } else if (!IsValidFlag(argv[i], kPrefix, kPrefixLen)) { 429 } else if (!IsValidFlag(argv[i], kPrefix, kPrefixLen)) {
403 break; 430 break;
404 } 431 }
(...skipping 724 matching lines...) Expand 10 before | Expand all | Expand 10 after
1129 exit(Process::GlobalExitCode()); 1156 exit(Process::GlobalExitCode());
1130 } 1157 }
1131 1158
1132 } // namespace bin 1159 } // namespace bin
1133 } // namespace dart 1160 } // namespace dart
1134 1161
1135 int main(int argc, char** argv) { 1162 int main(int argc, char** argv) {
1136 dart::bin::main(argc, argv); 1163 dart::bin::main(argc, argv);
1137 UNREACHABLE(); 1164 UNREACHABLE();
1138 } 1165 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698