| 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/platform.h" | 21 #include "bin/platform.h" |
| 21 #include "bin/process.h" | 22 #include "bin/process.h" |
| 22 #include "platform/globals.h" | 23 #include "platform/globals.h" |
| 23 | 24 |
| 24 // snapshot_buffer points to a snapshot if we link in a snapshot otherwise | 25 // snapshot_buffer points to a snapshot if we link in a snapshot otherwise |
| 25 // it is initialized to NULL. | 26 // it is initialized to NULL. |
| 26 extern const uint8_t* snapshot_buffer; | 27 extern const uint8_t* snapshot_buffer; |
| 27 | 28 |
| 28 | 29 |
| 29 // Global state that indicates whether perf_events symbol information | 30 // Global state that indicates whether perf_events symbol information |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 135 ASSERT(port != NULL); | 136 ASSERT(port != NULL); |
| 136 debug_port = 0; | 137 debug_port = 0; |
| 137 if (*port == '\0') { | 138 if (*port == '\0') { |
| 138 debug_port = DEFAULT_DEBUG_PORT; | 139 debug_port = DEFAULT_DEBUG_PORT; |
| 139 } else { | 140 } else { |
| 140 if ((*port == '=') || (*port == ':')) { | 141 if ((*port == '=') || (*port == ':')) { |
| 141 debug_port = atoi(port + 1); | 142 debug_port = atoi(port + 1); |
| 142 } | 143 } |
| 143 } | 144 } |
| 144 if (debug_port == 0) { | 145 if (debug_port == 0) { |
| 145 fprintf(stderr, "unrecognized --debug option syntax. " | 146 Log::PrintErr("unrecognized --debug option syntax. " |
| 146 "Use --debug[:<port number>]\n"); | 147 "Use --debug[:<port number>]\n"); |
| 147 return false; | 148 return false; |
| 148 } | 149 } |
| 149 breakpoint_at = "main"; | 150 breakpoint_at = "main"; |
| 150 start_debugger = true; | 151 start_debugger = true; |
| 151 return true; | 152 return true; |
| 152 } | 153 } |
| 153 | 154 |
| 154 | 155 |
| 155 static bool ProcessPerfEventsOption(const char* option) { | 156 static bool ProcessPerfEventsOption(const char* option) { |
| (...skipping 353 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 509 const char* main, | 510 const char* main, |
| 510 void* data, char** error) { | 511 void* data, char** error) { |
| 511 return CreateIsolateAndSetupHelper(script_uri, | 512 return CreateIsolateAndSetupHelper(script_uri, |
| 512 main, | 513 main, |
| 513 new IsolateData(), | 514 new IsolateData(), |
| 514 error); | 515 error); |
| 515 } | 516 } |
| 516 | 517 |
| 517 | 518 |
| 518 static void PrintVersion() { | 519 static void PrintVersion() { |
| 519 fprintf(stderr, "Dart VM version: %s\n", Dart_VersionString()); | 520 Log::PrintErr("Dart VM version: %s\n", Dart_VersionString()); |
| 520 } | 521 } |
| 521 | 522 |
| 522 | 523 |
| 523 static void PrintUsage() { | 524 static void PrintUsage() { |
| 524 fprintf(stderr, | 525 Log::PrintErr( |
| 525 "Usage: dart [<vm-flags>] <dart-script-file> [<dart-options>]\n" | 526 "Usage: dart [<vm-flags>] <dart-script-file> [<dart-options>]\n" |
| 526 "\n" | 527 "\n" |
| 527 "Executes the Dart script passed as <dart-script-file>.\n" | 528 "Executes the Dart script passed as <dart-script-file>.\n" |
| 528 "\n"); | 529 "\n"); |
| 529 if (!has_verbose_option) { | 530 if (!has_verbose_option) { |
| 530 fprintf(stderr, | 531 Log::PrintErr( |
| 531 "Common options:\n" | 532 "Common options:\n" |
| 532 "--checked Insert runtime type checks and enable assertions (checked mode).\n" | 533 "--checked Insert runtime type checks and enable assertions (checked mode).\n" |
| 533 "--version Print the VM version.\n" | 534 "--version Print the VM version.\n" |
| 534 "--help Display this message (add --verbose for information about all\n" | 535 "--help Display this message (add --verbose for information about all\n" |
| 535 " VM options).\n"); | 536 " VM options).\n"); |
| 536 } else { | 537 } else { |
| 537 fprintf(stderr, | 538 Log::PrintErr( |
| 538 "Supported options:\n" | 539 "Supported options:\n" |
| 539 "--checked\n" | 540 "--checked\n" |
| 540 " Insert runtime type checks and enable assertions (checked mode).\n" | 541 " Insert runtime type checks and enable assertions (checked mode).\n" |
| 541 "\n" | 542 "\n" |
| 542 "--version\n" | 543 "--version\n" |
| 543 " Print the VM version.\n" | 544 " Print the VM version.\n" |
| 544 "\n" | 545 "\n" |
| 545 "--help\n" | 546 "--help\n" |
| 546 " Display this message (add --verbose for information about all VM options).\n" | 547 " Display this message (add --verbose for information about all VM options).\n" |
| 547 "\n" | 548 "\n" |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 619 return buffer; | 620 return buffer; |
| 620 } | 621 } |
| 621 | 622 |
| 622 | 623 |
| 623 static const int kErrorExitCode = 255; // Indicates we encountered an error. | 624 static const int kErrorExitCode = 255; // Indicates we encountered an error. |
| 624 | 625 |
| 625 | 626 |
| 626 static int ErrorExit(const char* format, ...) { | 627 static int ErrorExit(const char* format, ...) { |
| 627 va_list arguments; | 628 va_list arguments; |
| 628 va_start(arguments, format); | 629 va_start(arguments, format); |
| 629 vfprintf(stderr, format, arguments); | 630 Log::VPrintErr(format, arguments); |
| 630 va_end(arguments); | 631 va_end(arguments); |
| 631 | 632 |
| 632 Dart_ExitScope(); | 633 Dart_ExitScope(); |
| 633 Dart_ShutdownIsolate(); | 634 Dart_ShutdownIsolate(); |
| 634 | 635 |
| 635 return kErrorExitCode; | 636 return kErrorExitCode; |
| 636 } | 637 } |
| 637 | 638 |
| 638 | 639 |
| 639 static void ShutdownIsolate(void* callback_data) { | 640 static void ShutdownIsolate(void* callback_data) { |
| 640 IsolateData* isolate_data = reinterpret_cast<IsolateData*>(callback_data); | 641 IsolateData* isolate_data = reinterpret_cast<IsolateData*>(callback_data); |
| 641 EventHandler* handler = isolate_data->event_handler; | 642 EventHandler* handler = isolate_data->event_handler; |
| 642 if (handler != NULL) handler->Shutdown(); | 643 if (handler != NULL) handler->Shutdown(); |
| 643 delete isolate_data; | 644 delete isolate_data; |
| 644 } | 645 } |
| 645 | 646 |
| 646 | 647 |
| 647 int main(int argc, char** argv) { | 648 int main(int argc, char** argv) { |
| 648 char* executable_name; | 649 char* executable_name; |
| 649 char* script_name; | 650 char* script_name; |
| 650 CommandLineOptions vm_options(argc); | 651 CommandLineOptions vm_options(argc); |
| 651 CommandLineOptions dart_options(argc); | 652 CommandLineOptions dart_options(argc); |
| 652 bool print_flags_seen = false; | 653 bool print_flags_seen = false; |
| 653 | 654 |
| 654 // Perform platform specific initialization. | 655 // Perform platform specific initialization. |
| 655 if (!Platform::Initialize()) { | 656 if (!Platform::Initialize()) { |
| 656 fprintf(stderr, "Initialization failed\n"); | 657 Log::PrintErr("Initialization failed\n"); |
| 657 } | 658 } |
| 658 | 659 |
| 659 // On Windows, the argv strings are code page encoded and not | 660 // On Windows, the argv strings are code page encoded and not |
| 660 // utf8. We need to convert them to utf8. | 661 // utf8. We need to convert them to utf8. |
| 661 bool argv_converted = Utf8ConvertArgv(argc, argv); | 662 bool argv_converted = Utf8ConvertArgv(argc, argv); |
| 662 | 663 |
| 663 // Parse command line arguments. | 664 // Parse command line arguments. |
| 664 if (ParseArguments(argc, | 665 if (ParseArguments(argc, |
| 665 argv, | 666 argv, |
| 666 &vm_options, | 667 &vm_options, |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 703 } | 704 } |
| 704 | 705 |
| 705 // Call CreateIsolateAndSetup which creates an isolate and loads up | 706 // Call CreateIsolateAndSetup which creates an isolate and loads up |
| 706 // the specified application script. | 707 // the specified application script. |
| 707 char* error = NULL; | 708 char* error = NULL; |
| 708 char* isolate_name = BuildIsolateName(script_name, "main"); | 709 char* isolate_name = BuildIsolateName(script_name, "main"); |
| 709 if (!CreateIsolateAndSetupHelper(script_name, | 710 if (!CreateIsolateAndSetupHelper(script_name, |
| 710 "main", | 711 "main", |
| 711 new IsolateData(), | 712 new IsolateData(), |
| 712 &error)) { | 713 &error)) { |
| 713 fprintf(stderr, "%s\n", error); | 714 Log::PrintErr("%s\n", error); |
| 714 free(error); | 715 free(error); |
| 715 delete [] isolate_name; | 716 delete [] isolate_name; |
| 716 return kErrorExitCode; // Indicates we encountered an error. | 717 return kErrorExitCode; // Indicates we encountered an error. |
| 717 } | 718 } |
| 718 delete [] isolate_name; | 719 delete [] isolate_name; |
| 719 | 720 |
| 720 Dart_Isolate isolate = Dart_CurrentIsolate(); | 721 Dart_Isolate isolate = Dart_CurrentIsolate(); |
| 721 ASSERT(isolate != NULL); | 722 ASSERT(isolate != NULL); |
| 722 Dart_Handle result; | 723 Dart_Handle result; |
| 723 | 724 |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 770 Dart_ShutdownIsolate(); | 771 Dart_ShutdownIsolate(); |
| 771 // Terminate process exit-code handler. | 772 // Terminate process exit-code handler. |
| 772 Process::TerminateExitCodeHandler(); | 773 Process::TerminateExitCodeHandler(); |
| 773 // Free copied argument strings if converted. | 774 // Free copied argument strings if converted. |
| 774 if (argv_converted) { | 775 if (argv_converted) { |
| 775 for (int i = 0; i < argc; i++) free(argv[i]); | 776 for (int i = 0; i < argc; i++) free(argv[i]); |
| 776 } | 777 } |
| 777 | 778 |
| 778 return 0; | 779 return 0; |
| 779 } | 780 } |
| OLD | NEW |