| 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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 42 // Global state that indicates whether we should open a connection | 42 // Global state that indicates whether we should open a connection |
| 43 // and listen for a debugger to connect. | 43 // and listen for a debugger to connect. |
| 44 static bool start_debugger = false; | 44 static bool start_debugger = false; |
| 45 static const int DEFAULT_DEBUG_PORT = 5858; | 45 static const int DEFAULT_DEBUG_PORT = 5858; |
| 46 static const char* DEFAULT_DEBUG_IP = "127.0.0.1"; | 46 static const char* DEFAULT_DEBUG_IP = "127.0.0.1"; |
| 47 static const char* debug_ip = DEFAULT_DEBUG_IP; | 47 static const char* debug_ip = DEFAULT_DEBUG_IP; |
| 48 static int debug_port = 0; | 48 static int debug_port = 0; |
| 49 | 49 |
| 50 // Global state that defines the VmStats web server port and root directory. | 50 // Global state that defines the VmStats web server port and root directory. |
| 51 static int vmstats_port = -1; | 51 static int vmstats_port = -1; |
| 52 static const char* vmstats_root = NULL; | 52 static const char* vmstats_root = ""; |
| 53 | 53 |
| 54 // Value of the --package-root flag. | 54 // Value of the --package-root flag. |
| 55 // (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 |
| 56 // free'd.) | 56 // free'd.) |
| 57 static const char* package_root = NULL; | 57 static const char* package_root = NULL; |
| 58 | 58 |
| 59 | 59 |
| 60 // 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 |
| 61 // dart functions and not run anything. | 61 // dart functions and not run anything. |
| 62 static bool has_compile_all = false; | 62 static bool has_compile_all = false; |
| (...skipping 663 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 726 DartUtils::SetOriginalWorkingDirectory(); | 726 DartUtils::SetOriginalWorkingDirectory(); |
| 727 | 727 |
| 728 // Start the debugger wire protocol handler if necessary. | 728 // Start the debugger wire protocol handler if necessary. |
| 729 if (start_debugger) { | 729 if (start_debugger) { |
| 730 ASSERT(debug_port != 0); | 730 ASSERT(debug_port != 0); |
| 731 DebuggerConnectionHandler::StartHandler(debug_ip, debug_port); | 731 DebuggerConnectionHandler::StartHandler(debug_ip, debug_port); |
| 732 if (verbose_debug_seen) { | 732 if (verbose_debug_seen) { |
| 733 Log::Print("Debugger initialized\n"); | 733 Log::Print("Debugger initialized\n"); |
| 734 } | 734 } |
| 735 } | 735 } |
| 736 VmStats::Start(vmstats_port, vmstats_root, verbose_debug_seen); |
| 736 | 737 |
| 737 // Call CreateIsolateAndSetup which creates an isolate and loads up | 738 // Call CreateIsolateAndSetup which creates an isolate and loads up |
| 738 // the specified application script. | 739 // the specified application script. |
| 739 char* error = NULL; | 740 char* error = NULL; |
| 740 char* isolate_name = BuildIsolateName(script_name, "main"); | 741 char* isolate_name = BuildIsolateName(script_name, "main"); |
| 741 Dart_Isolate isolate = CreateIsolateAndSetupHelper(script_name, | 742 Dart_Isolate isolate = CreateIsolateAndSetupHelper(script_name, |
| 742 "main", | 743 "main", |
| 743 new IsolateData(), | 744 new IsolateData(), |
| 744 &error); | 745 &error); |
| 745 if (isolate == NULL) { | 746 if (isolate == NULL) { |
| 746 Log::PrintErr("%s\n", error); | 747 Log::PrintErr("%s\n", error); |
| 747 free(error); | 748 free(error); |
| 748 delete [] isolate_name; | 749 delete [] isolate_name; |
| 749 return kErrorExitCode; // Indicates we encountered an error. | 750 return kErrorExitCode; // Indicates we encountered an error. |
| 750 } | 751 } |
| 751 delete [] isolate_name; | 752 delete [] isolate_name; |
| 752 | 753 |
| 753 Dart_EnterIsolate(isolate); | 754 Dart_EnterIsolate(isolate); |
| 754 ASSERT(isolate == Dart_CurrentIsolate()); | 755 ASSERT(isolate == Dart_CurrentIsolate()); |
| 755 ASSERT(isolate != NULL); | 756 ASSERT(isolate != NULL); |
| 756 Dart_Handle result; | 757 Dart_Handle result; |
| 757 | 758 |
| 758 Dart_EnterScope(); | 759 Dart_EnterScope(); |
| 759 | 760 |
| 760 if (vmstats_port >= 0) { | |
| 761 VmStats::Start(vmstats_port, vmstats_root); | |
| 762 } | |
| 763 | |
| 764 if (generate_script_snapshot) { | 761 if (generate_script_snapshot) { |
| 765 // First create a snapshot. | 762 // First create a snapshot. |
| 766 Dart_Handle result; | 763 Dart_Handle result; |
| 767 uint8_t* buffer = NULL; | 764 uint8_t* buffer = NULL; |
| 768 intptr_t size = 0; | 765 intptr_t size = 0; |
| 769 result = Dart_CreateScriptSnapshot(&buffer, &size); | 766 result = Dart_CreateScriptSnapshot(&buffer, &size); |
| 770 if (Dart_IsError(result)) { | 767 if (Dart_IsError(result)) { |
| 771 Log::PrintErr("%s\n", Dart_GetError(result)); | 768 Log::PrintErr("%s\n", Dart_GetError(result)); |
| 772 Dart_ExitScope(); | 769 Dart_ExitScope(); |
| 773 Dart_ShutdownIsolate(); | 770 Dart_ShutdownIsolate(); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 814 result = GenerateScriptSource(); | 811 result = GenerateScriptSource(); |
| 815 if (Dart_IsError(result)) { | 812 if (Dart_IsError(result)) { |
| 816 return ErrorExit("%s\n", Dart_GetError(result)); | 813 return ErrorExit("%s\n", Dart_GetError(result)); |
| 817 } | 814 } |
| 818 } else { | 815 } else { |
| 819 // Lookup and invoke the top level main function. | 816 // Lookup and invoke the top level main function. |
| 820 result = Dart_Invoke(library, DartUtils::NewString("main"), 0, NULL); | 817 result = Dart_Invoke(library, DartUtils::NewString("main"), 0, NULL); |
| 821 if (Dart_IsError(result)) { | 818 if (Dart_IsError(result)) { |
| 822 return ErrorExit("%s\n", Dart_GetError(result)); | 819 return ErrorExit("%s\n", Dart_GetError(result)); |
| 823 } | 820 } |
| 821 |
| 824 // Keep handling messages until the last active receive port is closed. | 822 // Keep handling messages until the last active receive port is closed. |
| 825 result = Dart_RunLoop(); | 823 result = Dart_RunLoop(); |
| 826 if (Dart_IsError(result)) { | 824 if (Dart_IsError(result)) { |
| 827 return ErrorExit("%s\n", Dart_GetError(result)); | 825 return ErrorExit("%s\n", Dart_GetError(result)); |
| 828 } | 826 } |
| 829 } | 827 } |
| 830 } | 828 } |
| 831 | 829 |
| 832 Dart_ExitScope(); | 830 Dart_ExitScope(); |
| 833 if (vmstats_port >= 0) { | 831 if (vmstats_port >= 0) { |
| 834 VmStats::Stop(); | 832 VmStats::Stop(); |
| 835 } | 833 } |
| 836 // Shutdown the isolate. | 834 // Shutdown the isolate. |
| 837 Dart_ShutdownIsolate(); | 835 Dart_ShutdownIsolate(); |
| 838 // Terminate process exit-code handler. | 836 // Terminate process exit-code handler. |
| 839 Process::TerminateExitCodeHandler(); | 837 Process::TerminateExitCodeHandler(); |
| 840 // Free copied argument strings if converted. | 838 // Free copied argument strings if converted. |
| 841 if (argv_converted) { | 839 if (argv_converted) { |
| 842 for (int i = 0; i < argc; i++) free(argv[i]); | 840 for (int i = 0; i < argc; i++) free(argv[i]); |
| 843 } | 841 } |
| 844 | 842 |
| 845 return Process::GlobalExitCode(); | 843 return Process::GlobalExitCode(); |
| 846 } | 844 } |
| OLD | NEW |