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_tools_api.h" | 10 #include "include/dart_tools_api.h" |
11 | 11 |
12 #include "bin/builtin.h" | 12 #include "bin/builtin.h" |
13 #include "bin/dartutils.h" | 13 #include "bin/dartutils.h" |
14 #include "bin/dbg_connection.h" | |
15 #include "bin/directory.h" | 14 #include "bin/directory.h" |
16 #include "bin/embedded_dart_io.h" | 15 #include "bin/embedded_dart_io.h" |
17 #include "bin/eventhandler.h" | 16 #include "bin/eventhandler.h" |
18 #include "bin/extensions.h" | 17 #include "bin/extensions.h" |
19 #include "bin/file.h" | 18 #include "bin/file.h" |
20 #include "bin/isolate_data.h" | 19 #include "bin/isolate_data.h" |
21 #include "bin/log.h" | 20 #include "bin/log.h" |
22 #include "bin/platform.h" | 21 #include "bin/platform.h" |
23 #include "bin/process.h" | 22 #include "bin/process.h" |
24 #include "bin/thread.h" | 23 #include "bin/thread.h" |
24 #include "bin/utils.h" | |
25 #include "bin/vmservice_impl.h" | 25 #include "bin/vmservice_impl.h" |
26 #include "platform/globals.h" | 26 #include "platform/globals.h" |
27 #include "platform/hashmap.h" | 27 #include "platform/hashmap.h" |
28 #include "platform/text_buffer.h" | |
28 | 29 |
29 namespace dart { | 30 namespace dart { |
30 namespace bin { | 31 namespace bin { |
31 | 32 |
32 // vm_isolate_snapshot_buffer points to a snapshot for the vm isolate if we | 33 // vm_isolate_snapshot_buffer points to a snapshot for the vm isolate if we |
33 // link in a snapshot otherwise it is initialized to NULL. | 34 // link in a snapshot otherwise it is initialized to NULL. |
34 extern const uint8_t* vm_isolate_snapshot_buffer; | 35 extern const uint8_t* vm_isolate_snapshot_buffer; |
35 | 36 |
36 // isolate_snapshot_buffer points to a snapshot for an isolate if we link in a | 37 // isolate_snapshot_buffer points to a snapshot for an isolate if we link in a |
37 // snapshot otherwise it is initialized to NULL. | 38 // snapshot otherwise it is initialized to NULL. |
38 extern const uint8_t* isolate_snapshot_buffer; | 39 extern const uint8_t* isolate_snapshot_buffer; |
39 | 40 |
40 // Global state that stores a pointer to the application script snapshot. | 41 // Global state that stores a pointer to the application script snapshot. |
41 static bool generate_script_snapshot = false; | 42 static bool generate_script_snapshot = false; |
42 static bool generate_script_snapshot_after_run = false; | 43 static bool generate_script_snapshot_after_run = false; |
43 static const char* snapshot_filename = NULL; | 44 static const char* snapshot_filename = NULL; |
44 | 45 |
45 | 46 |
46 // Global state that indicates whether there is a debug breakpoint. | |
47 // This pointer points into an argv buffer and does not need to be | |
48 // free'd. | |
49 static const char* breakpoint_at = NULL; | |
hausner
2015/12/04 00:23:11
I was hoping that the Observatory debugger could p
| |
50 | |
51 | |
52 // Global state that indicates whether we should open a connection | |
53 // and listen for a debugger to connect. | |
54 static bool start_debugger = false; | |
55 static const char* debug_ip = NULL; | |
56 static int debug_port = -1; | |
57 static const char* DEFAULT_DEBUG_IP = "127.0.0.1"; | |
58 static const int DEFAULT_DEBUG_PORT = 5858; | |
59 | |
60 // Value of the --package-root flag. | 47 // Value of the --package-root flag. |
61 // (This pointer points into an argv buffer and does not need to be | 48 // (This pointer points into an argv buffer and does not need to be |
62 // free'd.) | 49 // free'd.) |
63 static const char* commandline_package_root = NULL; | 50 static const char* commandline_package_root = NULL; |
64 | 51 |
65 // Value of the --packages flag. | 52 // Value of the --packages flag. |
66 // (This pointer points into an argv buffer and does not need to be | 53 // (This pointer points into an argv buffer and does not need to be |
67 // free'd.) | 54 // free'd.) |
68 static const char* commandline_packages_file = NULL; | 55 static const char* commandline_packages_file = NULL; |
69 | 56 |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
136 // Terminate process exit-code handler. | 123 // Terminate process exit-code handler. |
137 Process::TerminateExitCodeHandler(); | 124 Process::TerminateExitCodeHandler(); |
138 | 125 |
139 char* error = Dart_Cleanup(); | 126 char* error = Dart_Cleanup(); |
140 if (error != NULL) { | 127 if (error != NULL) { |
141 Log::PrintErr("VM cleanup failed: %s\n", error); | 128 Log::PrintErr("VM cleanup failed: %s\n", error); |
142 free(error); | 129 free(error); |
143 } | 130 } |
144 | 131 |
145 if (do_vm_shutdown) { | 132 if (do_vm_shutdown) { |
146 DebuggerConnectionHandler::StopHandler(); | |
147 EventHandler::Stop(); | 133 EventHandler::Stop(); |
148 } | 134 } |
149 Platform::Exit(exit_code); | 135 Platform::Exit(exit_code); |
150 } | 136 } |
151 | 137 |
152 | 138 |
153 // The environment provided through the command line using -D options. | 139 // The environment provided through the command line using -D options. |
154 static dart::HashMap* environment = NULL; | 140 static dart::HashMap* environment = NULL; |
155 | 141 |
156 static bool IsValidFlag(const char* name, | 142 static bool IsValidFlag(const char* name, |
(...skipping 30 matching lines...) Expand all Loading... | |
187 static bool ProcessVerboseOption(const char* arg, | 173 static bool ProcessVerboseOption(const char* arg, |
188 CommandLineOptions* vm_options) { | 174 CommandLineOptions* vm_options) { |
189 if (*arg != '\0') { | 175 if (*arg != '\0') { |
190 return false; | 176 return false; |
191 } | 177 } |
192 has_verbose_option = true; | 178 has_verbose_option = true; |
193 return true; | 179 return true; |
194 } | 180 } |
195 | 181 |
196 | 182 |
197 static bool ProcessBreakpointOption(const char* funcname, | |
198 CommandLineOptions* vm_options) { | |
199 ASSERT(funcname != NULL); | |
200 if (*funcname == '\0') { | |
201 return false; | |
202 } | |
203 breakpoint_at = funcname; | |
204 return true; | |
205 } | |
206 | |
207 | |
208 static bool ProcessPackageRootOption(const char* arg, | 183 static bool ProcessPackageRootOption(const char* arg, |
209 CommandLineOptions* vm_options) { | 184 CommandLineOptions* vm_options) { |
210 ASSERT(arg != NULL); | 185 ASSERT(arg != NULL); |
211 if (*arg == '\0' || *arg == '-') { | 186 if (*arg == '\0' || *arg == '-') { |
212 return false; | 187 return false; |
213 } | 188 } |
214 commandline_package_root = arg; | 189 commandline_package_root = arg; |
215 return true; | 190 return true; |
216 } | 191 } |
217 | 192 |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
363 ASSERT(arg != NULL); | 338 ASSERT(arg != NULL); |
364 if (*arg != '\0') { | 339 if (*arg != '\0') { |
365 return false; | 340 return false; |
366 } | 341 } |
367 has_noopt = true; | 342 has_noopt = true; |
368 vm_options->AddArgument("--precompilation"); | 343 vm_options->AddArgument("--precompilation"); |
369 return true; | 344 return true; |
370 } | 345 } |
371 | 346 |
372 | 347 |
373 static bool ProcessDebugOption(const char* option_value, | |
374 CommandLineOptions* vm_options) { | |
375 ASSERT(option_value != NULL); | |
376 if (!ExtractPortAndIP(option_value, &debug_port, &debug_ip, | |
377 DEFAULT_DEBUG_PORT, DEFAULT_DEBUG_IP)) { | |
378 Log::PrintErr("unrecognized --debug option syntax. " | |
379 "Use --debug[:<port number>[/<IPv4 address>]]\n"); | |
380 return false; | |
381 } | |
382 | |
383 breakpoint_at = "main"; | |
384 start_debugger = true; | |
385 return true; | |
386 } | |
387 | |
388 | |
389 static bool ProcessScriptSnapshotOptionHelper(const char* filename, | 348 static bool ProcessScriptSnapshotOptionHelper(const char* filename, |
390 bool* snapshot_option) { | 349 bool* snapshot_option) { |
391 *snapshot_option = false; | 350 *snapshot_option = false; |
392 if ((filename != NULL) && (strlen(filename) != 0)) { | 351 if ((filename != NULL) && (strlen(filename) != 0)) { |
393 // Ensure that we are already running using a full snapshot. | 352 // Ensure that we are already running using a full snapshot. |
394 if (isolate_snapshot_buffer == NULL) { | 353 if (isolate_snapshot_buffer == NULL) { |
395 Log::PrintErr("Script snapshots cannot be generated in this version of" | 354 Log::PrintErr("Script snapshots cannot be generated in this version of" |
396 " dart\n"); | 355 " dart\n"); |
397 return false; | 356 return false; |
398 } | 357 } |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
452 Log::PrintErr("unrecognized --observe option syntax. " | 411 Log::PrintErr("unrecognized --observe option syntax. " |
453 "Use --observe[:<port number>[/<IPv4 address>]]\n"); | 412 "Use --observe[:<port number>[/<IPv4 address>]]\n"); |
454 return false; | 413 return false; |
455 } | 414 } |
456 | 415 |
457 vm_options->AddArgument("--pause-isolates-on-exit"); | 416 vm_options->AddArgument("--pause-isolates-on-exit"); |
458 return true; | 417 return true; |
459 } | 418 } |
460 | 419 |
461 | 420 |
462 extern bool trace_debug_protocol; | |
463 static bool ProcessTraceDebugProtocolOption(const char* arg, | |
464 CommandLineOptions* vm_options) { | |
465 if (*arg != '\0') { | |
466 return false; | |
467 } | |
468 trace_debug_protocol = true; | |
469 return true; | |
470 } | |
471 | |
472 | |
473 static bool ProcessTraceLoadingOption(const char* arg, | 421 static bool ProcessTraceLoadingOption(const char* arg, |
474 CommandLineOptions* vm_options) { | 422 CommandLineOptions* vm_options) { |
475 if (*arg != '\0') { | 423 if (*arg != '\0') { |
476 return false; | 424 return false; |
477 } | 425 } |
478 has_trace_loading = true; | 426 has_trace_loading = true; |
479 return true; | 427 return true; |
480 } | 428 } |
481 | 429 |
482 | 430 |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
516 { "-D", ProcessEnvironmentOption }, | 464 { "-D", ProcessEnvironmentOption }, |
517 { "-h", ProcessHelpOption }, | 465 { "-h", ProcessHelpOption }, |
518 { "--help", ProcessHelpOption }, | 466 { "--help", ProcessHelpOption }, |
519 { "--packages=", ProcessPackagesOption }, | 467 { "--packages=", ProcessPackagesOption }, |
520 { "--package-root=", ProcessPackageRootOption }, | 468 { "--package-root=", ProcessPackageRootOption }, |
521 { "-v", ProcessVerboseOption }, | 469 { "-v", ProcessVerboseOption }, |
522 { "--verbose", ProcessVerboseOption }, | 470 { "--verbose", ProcessVerboseOption }, |
523 { "--version", ProcessVersionOption }, | 471 { "--version", ProcessVersionOption }, |
524 | 472 |
525 // VM specific options to the standalone dart program. | 473 // VM specific options to the standalone dart program. |
526 { "--break-at=", ProcessBreakpointOption }, | |
527 { "--compile_all", ProcessCompileAllOption }, | 474 { "--compile_all", ProcessCompileAllOption }, |
528 { "--debug", ProcessDebugOption }, | |
529 { "--enable-vm-service", ProcessEnableVmServiceOption }, | 475 { "--enable-vm-service", ProcessEnableVmServiceOption }, |
530 { "--gen-precompiled-snapshot", ProcessGenPrecompiledSnapshotOption }, | 476 { "--gen-precompiled-snapshot", ProcessGenPrecompiledSnapshotOption }, |
531 { "--noopt", ProcessNooptOption }, | 477 { "--noopt", ProcessNooptOption }, |
532 { "--observe", ProcessObserveOption }, | 478 { "--observe", ProcessObserveOption }, |
533 { "--run-precompiled-snapshot", ProcessRunPrecompiledSnapshotOption }, | 479 { "--run-precompiled-snapshot", ProcessRunPrecompiledSnapshotOption }, |
534 { "--shutdown", ProcessShutdownOption }, | 480 { "--shutdown", ProcessShutdownOption }, |
535 { "--snapshot=", ProcessScriptSnapshotOption }, | 481 { "--snapshot=", ProcessScriptSnapshotOption }, |
536 { "--snapshot-after-run=", ProcessScriptSnapshotAfterRunOption }, | 482 { "--snapshot-after-run=", ProcessScriptSnapshotAfterRunOption }, |
537 { "--trace-debug-protocol", ProcessTraceDebugProtocolOption }, | |
538 { "--trace-loading", ProcessTraceLoadingOption }, | 483 { "--trace-loading", ProcessTraceLoadingOption }, |
539 { NULL, NULL } | 484 { NULL, NULL } |
540 }; | 485 }; |
541 | 486 |
542 | 487 |
543 static bool ProcessMainOptions(const char* option, | 488 static bool ProcessMainOptions(const char* option, |
544 CommandLineOptions* vm_options) { | 489 CommandLineOptions* vm_options) { |
545 int i = 0; | 490 int i = 0; |
546 const char* name = main_options[0].option_name; | 491 const char* name = main_options[0].option_name; |
547 int option_length = strlen(option); | 492 int option_length = strlen(option); |
(...skipping 409 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
957 " (default port number is 8181)\n" | 902 " (default port number is 8181)\n" |
958 "\n" | 903 "\n" |
959 "The following options are only used for VM development and may\n" | 904 "The following options are only used for VM development and may\n" |
960 "be changed in any future version:\n"); | 905 "be changed in any future version:\n"); |
961 const char* print_flags = "--print_flags"; | 906 const char* print_flags = "--print_flags"; |
962 Dart_SetVMFlags(1, &print_flags); | 907 Dart_SetVMFlags(1, &print_flags); |
963 } | 908 } |
964 } | 909 } |
965 | 910 |
966 | 911 |
967 static Dart_Handle SetBreakpoint(const char* breakpoint_at, | |
968 Dart_Handle library) { | |
969 char* bpt_function = strdup(breakpoint_at); | |
970 Dart_Handle class_name; | |
971 Dart_Handle function_name; | |
972 char* dot = strchr(bpt_function, '.'); | |
973 if (dot == NULL) { | |
974 class_name = DartUtils::NewString(""); | |
975 function_name = DartUtils::NewString(breakpoint_at); | |
976 } else { | |
977 *dot = '\0'; | |
978 class_name = DartUtils::NewString(bpt_function); | |
979 function_name = DartUtils::NewString(dot + 1); | |
980 } | |
981 free(bpt_function); | |
982 return Dart_OneTimeBreakAtEntry(library, class_name, function_name); | |
983 } | |
984 | |
985 | |
986 char* BuildIsolateName(const char* script_name, | 912 char* BuildIsolateName(const char* script_name, |
987 const char* func_name) { | 913 const char* func_name) { |
988 // Skip past any slashes in the script name. | 914 // Skip past any slashes in the script name. |
989 const char* last_slash = strrchr(script_name, '/'); | 915 const char* last_slash = strrchr(script_name, '/'); |
990 if (last_slash != NULL) { | 916 if (last_slash != NULL) { |
991 script_name = last_slash + 1; | 917 script_name = last_slash + 1; |
992 } | 918 } |
993 | 919 |
994 const char* kFormat = "%s/%s"; | 920 const char* kFormat = "%s/%s"; |
995 intptr_t len = strlen(script_name) + strlen(func_name) + 2; | 921 intptr_t len = strlen(script_name) + strlen(func_name) + 2; |
(...skipping 26 matching lines...) Expand all Loading... | |
1022 | 948 |
1023 static const char* ServiceGetIOHandler( | 949 static const char* ServiceGetIOHandler( |
1024 const char* method, | 950 const char* method, |
1025 const char** param_keys, | 951 const char** param_keys, |
1026 const char** param_values, | 952 const char** param_values, |
1027 intptr_t num_params, | 953 intptr_t num_params, |
1028 void* user_data) { | 954 void* user_data) { |
1029 DartScope scope; | 955 DartScope scope; |
1030 // TODO(ajohnsen): Store the library/function in isolate data or user_data. | 956 // TODO(ajohnsen): Store the library/function in isolate data or user_data. |
1031 Dart_Handle dart_io_str = Dart_NewStringFromCString("dart:io"); | 957 Dart_Handle dart_io_str = Dart_NewStringFromCString("dart:io"); |
1032 if (Dart_IsError(dart_io_str)) return ServiceRequestError(dart_io_str); | 958 if (Dart_IsError(dart_io_str)) { |
959 return ServiceRequestError(dart_io_str); | |
960 } | |
961 | |
1033 Dart_Handle io_lib = Dart_LookupLibrary(dart_io_str); | 962 Dart_Handle io_lib = Dart_LookupLibrary(dart_io_str); |
1034 if (Dart_IsError(io_lib)) return ServiceRequestError(io_lib); | 963 if (Dart_IsError(io_lib)) { |
964 return ServiceRequestError(io_lib); | |
965 } | |
966 | |
1035 Dart_Handle handler_function_name = | 967 Dart_Handle handler_function_name = |
1036 Dart_NewStringFromCString("_serviceObjectHandler"); | 968 Dart_NewStringFromCString("_serviceObjectHandler"); |
1037 if (Dart_IsError(handler_function_name)) { | 969 if (Dart_IsError(handler_function_name)) { |
1038 return ServiceRequestError(handler_function_name); | 970 return ServiceRequestError(handler_function_name); |
1039 } | 971 } |
972 | |
1040 // TODO(johnmccutchan): paths is no longer used. Update the io | 973 // TODO(johnmccutchan): paths is no longer used. Update the io |
1041 // _serviceObjectHandler function to use json rpc. | 974 // _serviceObjectHandler function to use json rpc. |
1042 Dart_Handle paths = Dart_NewList(0); | 975 Dart_Handle paths = Dart_NewList(0); |
1043 Dart_Handle keys = Dart_NewList(num_params); | 976 Dart_Handle keys = Dart_NewList(num_params); |
1044 Dart_Handle values = Dart_NewList(num_params); | 977 Dart_Handle values = Dart_NewList(num_params); |
1045 for (int i = 0; i < num_params; i++) { | 978 for (int i = 0; i < num_params; i++) { |
1046 Dart_ListSetAt(keys, i, Dart_NewStringFromCString(param_keys[i])); | 979 Dart_ListSetAt(keys, i, Dart_NewStringFromCString(param_keys[i])); |
1047 Dart_ListSetAt(values, i, Dart_NewStringFromCString(param_values[i])); | 980 Dart_ListSetAt(values, i, Dart_NewStringFromCString(param_values[i])); |
1048 } | 981 } |
1049 Dart_Handle args[] = {paths, keys, values}; | 982 Dart_Handle args[] = {paths, keys, values}; |
1050 Dart_Handle result = Dart_Invoke(io_lib, handler_function_name, 3, args); | 983 Dart_Handle result = Dart_Invoke(io_lib, handler_function_name, 3, args); |
1051 if (Dart_IsError(result)) return ServiceRequestError(result); | 984 if (Dart_IsError(result)) { |
985 return ServiceRequestError(result); | |
986 } | |
987 | |
1052 const char *json; | 988 const char *json; |
1053 result = Dart_StringToCString(result, &json); | 989 result = Dart_StringToCString(result, &json); |
1054 if (Dart_IsError(result)) return ServiceRequestError(result); | 990 if (Dart_IsError(result)) { |
991 return ServiceRequestError(result); | |
992 } | |
1055 return strdup(json); | 993 return strdup(json); |
1056 } | 994 } |
1057 | 995 |
1058 | 996 |
1059 static const char* kStdoutStreamId = "Stdout"; | 997 static const char* kStdoutStreamId = "Stdout"; |
1060 static const char* kStderrStreamId = "Stderr"; | 998 static const char* kStderrStreamId = "Stderr"; |
1061 | 999 |
1062 | 1000 |
1063 static bool ServiceStreamListenCallback(const char* stream_id) { | 1001 static bool ServiceStreamListenCallback(const char* stream_id) { |
1064 if (strcmp(stream_id, kStdoutStreamId) == 0) { | 1002 if (strcmp(stream_id, kStdoutStreamId) == 0) { |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1192 Log::PrintErr("%s\n", error); | 1130 Log::PrintErr("%s\n", error); |
1193 free(error); | 1131 free(error); |
1194 error = NULL; | 1132 error = NULL; |
1195 Process::TerminateExitCodeHandler(); | 1133 Process::TerminateExitCodeHandler(); |
1196 error = Dart_Cleanup(); | 1134 error = Dart_Cleanup(); |
1197 if (error != NULL) { | 1135 if (error != NULL) { |
1198 Log::PrintErr("VM cleanup failed: %s\n", error); | 1136 Log::PrintErr("VM cleanup failed: %s\n", error); |
1199 free(error); | 1137 free(error); |
1200 } | 1138 } |
1201 if (do_vm_shutdown) { | 1139 if (do_vm_shutdown) { |
1202 DebuggerConnectionHandler::StopHandler(); | |
1203 EventHandler::Stop(); | 1140 EventHandler::Stop(); |
1204 } | 1141 } |
1205 Platform::Exit((exit_code != 0) ? exit_code : kErrorExitCode); | 1142 Platform::Exit((exit_code != 0) ? exit_code : kErrorExitCode); |
1206 } | 1143 } |
1207 delete [] isolate_name; | 1144 delete [] isolate_name; |
1208 | 1145 |
1209 Dart_EnterIsolate(isolate); | 1146 Dart_EnterIsolate(isolate); |
1210 ASSERT(isolate == Dart_CurrentIsolate()); | 1147 ASSERT(isolate == Dart_CurrentIsolate()); |
1211 ASSERT(isolate != NULL); | 1148 ASSERT(isolate != NULL); |
1212 Dart_Handle result; | 1149 Dart_Handle result; |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1309 script_name); | 1246 script_name); |
1310 } | 1247 } |
1311 | 1248 |
1312 // The helper function _getMainClosure creates a closure for the main | 1249 // The helper function _getMainClosure creates a closure for the main |
1313 // entry point which is either explicitly or implictly exported from the | 1250 // entry point which is either explicitly or implictly exported from the |
1314 // root library. | 1251 // root library. |
1315 Dart_Handle main_closure = Dart_Invoke(builtin_lib, | 1252 Dart_Handle main_closure = Dart_Invoke(builtin_lib, |
1316 Dart_NewStringFromCString("_getMainClosure"), 0, NULL); | 1253 Dart_NewStringFromCString("_getMainClosure"), 0, NULL); |
1317 CHECK_RESULT(main_closure); | 1254 CHECK_RESULT(main_closure); |
1318 | 1255 |
1319 // Set debug breakpoint if specified on the command line before calling | |
1320 // the main function. | |
1321 if (breakpoint_at != NULL) { | |
1322 result = SetBreakpoint(breakpoint_at, root_lib); | |
1323 if (Dart_IsError(result)) { | |
1324 ErrorExit(kErrorExitCode, | |
1325 "Error setting breakpoint at '%s': %s\n", | |
1326 breakpoint_at, | |
1327 Dart_GetError(result)); | |
1328 } | |
1329 } | |
1330 | |
1331 // Call _startIsolate in the isolate library to enable dispatching the | 1256 // Call _startIsolate in the isolate library to enable dispatching the |
1332 // initial startup message. | 1257 // initial startup message. |
1333 const intptr_t kNumIsolateArgs = 2; | 1258 const intptr_t kNumIsolateArgs = 2; |
1334 Dart_Handle isolate_args[kNumIsolateArgs]; | 1259 Dart_Handle isolate_args[kNumIsolateArgs]; |
1335 isolate_args[0] = main_closure; // entryPoint | 1260 isolate_args[0] = main_closure; // entryPoint |
1336 isolate_args[1] = CreateRuntimeOptions(dart_options); // args | 1261 isolate_args[1] = CreateRuntimeOptions(dart_options); // args |
1337 | 1262 |
1338 Dart_Handle isolate_lib = | 1263 Dart_Handle isolate_lib = |
1339 Dart_LookupLibrary(Dart_NewStringFromCString("dart:isolate")); | 1264 Dart_LookupLibrary(Dart_NewStringFromCString("dart:isolate")); |
1340 result = Dart_Invoke(isolate_lib, | 1265 result = Dart_Invoke(isolate_lib, |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1427 | 1352 |
1428 if (generate_script_snapshot) { | 1353 if (generate_script_snapshot) { |
1429 vm_options.AddArgument("--load_deferred_eagerly"); | 1354 vm_options.AddArgument("--load_deferred_eagerly"); |
1430 } | 1355 } |
1431 | 1356 |
1432 Dart_SetVMFlags(vm_options.count(), vm_options.arguments()); | 1357 Dart_SetVMFlags(vm_options.count(), vm_options.arguments()); |
1433 | 1358 |
1434 // Start event handler. | 1359 // Start event handler. |
1435 EventHandler::Start(); | 1360 EventHandler::Start(); |
1436 | 1361 |
1437 // Start the debugger wire protocol handler if necessary. | |
1438 if (start_debugger) { | |
1439 ASSERT(debug_port >= 0); | |
1440 bool print_msg = verbose_debug_seen || (debug_port == 0); | |
1441 debug_port = DebuggerConnectionHandler::StartHandler(debug_ip, debug_port); | |
1442 if (print_msg) { | |
1443 Log::Print("Debugger listening on port %d\n", debug_port); | |
1444 } | |
1445 } else { | |
1446 DebuggerConnectionHandler::InitForVmService(); | |
1447 } | |
1448 | |
1449 const uint8_t* instructions_snapshot = NULL; | 1362 const uint8_t* instructions_snapshot = NULL; |
1450 if (has_run_precompiled_snapshot) { | 1363 if (has_run_precompiled_snapshot) { |
1451 instructions_snapshot = reinterpret_cast<const uint8_t*>( | 1364 instructions_snapshot = reinterpret_cast<const uint8_t*>( |
1452 LoadLibrarySymbol(kPrecompiledLibraryName, kPrecompiledSymbolName)); | 1365 LoadLibrarySymbol(kPrecompiledLibraryName, kPrecompiledSymbolName)); |
1453 ReadSnapshotFile(kPrecompiledVmIsolateName, &vm_isolate_snapshot_buffer); | 1366 ReadSnapshotFile(kPrecompiledVmIsolateName, &vm_isolate_snapshot_buffer); |
1454 ReadSnapshotFile(kPrecompiledIsolateName, &isolate_snapshot_buffer); | 1367 ReadSnapshotFile(kPrecompiledIsolateName, &isolate_snapshot_buffer); |
1455 } | 1368 } |
1456 | 1369 |
1457 // Initialize the Dart VM. | 1370 // Initialize the Dart VM. |
1458 char* error = Dart_Initialize( | 1371 char* error = Dart_Initialize( |
1459 vm_isolate_snapshot_buffer, instructions_snapshot, | 1372 vm_isolate_snapshot_buffer, instructions_snapshot, |
1460 CreateIsolateAndSetup, NULL, NULL, ShutdownIsolate, | 1373 CreateIsolateAndSetup, NULL, NULL, ShutdownIsolate, |
1461 DartUtils::OpenFile, | 1374 DartUtils::OpenFile, |
1462 DartUtils::ReadFile, | 1375 DartUtils::ReadFile, |
1463 DartUtils::WriteFile, | 1376 DartUtils::WriteFile, |
1464 DartUtils::CloseFile, | 1377 DartUtils::CloseFile, |
1465 DartUtils::EntropySource, | 1378 DartUtils::EntropySource, |
1466 GetVMServiceAssetsArchiveCallback); | 1379 GetVMServiceAssetsArchiveCallback); |
1467 if (error != NULL) { | 1380 if (error != NULL) { |
1468 if (do_vm_shutdown) { | 1381 if (do_vm_shutdown) { |
1469 DebuggerConnectionHandler::StopHandler(); | |
1470 EventHandler::Stop(); | 1382 EventHandler::Stop(); |
1471 } | 1383 } |
1472 fprintf(stderr, "VM initialization failed: %s\n", error); | 1384 fprintf(stderr, "VM initialization failed: %s\n", error); |
1473 fflush(stderr); | 1385 fflush(stderr); |
1474 free(error); | 1386 free(error); |
1475 Platform::Exit(kErrorExitCode); | 1387 Platform::Exit(kErrorExitCode); |
1476 } | 1388 } |
1477 | 1389 |
1478 Dart_RegisterIsolateServiceRequestCallback( | 1390 Dart_RegisterIsolateServiceRequestCallback( |
1479 "getIO", &ServiceGetIOHandler, NULL); | 1391 "getIO", &ServiceGetIOHandler, NULL); |
1480 Dart_SetServiceStreamCallbacks(&ServiceStreamListenCallback, | 1392 Dart_SetServiceStreamCallbacks(&ServiceStreamListenCallback, |
1481 &ServiceStreamCancelCallback); | 1393 &ServiceStreamCancelCallback); |
1482 | 1394 |
1483 // Run the main isolate until we aren't told to restart. | 1395 // Run the main isolate until we aren't told to restart. |
1484 while (RunMainIsolate(script_name, &dart_options)) { | 1396 while (RunMainIsolate(script_name, &dart_options)) { |
1485 Log::PrintErr("Restarting VM\n"); | 1397 Log::PrintErr("Restarting VM\n"); |
1486 } | 1398 } |
1487 | 1399 |
1488 // Terminate process exit-code handler. | 1400 // Terminate process exit-code handler. |
1489 Process::TerminateExitCodeHandler(); | 1401 Process::TerminateExitCodeHandler(); |
1490 | 1402 |
1491 error = Dart_Cleanup(); | 1403 error = Dart_Cleanup(); |
1492 if (error != NULL) { | 1404 if (error != NULL) { |
1493 Log::PrintErr("VM cleanup failed: %s\n", error); | 1405 Log::PrintErr("VM cleanup failed: %s\n", error); |
1494 free(error); | 1406 free(error); |
1495 } | 1407 } |
1496 if (do_vm_shutdown) { | 1408 if (do_vm_shutdown) { |
1497 DebuggerConnectionHandler::StopHandler(); | |
1498 EventHandler::Stop(); | 1409 EventHandler::Stop(); |
1499 } | 1410 } |
1500 | 1411 |
1501 // Free copied argument strings if converted. | 1412 // Free copied argument strings if converted. |
1502 if (argv_converted) { | 1413 if (argv_converted) { |
1503 for (int i = 0; i < argc; i++) free(argv[i]); | 1414 for (int i = 0; i < argc; i++) free(argv[i]); |
1504 } | 1415 } |
1505 | 1416 |
1506 // Free environment if any. | 1417 // Free environment if any. |
1507 if (environment != NULL) { | 1418 if (environment != NULL) { |
1508 for (HashMap::Entry* p = environment->Start(); | 1419 for (HashMap::Entry* p = environment->Start(); |
1509 p != NULL; | 1420 p != NULL; |
1510 p = environment->Next(p)) { | 1421 p = environment->Next(p)) { |
1511 free(p->key); | 1422 free(p->key); |
1512 free(p->value); | 1423 free(p->value); |
1513 } | 1424 } |
1514 delete environment; | 1425 delete environment; |
1515 } | 1426 } |
1516 | 1427 |
1517 Platform::Exit(Process::GlobalExitCode()); | 1428 Platform::Exit(Process::GlobalExitCode()); |
1518 } | 1429 } |
1519 | 1430 |
1520 } // namespace bin | 1431 } // namespace bin |
1521 } // namespace dart | 1432 } // namespace dart |
1522 | 1433 |
1523 int main(int argc, char** argv) { | 1434 int main(int argc, char** argv) { |
1524 dart::bin::main(argc, argv); | 1435 dart::bin::main(argc, argv); |
1525 UNREACHABLE(); | 1436 UNREACHABLE(); |
1526 } | 1437 } |
OLD | NEW |