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" |
| (...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 224 } | 224 } |
| 225 return false; | 225 return false; |
| 226 } | 226 } |
| 227 | 227 |
| 228 | 228 |
| 229 static void WriteToPerfEventsFile(const char* buffer, int64_t num_bytes) { | 229 static void WriteToPerfEventsFile(const char* buffer, int64_t num_bytes) { |
| 230 ASSERT(perf_events_symbols_file != NULL); | 230 ASSERT(perf_events_symbols_file != NULL); |
| 231 perf_events_symbols_file->WriteFully(buffer, num_bytes); | 231 perf_events_symbols_file->WriteFully(buffer, num_bytes); |
| 232 } | 232 } |
| 233 | 233 |
| 234 static bool Utf8ConvertArgv(int argc, char** argv) { | |
| 235 // Convert all the arguments to UTF8. On Windows, the arguments are | |
| 236 // encoded in the current code page and not UTF8. | |
|
Søren Gjesse
2012/11/13 12:48:45
Document return value.
Mads Ager (google)
2012/11/13 14:50:17
Done.
| |
| 237 bool result = false; | |
| 238 for (int i = 0; i < argc; i++) { | |
| 239 char* arg = argv[i]; | |
| 240 argv[i] = StringUtils::SystemStringToUtf8(arg); | |
| 241 if (argv[i] != arg) result = true; | |
|
Søren Gjesse
2012/11/13 12:48:45
Maybe change this to
if (argv == 0) {
result =
Mads Ager (google)
2012/11/13 14:50:17
Done.
| |
| 242 } | |
| 243 return result; | |
| 244 } | |
| 245 | |
| 234 | 246 |
| 235 // Parse out the command line arguments. Returns -1 if the arguments | 247 // Parse out the command line arguments. Returns -1 if the arguments |
| 236 // are incorrect, 0 otherwise. | 248 // are incorrect, 0 otherwise. |
| 237 static int ParseArguments(int argc, | 249 static int ParseArguments(int argc, |
| 238 char** argv, | 250 char** argv, |
| 239 CommandLineOptions* vm_options, | 251 CommandLineOptions* vm_options, |
| 240 char** executable_name, | 252 char** executable_name, |
| 241 char** script_name, | 253 char** script_name, |
| 242 CommandLineOptions* dart_options, | 254 CommandLineOptions* dart_options, |
| 243 bool* print_flags_seen) { | 255 bool* print_flags_seen) { |
| (...skipping 386 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 630 char* script_name; | 642 char* script_name; |
| 631 CommandLineOptions vm_options(argc); | 643 CommandLineOptions vm_options(argc); |
| 632 CommandLineOptions dart_options(argc); | 644 CommandLineOptions dart_options(argc); |
| 633 bool print_flags_seen = false; | 645 bool print_flags_seen = false; |
| 634 | 646 |
| 635 // Perform platform specific initialization. | 647 // Perform platform specific initialization. |
| 636 if (!Platform::Initialize()) { | 648 if (!Platform::Initialize()) { |
| 637 fprintf(stderr, "Initialization failed\n"); | 649 fprintf(stderr, "Initialization failed\n"); |
| 638 } | 650 } |
| 639 | 651 |
| 652 // On Windows, the argv strings are code page incoded and not | |
|
Søren Gjesse
2012/11/13 12:48:45
incoded -> encoded
Mads Ager (google)
2012/11/13 14:50:17
Done.
| |
| 653 // utf8. We need to convert them to utf8. | |
| 654 bool argv_converted = Utf8ConvertArgv(argc, argv); | |
| 655 | |
| 640 // Parse command line arguments. | 656 // Parse command line arguments. |
| 641 if (ParseArguments(argc, | 657 if (ParseArguments(argc, |
| 642 argv, | 658 argv, |
| 643 &vm_options, | 659 &vm_options, |
| 644 &executable_name, | 660 &executable_name, |
| 645 &script_name, | 661 &script_name, |
| 646 &dart_options, | 662 &dart_options, |
| 647 &print_flags_seen) < 0) { | 663 &print_flags_seen) < 0) { |
| 648 if (has_help_option) { | 664 if (has_help_option) { |
| 649 PrintUsage(); | 665 PrintUsage(); |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 717 Dart_Handle library = Dart_RootLibrary(); | 733 Dart_Handle library = Dart_RootLibrary(); |
| 718 if (Dart_IsNull(library)) { | 734 if (Dart_IsNull(library)) { |
| 719 return ErrorExit("Unable to find root library for '%s'\n", | 735 return ErrorExit("Unable to find root library for '%s'\n", |
| 720 script_name); | 736 script_name); |
| 721 } | 737 } |
| 722 // Set debug breakpoint if specified on the command line. | 738 // Set debug breakpoint if specified on the command line. |
| 723 if (breakpoint_at != NULL) { | 739 if (breakpoint_at != NULL) { |
| 724 result = SetBreakpoint(breakpoint_at, library); | 740 result = SetBreakpoint(breakpoint_at, library); |
| 725 if (Dart_IsError(result)) { | 741 if (Dart_IsError(result)) { |
| 726 return ErrorExit("Error setting breakpoint at '%s': %s\n", | 742 return ErrorExit("Error setting breakpoint at '%s': %s\n", |
| 727 breakpoint_at, | 743 breakpoint_at, |
| 728 Dart_GetError(result)); | 744 Dart_GetError(result)); |
| 729 } | 745 } |
| 730 } | 746 } |
| 731 | 747 |
| 732 // Lookup and invoke the top level main function. | 748 // Lookup and invoke the top level main function. |
| 733 result = Dart_Invoke(library, DartUtils::NewString("main"), 0, NULL); | 749 result = Dart_Invoke(library, DartUtils::NewString("main"), 0, NULL); |
| 734 if (Dart_IsError(result)) { | 750 if (Dart_IsError(result)) { |
| 735 return ErrorExit("%s\n", Dart_GetError(result)); | 751 return ErrorExit("%s\n", Dart_GetError(result)); |
| 736 } | 752 } |
| 737 // Keep handling messages until the last active receive port is closed. | 753 // Keep handling messages until the last active receive port is closed. |
| 738 result = Dart_RunLoop(); | 754 result = Dart_RunLoop(); |
| 739 if (Dart_IsError(result)) { | 755 if (Dart_IsError(result)) { |
| 740 return ErrorExit("%s\n", Dart_GetError(result)); | 756 return ErrorExit("%s\n", Dart_GetError(result)); |
| 741 } | 757 } |
| 742 | 758 |
| 743 Dart_ExitScope(); | 759 Dart_ExitScope(); |
| 744 // Dump symbol information for the profiler. | 760 // Dump symbol information for the profiler. |
| 745 DumpPprofSymbolInfo(); | 761 DumpPprofSymbolInfo(); |
| 746 // Shutdown the isolate. | 762 // Shutdown the isolate. |
| 747 Dart_ShutdownIsolate(); | 763 Dart_ShutdownIsolate(); |
| 748 // Terminate process exit-code handler. | 764 // Terminate process exit-code handler. |
| 749 Process::TerminateExitCodeHandler(); | 765 Process::TerminateExitCodeHandler(); |
| 766 // Free copied argument strings if converted. | |
| 767 if (argv_converted) { | |
| 768 for (int i = 0; i < argc; i++) free(argv[i]); | |
| 769 } | |
| 750 | 770 |
| 751 return 0; | 771 return 0; |
| 752 } | 772 } |
| OLD | NEW |