| 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 27 matching lines...) Expand all Loading... |
| 38 | 38 |
| 39 // Global state that indicates whether there is a debug breakpoint. | 39 // Global state that indicates whether there is a debug breakpoint. |
| 40 // This pointer points into an argv buffer and does not need to be | 40 // This pointer points into an argv buffer and does not need to be |
| 41 // free'd. | 41 // free'd. |
| 42 static const char* breakpoint_at = NULL; | 42 static const char* breakpoint_at = NULL; |
| 43 | 43 |
| 44 | 44 |
| 45 // Global state that indicates whether we should open a connection | 45 // Global state that indicates whether we should open a connection |
| 46 // and listen for a debugger to connect. | 46 // and listen for a debugger to connect. |
| 47 static bool start_debugger = false; | 47 static bool start_debugger = false; |
| 48 static const char* debug_ip = NULL; |
| 49 static int debug_port = -1; |
| 50 static const char* DEFAULT_DEBUG_IP = "127.0.0.1"; |
| 48 static const int DEFAULT_DEBUG_PORT = 5858; | 51 static const int DEFAULT_DEBUG_PORT = 5858; |
| 49 static const char* DEFAULT_DEBUG_IP = "127.0.0.1"; | |
| 50 static const char* debug_ip = DEFAULT_DEBUG_IP; | |
| 51 static int debug_port = -1; | |
| 52 | 52 |
| 53 // Value of the --package-root flag. | 53 // Value of the --package-root flag. |
| 54 // (This pointer points into an argv buffer and does not need to be | 54 // (This pointer points into an argv buffer and does not need to be |
| 55 // free'd.) | 55 // free'd.) |
| 56 static const char* package_root = NULL; | 56 static const char* package_root = NULL; |
| 57 | 57 |
| 58 | 58 |
| 59 // Global flag that is used to indicate that we want to compile all the | 59 // Global flag that is used to indicate that we want to compile all the |
| 60 // dart functions and not run anything. | 60 // dart functions and not run anything. |
| 61 static bool has_compile_all = false; | 61 static bool has_compile_all = false; |
| 62 | 62 |
| 63 // Global flag that is used to indicate that we want to print the source code | 63 // Global flag that is used to indicate that we want to print the source code |
| 64 // for script that is being run. | 64 // for script that is being run. |
| 65 static bool has_print_script = false; | 65 static bool has_print_script = false; |
| 66 | 66 |
| 67 | 67 |
| 68 // VM Service options. | 68 // VM Service options. |
| 69 static bool start_vm_service = false; | 69 static bool start_vm_service = false; |
| 70 static const char *vm_service_server_ip = NULL; |
| 70 static int vm_service_server_port = -1; | 71 static int vm_service_server_port = -1; |
| 72 static const char *DEFAULT_VM_SERVICE_SERVER_IP = "127.0.0.1"; |
| 71 static const int DEFAULT_VM_SERVICE_SERVER_PORT = 8181; | 73 static const int DEFAULT_VM_SERVICE_SERVER_PORT = 8181; |
| 72 | 74 |
| 73 // The environment provided through the command line using -D options. | 75 // The environment provided through the command line using -D options. |
| 74 static dart::HashMap* environment = NULL; | 76 static dart::HashMap* environment = NULL; |
| 75 | 77 |
| 76 static bool IsValidFlag(const char* name, | 78 static bool IsValidFlag(const char* name, |
| 77 const char* prefix, | 79 const char* prefix, |
| 78 intptr_t prefix_length) { | 80 intptr_t prefix_length) { |
| 79 intptr_t name_length = strlen(name); | 81 intptr_t name_length = strlen(name); |
| 80 return ((name_length > prefix_length) && | 82 return ((name_length > prefix_length) && |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 129 } | 131 } |
| 130 package_root = arg; | 132 package_root = arg; |
| 131 return true; | 133 return true; |
| 132 } | 134 } |
| 133 | 135 |
| 134 | 136 |
| 135 static void* GetHashmapKeyFromString(char* key) { | 137 static void* GetHashmapKeyFromString(char* key) { |
| 136 return reinterpret_cast<void*>(key); | 138 return reinterpret_cast<void*>(key); |
| 137 } | 139 } |
| 138 | 140 |
| 141 |
| 142 static bool ExtractPortAndIP(const char *option_value, |
| 143 int *out_port, |
| 144 const char **out_ip, |
| 145 int default_port, |
| 146 const char *default_ip) { |
| 147 // [option_value] has to be one of the following formats: |
| 148 // - "" |
| 149 // - ":8181" |
| 150 // - "=8181" |
| 151 // - ":8181/192.168.0.1" |
| 152 // - "=8181/192.168.0.1" |
| 153 |
| 154 if (*option_value== '\0') { |
| 155 *out_ip = default_ip; |
| 156 *out_port = default_port; |
| 157 return true; |
| 158 } |
| 159 |
| 160 if ((*option_value != '=') && (*option_value != ':')) { |
| 161 return false; |
| 162 } |
| 163 |
| 164 int port = atoi(option_value + 1); |
| 165 const char *slash = strstr(option_value, "/"); |
| 166 if (slash == NULL) { |
| 167 *out_ip = default_ip; |
| 168 *out_port = port; |
| 169 return true; |
| 170 } |
| 171 |
| 172 int _, n; |
| 173 if (sscanf(option_value + 1, "%d/%d.%d.%d.%d%n", // NOLINT(runtime/printf) |
| 174 &_, &_, &_, &_, &_, &n)) { |
| 175 if (option_value[1 + n] == '\0') { |
| 176 *out_ip = slash + 1; |
| 177 *out_port = port; |
| 178 return true; |
| 179 } |
| 180 } |
| 181 return false; |
| 182 } |
| 183 |
| 184 |
| 139 static bool ProcessEnvironmentOption(const char* arg) { | 185 static bool ProcessEnvironmentOption(const char* arg) { |
| 140 ASSERT(arg != NULL); | 186 ASSERT(arg != NULL); |
| 141 if (*arg == '\0') { | 187 if (*arg == '\0') { |
| 142 // Ignore empty -D option. | 188 // Ignore empty -D option. |
| 143 Log::PrintErr("No arguments given to -D option\n"); | 189 Log::PrintErr("No arguments given to -D option\n"); |
| 144 return true; | 190 return true; |
| 145 } | 191 } |
| 146 if (environment == NULL) { | 192 if (environment == NULL) { |
| 147 environment = new HashMap(&HashMap::SameStringValue, 4); | 193 environment = new HashMap(&HashMap::SameStringValue, 4); |
| 148 } | 194 } |
| (...skipping 27 matching lines...) Expand all Loading... |
| 176 | 222 |
| 177 static bool ProcessCompileAllOption(const char* arg) { | 223 static bool ProcessCompileAllOption(const char* arg) { |
| 178 ASSERT(arg != NULL); | 224 ASSERT(arg != NULL); |
| 179 if (*arg != '\0') { | 225 if (*arg != '\0') { |
| 180 return false; | 226 return false; |
| 181 } | 227 } |
| 182 has_compile_all = true; | 228 has_compile_all = true; |
| 183 return true; | 229 return true; |
| 184 } | 230 } |
| 185 | 231 |
| 186 | 232 static bool ProcessDebugOption(const char* option_value) { |
| 187 static bool ProcessDebugOption(const char* port) { | 233 ASSERT(option_value != NULL); |
| 188 // TODO(hausner): Add support for specifying an IP address on which | 234 if (!ExtractPortAndIP(option_value, &debug_port, &debug_ip, |
| 189 // the debugger should listen. | 235 DEFAULT_DEBUG_PORT, DEFAULT_DEBUG_IP)) { |
| 190 ASSERT(port != NULL); | |
| 191 debug_port = -1; | |
| 192 if (*port == '\0') { | |
| 193 debug_port = DEFAULT_DEBUG_PORT; | |
| 194 } else { | |
| 195 if ((*port == '=') || (*port == ':')) { | |
| 196 debug_port = atoi(port + 1); | |
| 197 } | |
| 198 } | |
| 199 if (debug_port < 0) { | |
| 200 Log::PrintErr("unrecognized --debug option syntax. " | 236 Log::PrintErr("unrecognized --debug option syntax. " |
| 201 "Use --debug[:<port number>]\n"); | 237 "Use --debug[:<port number>[/<IPv4 address>]]\n"); |
| 202 return false; | 238 return false; |
| 203 } | 239 } |
| 240 |
| 204 breakpoint_at = "main"; | 241 breakpoint_at = "main"; |
| 205 start_debugger = true; | 242 start_debugger = true; |
| 206 return true; | 243 return true; |
| 207 } | 244 } |
| 208 | 245 |
| 209 | 246 |
| 210 static bool ProcessPrintScriptOption(const char* arg) { | 247 static bool ProcessPrintScriptOption(const char* arg) { |
| 211 ASSERT(arg != NULL); | 248 ASSERT(arg != NULL); |
| 212 if (*arg != '\0') { | 249 if (*arg != '\0') { |
| 213 return false; | 250 return false; |
| (...skipping 17 matching lines...) Expand all Loading... |
| 231 filename); | 268 filename); |
| 232 return false; | 269 return false; |
| 233 } | 270 } |
| 234 generate_script_snapshot = true; | 271 generate_script_snapshot = true; |
| 235 return true; | 272 return true; |
| 236 } | 273 } |
| 237 return false; | 274 return false; |
| 238 } | 275 } |
| 239 | 276 |
| 240 | 277 |
| 241 static bool ProcessEnableVmServiceOption(const char* port) { | 278 static bool ProcessEnableVmServiceOption(const char* option_value) { |
| 242 ASSERT(port != NULL); | 279 ASSERT(option_value != NULL); |
| 243 vm_service_server_port = -1; | 280 |
| 244 if (*port == '\0') { | 281 if (!ExtractPortAndIP(option_value, |
| 245 vm_service_server_port = DEFAULT_VM_SERVICE_SERVER_PORT; | 282 &vm_service_server_port, |
| 246 } else { | 283 &vm_service_server_ip, |
| 247 if ((*port == '=') || (*port == ':')) { | 284 DEFAULT_VM_SERVICE_SERVER_PORT, |
| 248 vm_service_server_port = atoi(port + 1); | 285 DEFAULT_VM_SERVICE_SERVER_IP)) { |
| 249 } | |
| 250 } | |
| 251 if (vm_service_server_port < 0) { | |
| 252 Log::PrintErr("unrecognized --enable-vm-service option syntax. " | 286 Log::PrintErr("unrecognized --enable-vm-service option syntax. " |
| 253 "Use --enable-vm-service[:<port number>]\n"); | 287 "Use --enable-vm-service[:<port number>[/<IPv4 address>]]\n"); |
| 254 return false; | 288 return false; |
| 255 } | 289 } |
| 290 |
| 256 start_vm_service = true; | 291 start_vm_service = true; |
| 257 return true; | 292 return true; |
| 258 } | 293 } |
| 259 | 294 |
| 260 bool trace_debug_protocol = false; | 295 bool trace_debug_protocol = false; |
| 261 static bool ProcessTraceDebugProtocolOption(const char* arg) { | 296 static bool ProcessTraceDebugProtocolOption(const char* arg) { |
| 262 if (*arg != '\0') { | 297 if (*arg != '\0') { |
| 263 return false; | 298 return false; |
| 264 } | 299 } |
| 265 trace_debug_protocol = true; | 300 trace_debug_protocol = true; |
| (...skipping 671 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 937 Log::Print("Debugger listening on port %d\n", debug_port); | 972 Log::Print("Debugger listening on port %d\n", debug_port); |
| 938 } | 973 } |
| 939 } | 974 } |
| 940 | 975 |
| 941 // Start event handler. | 976 // Start event handler. |
| 942 EventHandler::Start(); | 977 EventHandler::Start(); |
| 943 | 978 |
| 944 ASSERT(Dart_CurrentIsolate() == NULL); | 979 ASSERT(Dart_CurrentIsolate() == NULL); |
| 945 // Start the VM service isolate, if necessary. | 980 // Start the VM service isolate, if necessary. |
| 946 if (start_vm_service) { | 981 if (start_vm_service) { |
| 947 ASSERT(vm_service_server_port >= 0); | 982 ASSERT(vm_service_server_ip != NULL && vm_service_server_port >= 0); |
| 948 bool r = VmService::Start(vm_service_server_port); | 983 bool r = VmService::Start(vm_service_server_ip , vm_service_server_port); |
| 949 if (!r) { | 984 if (!r) { |
| 950 Log::PrintErr("Could not start VM Service isolate %s\n", | 985 Log::PrintErr("Could not start VM Service isolate %s\n", |
| 951 VmService::GetErrorMessage()); | 986 VmService::GetErrorMessage()); |
| 952 } | 987 } |
| 953 Dart_RegisterIsolateServiceRequestCallback( | 988 Dart_RegisterIsolateServiceRequestCallback( |
| 954 "io", &ServiceRequestHandler, NULL); | 989 "io", &ServiceRequestHandler, NULL); |
| 955 } | 990 } |
| 956 ASSERT(Dart_CurrentIsolate() == NULL); | 991 ASSERT(Dart_CurrentIsolate() == NULL); |
| 957 | 992 |
| 958 // Call CreateIsolateAndSetup which creates an isolate and loads up | 993 // Call CreateIsolateAndSetup which creates an isolate and loads up |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1097 exit(Process::GlobalExitCode()); | 1132 exit(Process::GlobalExitCode()); |
| 1098 } | 1133 } |
| 1099 | 1134 |
| 1100 } // namespace bin | 1135 } // namespace bin |
| 1101 } // namespace dart | 1136 } // namespace dart |
| 1102 | 1137 |
| 1103 int main(int argc, char** argv) { | 1138 int main(int argc, char** argv) { |
| 1104 dart::bin::main(argc, argv); | 1139 dart::bin::main(argc, argv); |
| 1105 UNREACHABLE(); | 1140 UNREACHABLE(); |
| 1106 } | 1141 } |
| OLD | NEW |