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 23 matching lines...) Expand all Loading... |
34 | 34 |
35 // Global state that indicates whether pprof symbol information is | 35 // Global state that indicates whether pprof symbol information is |
36 // to be generated or not. | 36 // to be generated or not. |
37 static const char* generate_pprof_symbols_filename = NULL; | 37 static const char* generate_pprof_symbols_filename = NULL; |
38 | 38 |
39 | 39 |
40 // Global state that stores a pointer to the application script snapshot. | 40 // Global state that stores a pointer to the application script snapshot. |
41 static bool use_script_snapshot = false; | 41 static bool use_script_snapshot = false; |
42 static File* snapshot_file = NULL; | 42 static File* snapshot_file = NULL; |
43 | 43 |
| 44 |
44 // Global state that indicates whether there is a debug breakpoint. | 45 // Global state that indicates whether there is a debug breakpoint. |
45 // This pointer points into an argv buffer and does not need to be | 46 // This pointer points into an argv buffer and does not need to be |
46 // free'd. | 47 // free'd. |
47 static const char* breakpoint_at = NULL; | 48 static const char* breakpoint_at = NULL; |
48 | 49 |
49 | 50 |
50 // Global state that indicates whether we should open a connection | 51 // Global state that indicates whether we should open a connection |
51 // and listen for a debugger to connect. | 52 // and listen for a debugger to connect. |
52 static bool start_debugger = false; | 53 static bool start_debugger = false; |
53 static const int DEFAULT_DEBUG_PORT = 5858; | 54 static const int DEFAULT_DEBUG_PORT = 5858; |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
220 if (strncmp(option, name, length) == 0) { | 221 if (strncmp(option, name, length) == 0) { |
221 return main_options[i].process(option + length); | 222 return main_options[i].process(option + length); |
222 } | 223 } |
223 i += 1; | 224 i += 1; |
224 name = main_options[i].option_name; | 225 name = main_options[i].option_name; |
225 } | 226 } |
226 return false; | 227 return false; |
227 } | 228 } |
228 | 229 |
229 | 230 |
230 static void WriteToPerfEventsFile(const char* buffer, int64_t num_bytes) { | 231 static void* OpenFile(const char* name) { |
231 ASSERT(perf_events_symbols_file != NULL); | 232 File* file = File::Open(name, File::kWriteTruncate); |
232 perf_events_symbols_file->WriteFully(buffer, num_bytes); | 233 ASSERT(file != NULL); |
| 234 return reinterpret_cast<void*>(file); |
233 } | 235 } |
234 | 236 |
| 237 |
| 238 static void WriteFile(const void* buffer, intptr_t num_bytes, void* stream) { |
| 239 ASSERT(stream != NULL); |
| 240 File* file_stream = reinterpret_cast<File*>(stream); |
| 241 bool bytes_written = file_stream->WriteFully(buffer, num_bytes); |
| 242 ASSERT(bytes_written); |
| 243 } |
| 244 |
| 245 |
| 246 static void CloseFile(void* stream) { |
| 247 delete reinterpret_cast<File*>(stream); |
| 248 } |
| 249 |
| 250 |
235 // Convert all the arguments to UTF8. On Windows, the arguments are | 251 // Convert all the arguments to UTF8. On Windows, the arguments are |
236 // encoded in the current code page and not UTF8. | 252 // encoded in the current code page and not UTF8. |
237 // | 253 // |
238 // Returns true if the arguments are converted. In that case | 254 // Returns true if the arguments are converted. In that case |
239 // each of the arguments need to be deallocated using free. | 255 // each of the arguments need to be deallocated using free. |
240 static bool Utf8ConvertArgv(int argc, char** argv) { | 256 static bool Utf8ConvertArgv(int argc, char** argv) { |
241 bool result = false; | 257 bool result = false; |
242 for (int i = 0; i < argc; i++) { | 258 for (int i = 0; i < argc; i++) { |
243 char* arg = argv[i]; | 259 char* arg = argv[i]; |
244 argv[i] = StringUtils::SystemStringToUtf8(arg); | 260 argv[i] = StringUtils::SystemStringToUtf8(arg); |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
284 if ((strncmp(argv[i], kPrintFlags1, strlen(kPrintFlags1)) == 0) || | 300 if ((strncmp(argv[i], kPrintFlags1, strlen(kPrintFlags1)) == 0) || |
285 (strncmp(argv[i], kPrintFlags2, strlen(kPrintFlags2)) == 0)) { | 301 (strncmp(argv[i], kPrintFlags2, strlen(kPrintFlags2)) == 0)) { |
286 *print_flags_seen = true; | 302 *print_flags_seen = true; |
287 } | 303 } |
288 vm_options->AddArgument(argv[i]); | 304 vm_options->AddArgument(argv[i]); |
289 i++; | 305 i++; |
290 } | 306 } |
291 } | 307 } |
292 | 308 |
293 if (perf_events_symbols_file != NULL) { | 309 if (perf_events_symbols_file != NULL) { |
294 Dart_InitPerfEventsSupport(&WriteToPerfEventsFile); | 310 Dart_InitPerfEventsSupport(perf_events_symbols_file); |
295 } | 311 } |
296 | 312 |
297 if (generate_pprof_symbols_filename != NULL) { | 313 if (generate_pprof_symbols_filename != NULL) { |
298 Dart_InitPprofSupport(); | 314 Dart_InitPprofSupport(); |
299 } | 315 } |
300 | 316 |
301 // Get the script name. | 317 // Get the script name. |
302 if (i < argc) { | 318 if (i < argc) { |
303 *script_name = argv[i]; | 319 *script_name = argv[i]; |
304 i++; | 320 i++; |
(...skipping 378 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
683 return 0; | 699 return 0; |
684 } else { | 700 } else { |
685 PrintUsage(); | 701 PrintUsage(); |
686 return kErrorExitCode; | 702 return kErrorExitCode; |
687 } | 703 } |
688 } | 704 } |
689 | 705 |
690 Dart_SetVMFlags(vm_options.count(), vm_options.arguments()); | 706 Dart_SetVMFlags(vm_options.count(), vm_options.arguments()); |
691 | 707 |
692 // Initialize the Dart VM. | 708 // Initialize the Dart VM. |
693 if (!Dart_Initialize(CreateIsolateAndSetup, | 709 if (!Dart_Initialize(CreateIsolateAndSetup, NULL, NULL, ShutdownIsolate, |
694 NULL, | 710 OpenFile, WriteFile, CloseFile)) { |
695 NULL, | |
696 ShutdownIsolate)) { | |
697 fprintf(stderr, "%s", "VM initialization failed\n"); | 711 fprintf(stderr, "%s", "VM initialization failed\n"); |
698 fflush(stderr); | 712 fflush(stderr); |
699 return kErrorExitCode; | 713 return kErrorExitCode; |
700 } | 714 } |
701 | 715 |
702 DartUtils::SetOriginalWorkingDirectory(); | 716 DartUtils::SetOriginalWorkingDirectory(); |
703 | 717 |
704 // Start the debugger wire protocol handler if necessary. | 718 // Start the debugger wire protocol handler if necessary. |
705 if (start_debugger) { | 719 if (start_debugger) { |
706 ASSERT(debug_port != 0); | 720 ASSERT(debug_port != 0); |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
775 Dart_ShutdownIsolate(); | 789 Dart_ShutdownIsolate(); |
776 // Terminate process exit-code handler. | 790 // Terminate process exit-code handler. |
777 Process::TerminateExitCodeHandler(); | 791 Process::TerminateExitCodeHandler(); |
778 // Free copied argument strings if converted. | 792 // Free copied argument strings if converted. |
779 if (argv_converted) { | 793 if (argv_converted) { |
780 for (int i = 0; i < argc; i++) free(argv[i]); | 794 for (int i = 0; i < argc; i++) free(argv[i]); |
781 } | 795 } |
782 | 796 |
783 return 0; | 797 return 0; |
784 } | 798 } |
OLD | NEW |