| 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 28 matching lines...) Expand all Loading... |
| 39 // to be generated or not. | 39 // to be generated or not. |
| 40 static const char* generate_pprof_symbols_filename = NULL; | 40 static const char* generate_pprof_symbols_filename = NULL; |
| 41 | 41 |
| 42 | 42 |
| 43 // Global state that indicates whether there is a debug breakpoint. | 43 // Global state that indicates whether there is a debug breakpoint. |
| 44 // This pointer points into an argv buffer and does not need to be | 44 // This pointer points into an argv buffer and does not need to be |
| 45 // free'd. | 45 // free'd. |
| 46 static const char* breakpoint_at = NULL; | 46 static const char* breakpoint_at = NULL; |
| 47 | 47 |
| 48 | 48 |
| 49 // Value of the --package-root flag. |
| 50 // (This pointer points into an argv buffer and does not need to be |
| 51 // free'd.) |
| 52 static const char* package_root = NULL; |
| 53 |
| 54 |
| 49 // Global flag that is used to indicate that we want to compile all the | 55 // Global flag that is used to indicate that we want to compile all the |
| 50 // dart functions and not run anything. | 56 // dart functions and not run anything. |
| 51 static bool has_compile_all = false; | 57 static bool has_compile_all = false; |
| 52 | 58 |
| 53 | 59 |
| 54 static bool IsValidFlag(const char* name, | 60 static bool IsValidFlag(const char* name, |
| 55 const char* prefix, | 61 const char* prefix, |
| 56 intptr_t prefix_length) { | 62 intptr_t prefix_length) { |
| 57 intptr_t name_length = strlen(name); | 63 intptr_t name_length = strlen(name); |
| 58 return ((name_length > prefix_length) && | 64 return ((name_length > prefix_length) && |
| 59 (strncmp(name, prefix, prefix_length) == 0)); | 65 (strncmp(name, prefix, prefix_length) == 0)); |
| 60 } | 66 } |
| 61 | 67 |
| 62 | 68 |
| 63 static void ProcessBreakpointOption(const char* funcname) { | 69 static void ProcessBreakpointOption(const char* funcname) { |
| 64 ASSERT(funcname != NULL); | 70 ASSERT(funcname != NULL); |
| 65 breakpoint_at = funcname; | 71 breakpoint_at = funcname; |
| 66 } | 72 } |
| 67 | 73 |
| 68 | 74 |
| 75 static void ProcessPackageRootOption(const char* arg) { |
| 76 ASSERT(arg != NULL); |
| 77 package_root = arg; |
| 78 } |
| 79 |
| 80 |
| 69 static void ProcessCompileAllOption(const char* compile_all) { | 81 static void ProcessCompileAllOption(const char* compile_all) { |
| 70 ASSERT(compile_all != NULL); | 82 ASSERT(compile_all != NULL); |
| 71 has_compile_all = true; | 83 has_compile_all = true; |
| 72 } | 84 } |
| 73 | 85 |
| 74 | 86 |
| 75 static void ProcessPprofOption(const char* filename) { | 87 static void ProcessPprofOption(const char* filename) { |
| 76 ASSERT(filename != NULL); | 88 ASSERT(filename != NULL); |
| 77 generate_pprof_symbols_filename = filename; | 89 generate_pprof_symbols_filename = filename; |
| 78 } | 90 } |
| 79 | 91 |
| 80 | 92 |
| 81 static void ProcessImportMapOption(const char* map) { | 93 static void ProcessImportMapOption(const char* map) { |
| 82 ASSERT(map != NULL); | 94 ASSERT(map != NULL); |
| 83 import_map_options->AddArgument(map); | 95 import_map_options->AddArgument(map); |
| 84 } | 96 } |
| 85 | 97 |
| 86 | 98 |
| 87 static struct { | 99 static struct { |
| 88 const char* option_name; | 100 const char* option_name; |
| 89 void (*process)(const char* option); | 101 void (*process)(const char* option); |
| 90 } main_options[] = { | 102 } main_options[] = { |
| 91 { "--break_at=", ProcessBreakpointOption }, | 103 { "--break_at=", ProcessBreakpointOption }, |
| 92 { "--compile_all", ProcessCompileAllOption }, | 104 { "--compile_all", ProcessCompileAllOption }, |
| 93 { "--generate_pprof_symbols=", ProcessPprofOption }, | 105 { "--generate_pprof_symbols=", ProcessPprofOption }, |
| 94 { "--import_map=", ProcessImportMapOption }, | 106 { "--import_map=", ProcessImportMapOption }, |
| 107 { "--package-root=", ProcessPackageRootOption }, |
| 95 { NULL, NULL } | 108 { NULL, NULL } |
| 96 }; | 109 }; |
| 97 | 110 |
| 98 | 111 |
| 99 static bool ProcessMainOptions(const char* option) { | 112 static bool ProcessMainOptions(const char* option) { |
| 100 int i = 0; | 113 int i = 0; |
| 101 const char* name = main_options[0].option_name; | 114 const char* name = main_options[0].option_name; |
| 102 while (name != NULL) { | 115 while (name != NULL) { |
| 103 int length = strlen(name); | 116 int length = strlen(name); |
| 104 if (strncmp(option, name, length) == 0) { | 117 if (strncmp(option, name, length) == 0) { |
| (...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 360 } else { | 373 } else { |
| 361 Dart_ListSetAt(import_map, index, Dart_NewString(name)); | 374 Dart_ListSetAt(import_map, index, Dart_NewString(name)); |
| 362 Dart_ListSetAt(import_map, (index + 1), Dart_NewString("")); | 375 Dart_ListSetAt(import_map, (index + 1), Dart_NewString("")); |
| 363 } | 376 } |
| 364 free(name); | 377 free(name); |
| 365 } | 378 } |
| 366 return Dart_LoadScript(script_url, source, LibraryTagHandler, import_map); | 379 return Dart_LoadScript(script_url, source, LibraryTagHandler, import_map); |
| 367 } | 380 } |
| 368 | 381 |
| 369 | 382 |
| 383 // Returns true on success, false on failure. |
| 370 static bool CreateIsolateAndSetup(const char* name_prefix, | 384 static bool CreateIsolateAndSetup(const char* name_prefix, |
| 371 void* data, char** error) { | 385 void* data, char** error) { |
| 372 Dart_Isolate isolate = | 386 Dart_Isolate isolate = |
| 373 Dart_CreateIsolate(name_prefix, snapshot_buffer, data, error); | 387 Dart_CreateIsolate(name_prefix, snapshot_buffer, data, error); |
| 374 if (isolate == NULL) { | 388 if (isolate == NULL) { |
| 375 return false; | 389 return false; |
| 376 } | 390 } |
| 377 | 391 |
| 378 Dart_EnterScope(); | 392 Dart_EnterScope(); |
| 379 | 393 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 393 if (Dart_IsError(builtin_lib)) { | 407 if (Dart_IsError(builtin_lib)) { |
| 394 *error = strdup(Dart_GetError(builtin_lib)); | 408 *error = strdup(Dart_GetError(builtin_lib)); |
| 395 return false; | 409 return false; |
| 396 } | 410 } |
| 397 Dart_Handle library = Dart_LibraryImportLibrary(builtin_lib, uri_lib); | 411 Dart_Handle library = Dart_LibraryImportLibrary(builtin_lib, uri_lib); |
| 398 if (Dart_IsError(library)) { | 412 if (Dart_IsError(library)) { |
| 399 *error = strdup(Dart_GetError(library)); | 413 *error = strdup(Dart_GetError(library)); |
| 400 return false; | 414 return false; |
| 401 } | 415 } |
| 402 | 416 |
| 417 if (package_root != NULL) { |
| 418 Dart_Handle dart_args[1]; |
| 419 |
| 420 Dart_Handle handle = Dart_NewString(package_root); |
| 421 if (Dart_IsError(handle)) { |
| 422 *error = strdup(Dart_GetError(handle)); |
| 423 return false; |
| 424 } |
| 425 dart_args[0] = handle; |
| 426 |
| 427 Dart_Handle result = Dart_Invoke(builtin_lib, |
| 428 Dart_NewString("_setPackageRoot"), 1, dart_args); |
| 429 if (Dart_IsError(result)) { |
| 430 *error = strdup(Dart_GetError(result)); |
| 431 return false; |
| 432 } |
| 433 } |
| 434 |
| 403 // Load the specified application script into the newly created isolate. | 435 // Load the specified application script into the newly created isolate. |
| 404 library = LoadScript(builtin_lib, import_map_options); | 436 library = LoadScript(builtin_lib, import_map_options); |
| 405 if (Dart_IsError(library)) { | 437 if (Dart_IsError(library)) { |
| 406 *error = strdup(Dart_GetError(library)); | 438 *error = strdup(Dart_GetError(library)); |
| 407 Dart_ExitScope(); | 439 Dart_ExitScope(); |
| 408 Dart_ShutdownIsolate(); | 440 Dart_ShutdownIsolate(); |
| 409 return false; | 441 return false; |
| 410 } | 442 } |
| 411 if (!Dart_IsLibrary(library)) { | 443 if (!Dart_IsLibrary(library)) { |
| 412 char errbuf[256]; | 444 char errbuf[256]; |
| (...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 599 Dart_ShutdownIsolate(); | 631 Dart_ShutdownIsolate(); |
| 600 // Terminate process exit-code handler. | 632 // Terminate process exit-code handler. |
| 601 Process::TerminateExitCodeHandler(); | 633 Process::TerminateExitCodeHandler(); |
| 602 | 634 |
| 603 free(const_cast<char*>(original_script_name)); | 635 free(const_cast<char*>(original_script_name)); |
| 604 free(const_cast<char*>(original_working_directory)); | 636 free(const_cast<char*>(original_working_directory)); |
| 605 free(const_cast<char*>(original_script_url)); | 637 free(const_cast<char*>(original_script_url)); |
| 606 | 638 |
| 607 return 0; | 639 return 0; |
| 608 } | 640 } |
| OLD | NEW |