| 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/vmstats.h" |
| 23 #include "platform/globals.h" | 24 #include "platform/globals.h" |
| 24 | 25 |
| 25 // snapshot_buffer points to a snapshot if we link in a snapshot otherwise | 26 // snapshot_buffer points to a snapshot if we link in a snapshot otherwise |
| 26 // it is initialized to NULL. | 27 // it is initialized to NULL. |
| 27 extern const uint8_t* snapshot_buffer; | 28 extern const uint8_t* snapshot_buffer; |
| 28 | 29 |
| 29 | 30 |
| 30 // Global state that stores a pointer to the application script snapshot. | 31 // Global state that stores a pointer to the application script snapshot. |
| 31 static bool use_script_snapshot = false; | 32 static bool use_script_snapshot = false; |
| 32 static bool generate_script_snapshot = false; | 33 static bool generate_script_snapshot = false; |
| 33 static File* snapshot_file = NULL; | 34 static File* snapshot_file = NULL; |
| 34 | 35 |
| 35 | 36 |
| 36 // Global state that indicates whether there is a debug breakpoint. | 37 // Global state that indicates whether there is a debug breakpoint. |
| 37 // This pointer points into an argv buffer and does not need to be | 38 // This pointer points into an argv buffer and does not need to be |
| 38 // free'd. | 39 // free'd. |
| 39 static const char* breakpoint_at = NULL; | 40 static const char* breakpoint_at = NULL; |
| 40 | 41 |
| 41 | 42 |
| 42 // Global state that indicates whether we should open a connection | 43 // Global state that indicates whether we should open a connection |
| 43 // and listen for a debugger to connect. | 44 // and listen for a debugger to connect. |
| 44 static bool start_debugger = false; | 45 static bool start_debugger = false; |
| 45 static const int DEFAULT_DEBUG_PORT = 5858; | 46 static const int DEFAULT_DEBUG_PORT = 5858; |
| 46 static const char* DEFAULT_DEBUG_IP = "127.0.0.1"; | 47 static const char* DEFAULT_DEBUG_IP = "127.0.0.1"; |
| 47 static const char* debug_ip = DEFAULT_DEBUG_IP; | 48 static const char* debug_ip = DEFAULT_DEBUG_IP; |
| 48 static int debug_port = 0; | 49 static int debug_port = 0; |
| 49 | 50 |
| 51 // Global state that defines the VmStats web server port. |
| 52 static int visual_vm_port = 0; |
| 50 | 53 |
| 51 // Value of the --package-root flag. | 54 // Value of the --package-root flag. |
| 52 // (This pointer points into an argv buffer and does not need to be | 55 // (This pointer points into an argv buffer and does not need to be |
| 53 // free'd.) | 56 // free'd.) |
| 54 static const char* package_root = NULL; | 57 static const char* package_root = NULL; |
| 55 | 58 |
| 56 | 59 |
| 57 // Global flag that is used to indicate that we want to compile all the | 60 // Global flag that is used to indicate that we want to compile all the |
| 58 // dart functions and not run anything. | 61 // dart functions and not run anything. |
| 59 static bool has_compile_all = false; | 62 static bool has_compile_all = false; |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 157 if (snapshot_file == NULL) { | 160 if (snapshot_file == NULL) { |
| 158 Log::PrintErr("Unable to open file %s for reading the snapshot\n", | 161 Log::PrintErr("Unable to open file %s for reading the snapshot\n", |
| 159 filename); | 162 filename); |
| 160 return false; | 163 return false; |
| 161 } | 164 } |
| 162 } | 165 } |
| 163 return true; | 166 return true; |
| 164 } | 167 } |
| 165 | 168 |
| 166 | 169 |
| 170 static bool ProcessVmStatsPortOption(const char* port) { |
| 171 ASSERT(port != NULL); |
| 172 if (*port == '\0') { |
| 173 visual_vm_port = 0; |
| 174 } else { |
| 175 visual_vm_port = atoi(port); |
| 176 } |
| 177 return true; |
| 178 } |
| 179 |
| 180 |
| 167 static bool ProcessGenScriptSnapshotOption(const char* filename) { | 181 static bool ProcessGenScriptSnapshotOption(const char* filename) { |
| 168 if (filename != NULL && strlen(filename) != 0) { | 182 if (filename != NULL && strlen(filename) != 0) { |
| 169 // Ensure that are already running using a full snapshot. | 183 // Ensure that are already running using a full snapshot. |
| 170 if (snapshot_buffer == NULL) { | 184 if (snapshot_buffer == NULL) { |
| 171 Log::PrintErr("Script snapshots cannot be generated in this version of" | 185 Log::PrintErr("Script snapshots cannot be generated in this version of" |
| 172 " dart\n"); | 186 " dart\n"); |
| 173 return false; | 187 return false; |
| 174 } | 188 } |
| 175 if (use_script_snapshot) { | 189 if (use_script_snapshot) { |
| 176 Log::PrintErr("Incompatible options specified --use-script-snapshot " | 190 Log::PrintErr("Incompatible options specified --use-script-snapshot " |
| (...skipping 23 matching lines...) Expand all Loading... |
| 200 { "--verbose", ProcessVerboseOption }, | 214 { "--verbose", ProcessVerboseOption }, |
| 201 { "-v", ProcessVerboseOption }, | 215 { "-v", ProcessVerboseOption }, |
| 202 { "--package-root=", ProcessPackageRootOption }, | 216 { "--package-root=", ProcessPackageRootOption }, |
| 203 { "-p", ProcessPackageRootOption }, | 217 { "-p", ProcessPackageRootOption }, |
| 204 // VM specific options to the standalone dart program. | 218 // VM specific options to the standalone dart program. |
| 205 { "--break_at=", ProcessBreakpointOption }, | 219 { "--break_at=", ProcessBreakpointOption }, |
| 206 { "--compile_all", ProcessCompileAllOption }, | 220 { "--compile_all", ProcessCompileAllOption }, |
| 207 { "--debug", ProcessDebugOption }, | 221 { "--debug", ProcessDebugOption }, |
| 208 { "--use-script-snapshot=", ProcessUseScriptSnapshotOption }, | 222 { "--use-script-snapshot=", ProcessUseScriptSnapshotOption }, |
| 209 { "--generate-script-snapshot=", ProcessGenScriptSnapshotOption }, | 223 { "--generate-script-snapshot=", ProcessGenScriptSnapshotOption }, |
| 224 { "--vmstats_port=", ProcessVmStatsPortOption }, |
| 210 { NULL, NULL } | 225 { NULL, NULL } |
| 211 }; | 226 }; |
| 212 | 227 |
| 213 | 228 |
| 214 static bool ProcessMainOptions(const char* option) { | 229 static bool ProcessMainOptions(const char* option) { |
| 215 int i = 0; | 230 int i = 0; |
| 216 const char* name = main_options[0].option_name; | 231 const char* name = main_options[0].option_name; |
| 217 while (name != NULL) { | 232 while (name != NULL) { |
| 218 int length = strlen(name); | 233 int length = strlen(name); |
| 219 if (strncmp(option, name, length) == 0) { | 234 if (strncmp(option, name, length) == 0) { |
| (...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 481 char errbuf[256]; | 496 char errbuf[256]; |
| 482 snprintf(errbuf, sizeof(errbuf), | 497 snprintf(errbuf, sizeof(errbuf), |
| 483 "Expected a library when loading script: %s", | 498 "Expected a library when loading script: %s", |
| 484 script_uri); | 499 script_uri); |
| 485 *error = strdup(errbuf); | 500 *error = strdup(errbuf); |
| 486 Dart_ExitScope(); | 501 Dart_ExitScope(); |
| 487 Dart_ShutdownIsolate(); | 502 Dart_ShutdownIsolate(); |
| 488 return false; | 503 return false; |
| 489 } | 504 } |
| 490 Dart_ExitScope(); | 505 Dart_ExitScope(); |
| 506 dart::VmStats::AddIsolate(reinterpret_cast<IsolateData*>(data), isolate); |
| 491 return true; | 507 return true; |
| 492 } | 508 } |
| 493 | 509 |
| 494 | 510 |
| 495 static bool CreateIsolateAndSetup(const char* script_uri, | 511 static bool CreateIsolateAndSetup(const char* script_uri, |
| 496 const char* main, | 512 const char* main, |
| 497 void* data, char** error) { | 513 void* data, char** error) { |
| 498 return CreateIsolateAndSetupHelper(script_uri, | 514 return CreateIsolateAndSetupHelper(script_uri, |
| 499 main, | 515 main, |
| 500 new IsolateData(), | 516 new IsolateData(), |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 620 | 636 |
| 621 Dart_ExitScope(); | 637 Dart_ExitScope(); |
| 622 Dart_ShutdownIsolate(); | 638 Dart_ShutdownIsolate(); |
| 623 | 639 |
| 624 return kErrorExitCode; | 640 return kErrorExitCode; |
| 625 } | 641 } |
| 626 | 642 |
| 627 | 643 |
| 628 static void ShutdownIsolate(void* callback_data) { | 644 static void ShutdownIsolate(void* callback_data) { |
| 629 IsolateData* isolate_data = reinterpret_cast<IsolateData*>(callback_data); | 645 IsolateData* isolate_data = reinterpret_cast<IsolateData*>(callback_data); |
| 646 dart::VmStats::RemoveIsolate(isolate_data); |
| 630 EventHandler* handler = isolate_data->event_handler; | 647 EventHandler* handler = isolate_data->event_handler; |
| 631 if (handler != NULL) handler->Shutdown(); | 648 if (handler != NULL) handler->Shutdown(); |
| 632 delete isolate_data; | 649 delete isolate_data; |
| 633 } | 650 } |
| 634 | 651 |
| 635 | 652 |
| 636 int main(int argc, char** argv) { | 653 int main(int argc, char** argv) { |
| 637 char* executable_name; | 654 char* executable_name; |
| 638 char* script_name; | 655 char* script_name; |
| 639 CommandLineOptions vm_options(argc); | 656 CommandLineOptions vm_options(argc); |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 706 return kErrorExitCode; // Indicates we encountered an error. | 723 return kErrorExitCode; // Indicates we encountered an error. |
| 707 } | 724 } |
| 708 delete [] isolate_name; | 725 delete [] isolate_name; |
| 709 | 726 |
| 710 Dart_Isolate isolate = Dart_CurrentIsolate(); | 727 Dart_Isolate isolate = Dart_CurrentIsolate(); |
| 711 ASSERT(isolate != NULL); | 728 ASSERT(isolate != NULL); |
| 712 Dart_Handle result; | 729 Dart_Handle result; |
| 713 | 730 |
| 714 Dart_EnterScope(); | 731 Dart_EnterScope(); |
| 715 | 732 |
| 733 if (visual_vm_port > 0) { |
| 734 dart::VmStats::Start(visual_vm_port); |
| 735 } |
| 736 |
| 716 if (generate_script_snapshot) { | 737 if (generate_script_snapshot) { |
| 717 // First create a snapshot. | 738 // First create a snapshot. |
| 718 Dart_Handle result; | 739 Dart_Handle result; |
| 719 uint8_t* buffer = NULL; | 740 uint8_t* buffer = NULL; |
| 720 intptr_t size = 0; | 741 intptr_t size = 0; |
| 721 result = Dart_CreateScriptSnapshot(&buffer, &size); | 742 result = Dart_CreateScriptSnapshot(&buffer, &size); |
| 722 if (Dart_IsError(result)) { | 743 if (Dart_IsError(result)) { |
| 723 Log::PrintErr("%s\n", Dart_GetError(result)); | 744 Log::PrintErr("%s\n", Dart_GetError(result)); |
| 724 Dart_ExitScope(); | 745 Dart_ExitScope(); |
| 725 Dart_ShutdownIsolate(); | 746 Dart_ShutdownIsolate(); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 766 return ErrorExit("%s\n", Dart_GetError(result)); | 787 return ErrorExit("%s\n", Dart_GetError(result)); |
| 767 } | 788 } |
| 768 // Keep handling messages until the last active receive port is closed. | 789 // Keep handling messages until the last active receive port is closed. |
| 769 result = Dart_RunLoop(); | 790 result = Dart_RunLoop(); |
| 770 if (Dart_IsError(result)) { | 791 if (Dart_IsError(result)) { |
| 771 return ErrorExit("%s\n", Dart_GetError(result)); | 792 return ErrorExit("%s\n", Dart_GetError(result)); |
| 772 } | 793 } |
| 773 } | 794 } |
| 774 | 795 |
| 775 Dart_ExitScope(); | 796 Dart_ExitScope(); |
| 797 dart::VmStats::Stop(); |
| 776 // Shutdown the isolate. | 798 // Shutdown the isolate. |
| 777 Dart_ShutdownIsolate(); | 799 Dart_ShutdownIsolate(); |
| 778 // Terminate process exit-code handler. | 800 // Terminate process exit-code handler. |
| 779 Process::TerminateExitCodeHandler(); | 801 Process::TerminateExitCodeHandler(); |
| 780 // Free copied argument strings if converted. | 802 // Free copied argument strings if converted. |
| 781 if (argv_converted) { | 803 if (argv_converted) { |
| 782 for (int i = 0; i < argc; i++) free(argv[i]); | 804 for (int i = 0; i < argc; i++) free(argv[i]); |
| 783 } | 805 } |
| 784 | 806 |
| 785 return Process::GlobalExitCode(); | 807 return Process::GlobalExitCode(); |
| 786 } | 808 } |
| OLD | NEW |