| 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" |
| 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" | 14 #include "bin/dbg_connection.h" |
| 15 #include "bin/directory.h" | 15 #include "bin/directory.h" |
| 16 #include "bin/eventhandler.h" | 16 #include "bin/eventhandler.h" |
| 17 #include "bin/extensions.h" | 17 #include "bin/extensions.h" |
| 18 #include "bin/file.h" | 18 #include "bin/file.h" |
| 19 #include "bin/isolate_data.h" | 19 #include "bin/isolate_data.h" |
| 20 #include "bin/log.h" | 20 #include "bin/log.h" |
| 21 #include "bin/platform.h" | 21 #include "bin/platform.h" |
| 22 #include "bin/process.h" | 22 #include "bin/process.h" |
| 23 #include "bin/vmservice_impl.h" |
| 23 #include "platform/globals.h" | 24 #include "platform/globals.h" |
| 24 | 25 |
| 25 namespace dart { | 26 namespace dart { |
| 26 namespace bin { | 27 namespace bin { |
| 27 | 28 |
| 28 // snapshot_buffer points to a snapshot if we link in a snapshot otherwise | 29 // snapshot_buffer points to a snapshot if we link in a snapshot otherwise |
| 29 // it is initialized to NULL. | 30 // it is initialized to NULL. |
| 30 extern const uint8_t* snapshot_buffer; | 31 extern const uint8_t* snapshot_buffer; |
| 31 | 32 |
| 32 // Global state that stores a pointer to the application script snapshot. | 33 // Global state that stores a pointer to the application script snapshot. |
| (...skipping 26 matching lines...) Expand all Loading... |
| 59 static bool has_compile_all = false; | 60 static bool has_compile_all = false; |
| 60 // Global flag that is used to indicate that we want to check function | 61 // Global flag that is used to indicate that we want to check function |
| 61 // fingerprints. | 62 // fingerprints. |
| 62 static bool has_check_function_fingerprints = false; | 63 static bool has_check_function_fingerprints = false; |
| 63 | 64 |
| 64 // Global flag that is used to indicate that we want to print the source code | 65 // Global flag that is used to indicate that we want to print the source code |
| 65 // for script that is being run. | 66 // for script that is being run. |
| 66 static bool has_print_script = false; | 67 static bool has_print_script = false; |
| 67 | 68 |
| 68 | 69 |
| 70 // VM Service options. |
| 71 static bool start_vm_service = false; |
| 72 static int vm_service_server_port = -1; |
| 73 static const int DEFAULT_VM_SERVICE_SERVER_PORT = 8181; |
| 74 |
| 75 |
| 69 static bool IsValidFlag(const char* name, | 76 static bool IsValidFlag(const char* name, |
| 70 const char* prefix, | 77 const char* prefix, |
| 71 intptr_t prefix_length) { | 78 intptr_t prefix_length) { |
| 72 intptr_t name_length = strlen(name); | 79 intptr_t name_length = strlen(name); |
| 73 return ((name_length > prefix_length) && | 80 return ((name_length > prefix_length) && |
| 74 (strncmp(name, prefix, prefix_length) == 0)); | 81 (strncmp(name, prefix, prefix_length) == 0)); |
| 75 } | 82 } |
| 76 | 83 |
| 77 | 84 |
| 78 static bool has_version_option = false; | 85 static bool has_version_option = false; |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 192 filename); | 199 filename); |
| 193 return false; | 200 return false; |
| 194 } | 201 } |
| 195 generate_script_snapshot = true; | 202 generate_script_snapshot = true; |
| 196 return true; | 203 return true; |
| 197 } | 204 } |
| 198 return false; | 205 return false; |
| 199 } | 206 } |
| 200 | 207 |
| 201 | 208 |
| 209 static bool ProcessEnableVmServiceOption(const char* port) { |
| 210 ASSERT(port != NULL); |
| 211 vm_service_server_port = -1; |
| 212 if (*port == '\0') { |
| 213 vm_service_server_port = DEFAULT_VM_SERVICE_SERVER_PORT; |
| 214 } else { |
| 215 if ((*port == '=') || (*port == ':')) { |
| 216 vm_service_server_port = atoi(port + 1); |
| 217 } |
| 218 } |
| 219 if (vm_service_server_port < 0) { |
| 220 Log::PrintErr("unrecognized --enable-vm-service option syntax. " |
| 221 "Use --enable-vm-service[:<port number>]\n"); |
| 222 return false; |
| 223 } |
| 224 start_vm_service = true; |
| 225 return true; |
| 226 } |
| 227 |
| 202 static struct { | 228 static struct { |
| 203 const char* option_name; | 229 const char* option_name; |
| 204 bool (*process)(const char* option); | 230 bool (*process)(const char* option); |
| 205 } main_options[] = { | 231 } main_options[] = { |
| 206 // Standard options shared with dart2js. | 232 // Standard options shared with dart2js. |
| 207 { "--version", ProcessVersionOption }, | 233 { "--version", ProcessVersionOption }, |
| 208 { "--help", ProcessHelpOption }, | 234 { "--help", ProcessHelpOption }, |
| 209 { "-h", ProcessHelpOption }, | 235 { "-h", ProcessHelpOption }, |
| 210 { "--verbose", ProcessVerboseOption }, | 236 { "--verbose", ProcessVerboseOption }, |
| 211 { "-v", ProcessVerboseOption }, | 237 { "-v", ProcessVerboseOption }, |
| 212 { "--package-root=", ProcessPackageRootOption }, | 238 { "--package-root=", ProcessPackageRootOption }, |
| 213 // VM specific options to the standalone dart program. | 239 // VM specific options to the standalone dart program. |
| 214 { "--break-at=", ProcessBreakpointOption }, | 240 { "--break-at=", ProcessBreakpointOption }, |
| 215 { "--compile_all", ProcessCompileAllOption }, | 241 { "--compile_all", ProcessCompileAllOption }, |
| 216 { "--debug", ProcessDebugOption }, | 242 { "--debug", ProcessDebugOption }, |
| 217 { "--snapshot=", ProcessGenScriptSnapshotOption }, | 243 { "--snapshot=", ProcessGenScriptSnapshotOption }, |
| 218 { "--print-script", ProcessPrintScriptOption }, | 244 { "--print-script", ProcessPrintScriptOption }, |
| 219 { "--check-function-fingerprints", ProcessFingerprintedFunctions }, | 245 { "--check-function-fingerprints", ProcessFingerprintedFunctions }, |
| 246 { "--enable-vm-service", ProcessEnableVmServiceOption }, |
| 220 { NULL, NULL } | 247 { NULL, NULL } |
| 221 }; | 248 }; |
| 222 | 249 |
| 223 | 250 |
| 224 static bool ProcessMainOptions(const char* option) { | 251 static bool ProcessMainOptions(const char* option) { |
| 225 int i = 0; | 252 int i = 0; |
| 226 const char* name = main_options[0].option_name; | 253 const char* name = main_options[0].option_name; |
| 227 int option_length = strlen(option); | 254 int option_length = strlen(option); |
| 228 while (name != NULL) { | 255 while (name != NULL) { |
| 229 int length = strlen(name); | 256 int length = strlen(name); |
| (...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 542 " 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" |
| 543 " url:<line_num> e.g. test.dart:10\n" | 570 " url:<line_num> e.g. test.dart:10\n" |
| 544 " [<class_name>.]<function_name> e.g. B.foo\n" | 571 " [<class_name>.]<function_name> e.g. B.foo\n" |
| 545 "\n" | 572 "\n" |
| 546 "--snapshot=<file_name>\n" | 573 "--snapshot=<file_name>\n" |
| 547 " 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" |
| 548 "\n" | 575 "\n" |
| 549 "--print-script\n" | 576 "--print-script\n" |
| 550 " 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" |
| 551 "\n" | 578 "\n" |
| 579 "--enable-vm-service[:<port number>]\n" |
| 580 " enables the VM service and listens on specified port for connections\n" |
| 581 " (default port number is 8181)\n" |
| 582 "\n" |
| 552 "The following options are only used for VM development and may\n" | 583 "The following options are only used for VM development and may\n" |
| 553 "be changed in any future version:\n"); | 584 "be changed in any future version:\n"); |
| 554 const char* print_flags = "--print_flags"; | 585 const char* print_flags = "--print_flags"; |
| 555 Dart_SetVMFlags(1, &print_flags); | 586 Dart_SetVMFlags(1, &print_flags); |
| 556 } | 587 } |
| 557 } | 588 } |
| 558 | 589 |
| 559 | 590 |
| 560 static Dart_Handle SetBreakpoint(const char* breakpoint_at, | 591 static Dart_Handle SetBreakpoint(const char* breakpoint_at, |
| 561 Dart_Handle library) { | 592 Dart_Handle library) { |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 713 // Start the debugger wire protocol handler if necessary. | 744 // Start the debugger wire protocol handler if necessary. |
| 714 if (start_debugger) { | 745 if (start_debugger) { |
| 715 ASSERT(debug_port >= 0); | 746 ASSERT(debug_port >= 0); |
| 716 bool print_msg = verbose_debug_seen || (debug_port == 0); | 747 bool print_msg = verbose_debug_seen || (debug_port == 0); |
| 717 debug_port = DebuggerConnectionHandler::StartHandler(debug_ip, debug_port); | 748 debug_port = DebuggerConnectionHandler::StartHandler(debug_ip, debug_port); |
| 718 if (print_msg) { | 749 if (print_msg) { |
| 719 Log::Print("Debugger listening on port %d\n", debug_port); | 750 Log::Print("Debugger listening on port %d\n", debug_port); |
| 720 } | 751 } |
| 721 } | 752 } |
| 722 | 753 |
| 754 // Start the VM service isolate, if necessary. |
| 755 if (start_vm_service) { |
| 756 ASSERT(vm_service_server_port >= 0); |
| 757 bool r = VmService::Start(vm_service_server_port); |
| 758 if (!r) { |
| 759 Log::PrintErr("Could not start VM Service isolate %s", |
| 760 VmService::GetErrorMessage()); |
| 761 } |
| 762 } |
| 763 |
| 723 // Call CreateIsolateAndSetup which creates an isolate and loads up | 764 // Call CreateIsolateAndSetup which creates an isolate and loads up |
| 724 // the specified application script. | 765 // the specified application script. |
| 725 char* error = NULL; | 766 char* error = NULL; |
| 726 char* isolate_name = BuildIsolateName(script_name, "main"); | 767 char* isolate_name = BuildIsolateName(script_name, "main"); |
| 727 Dart_Isolate isolate = CreateIsolateAndSetupHelper(script_name, | 768 Dart_Isolate isolate = CreateIsolateAndSetupHelper(script_name, |
| 728 "main", | 769 "main", |
| 729 new IsolateData(), | 770 new IsolateData(), |
| 730 &error); | 771 &error); |
| 731 if (isolate == NULL) { | 772 if (isolate == NULL) { |
| 732 Log::PrintErr("%s\n", error); | 773 Log::PrintErr("%s\n", error); |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 831 | 872 |
| 832 return Process::GlobalExitCode(); | 873 return Process::GlobalExitCode(); |
| 833 } | 874 } |
| 834 | 875 |
| 835 } // namespace bin | 876 } // namespace bin |
| 836 } // namespace dart | 877 } // namespace dart |
| 837 | 878 |
| 838 int main(int argc, char** argv) { | 879 int main(int argc, char** argv) { |
| 839 return dart::bin::main(argc, argv); | 880 return dart::bin::main(argc, argv); |
| 840 } | 881 } |
| OLD | NEW |