Chromium Code Reviews| 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 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 617 ASSERT(buffer != NULL); | 618 ASSERT(buffer != NULL); |
| 618 snprintf(buffer, len, kFormat, script_name, func_name); | 619 snprintf(buffer, len, kFormat, script_name, func_name); |
| 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, ...) { |
| 628 char buf[1024]; | |
|
Ivan Posva
2012/11/15 07:43:17
This will make lots of users very unhappy. As the
siva
2012/11/15 18:46:48
I agree, in fact we had a bug filed against us for
gram
2012/11/15 21:16:50
Done.
gram
2012/11/15 21:16:50
Done.
| |
| 627 va_list arguments; | 629 va_list arguments; |
| 628 va_start(arguments, format); | 630 va_start(arguments, format); |
| 629 vfprintf(stderr, format, arguments); | 631 vsnprintf(buf, sizeof(buf), format, arguments); |
|
Ivan Posva
2012/11/15 18:59:44
Why not use Log::VFPrint here?
gram
2012/11/15 21:16:50
Done.
| |
| 630 va_end(arguments); | 632 va_end(arguments); |
| 633 Log::PrintErr("%s", buf); | |
| 631 | 634 |
| 632 Dart_ExitScope(); | 635 Dart_ExitScope(); |
| 633 Dart_ShutdownIsolate(); | 636 Dart_ShutdownIsolate(); |
| 634 | 637 |
| 635 return kErrorExitCode; | 638 return kErrorExitCode; |
| 636 } | 639 } |
| 637 | 640 |
| 638 | 641 |
| 639 static void ShutdownIsolate(void* callback_data) { | 642 static void ShutdownIsolate(void* callback_data) { |
| 640 IsolateData* isolate_data = reinterpret_cast<IsolateData*>(callback_data); | 643 IsolateData* isolate_data = reinterpret_cast<IsolateData*>(callback_data); |
| 641 EventHandler* handler = isolate_data->event_handler; | 644 EventHandler* handler = isolate_data->event_handler; |
| 642 if (handler != NULL) handler->Shutdown(); | 645 if (handler != NULL) handler->Shutdown(); |
| 643 delete isolate_data; | 646 delete isolate_data; |
| 644 } | 647 } |
| 645 | 648 |
| 646 | 649 |
| 647 int main(int argc, char** argv) { | 650 int main(int argc, char** argv) { |
| 648 char* executable_name; | 651 char* executable_name; |
| 649 char* script_name; | 652 char* script_name; |
| 650 CommandLineOptions vm_options(argc); | 653 CommandLineOptions vm_options(argc); |
| 651 CommandLineOptions dart_options(argc); | 654 CommandLineOptions dart_options(argc); |
| 652 bool print_flags_seen = false; | 655 bool print_flags_seen = false; |
| 653 | 656 |
| 654 // Perform platform specific initialization. | 657 // Perform platform specific initialization. |
| 655 if (!Platform::Initialize()) { | 658 if (!Platform::Initialize()) { |
| 656 fprintf(stderr, "Initialization failed\n"); | 659 Log::PrintErr("Initialization failed\n"); |
| 657 } | 660 } |
| 658 | 661 |
| 659 // On Windows, the argv strings are code page encoded and not | 662 // On Windows, the argv strings are code page encoded and not |
| 660 // utf8. We need to convert them to utf8. | 663 // utf8. We need to convert them to utf8. |
| 661 bool argv_converted = Utf8ConvertArgv(argc, argv); | 664 bool argv_converted = Utf8ConvertArgv(argc, argv); |
| 662 | 665 |
| 663 // Parse command line arguments. | 666 // Parse command line arguments. |
| 664 if (ParseArguments(argc, | 667 if (ParseArguments(argc, |
| 665 argv, | 668 argv, |
| 666 &vm_options, | 669 &vm_options, |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 703 } | 706 } |
| 704 | 707 |
| 705 // Call CreateIsolateAndSetup which creates an isolate and loads up | 708 // Call CreateIsolateAndSetup which creates an isolate and loads up |
| 706 // the specified application script. | 709 // the specified application script. |
| 707 char* error = NULL; | 710 char* error = NULL; |
| 708 char* isolate_name = BuildIsolateName(script_name, "main"); | 711 char* isolate_name = BuildIsolateName(script_name, "main"); |
| 709 if (!CreateIsolateAndSetupHelper(script_name, | 712 if (!CreateIsolateAndSetupHelper(script_name, |
| 710 "main", | 713 "main", |
| 711 new IsolateData(), | 714 new IsolateData(), |
| 712 &error)) { | 715 &error)) { |
| 713 fprintf(stderr, "%s\n", error); | 716 Log::PrintErr("%s\n", error); |
| 714 free(error); | 717 free(error); |
| 715 delete [] isolate_name; | 718 delete [] isolate_name; |
| 716 return kErrorExitCode; // Indicates we encountered an error. | 719 return kErrorExitCode; // Indicates we encountered an error. |
| 717 } | 720 } |
| 718 delete [] isolate_name; | 721 delete [] isolate_name; |
| 719 | 722 |
| 720 Dart_Isolate isolate = Dart_CurrentIsolate(); | 723 Dart_Isolate isolate = Dart_CurrentIsolate(); |
| 721 ASSERT(isolate != NULL); | 724 ASSERT(isolate != NULL); |
| 722 Dart_Handle result; | 725 Dart_Handle result; |
| 723 | 726 |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 770 Dart_ShutdownIsolate(); | 773 Dart_ShutdownIsolate(); |
| 771 // Terminate process exit-code handler. | 774 // Terminate process exit-code handler. |
| 772 Process::TerminateExitCodeHandler(); | 775 Process::TerminateExitCodeHandler(); |
| 773 // Free copied argument strings if converted. | 776 // Free copied argument strings if converted. |
| 774 if (argv_converted) { | 777 if (argv_converted) { |
| 775 for (int i = 0; i < argc; i++) free(argv[i]); | 778 for (int i = 0; i < argc; i++) free(argv[i]); |
| 776 } | 779 } |
| 777 | 780 |
| 778 return 0; | 781 return 0; |
| 779 } | 782 } |
| OLD | NEW |