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 "platform/globals.h" | 23 #include "platform/globals.h" |
24 | 24 |
25 // snapshot_buffer points to a snapshot if we link in a snapshot otherwise | 25 // snapshot_buffer points to a snapshot if we link in a snapshot otherwise |
26 // it is initialized to NULL. | 26 // it is initialized to NULL. |
27 extern const uint8_t* snapshot_buffer; | 27 extern const uint8_t* snapshot_buffer; |
28 | 28 |
29 // Global state that indicates whether pprof symbol information is | |
30 // to be generated or not. | |
31 static const char* generate_pprof_symbols_filename = NULL; | |
32 | |
33 | 29 |
34 // Global state that stores a pointer to the application script snapshot. | 30 // Global state that stores a pointer to the application script snapshot. |
35 static bool use_script_snapshot = false; | 31 static bool use_script_snapshot = false; |
36 static File* snapshot_file = NULL; | 32 static File* snapshot_file = NULL; |
37 | 33 |
38 | 34 |
39 // Global state that indicates whether there is a debug breakpoint. | 35 // Global state that indicates whether there is a debug breakpoint. |
40 // This pointer points into an argv buffer and does not need to be | 36 // This pointer points into an argv buffer and does not need to be |
41 // free'd. | 37 // free'd. |
42 static const char* breakpoint_at = NULL; | 38 static const char* breakpoint_at = NULL; |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
140 if (debug_port == 0) { | 136 if (debug_port == 0) { |
141 Log::PrintErr("unrecognized --debug option syntax. " | 137 Log::PrintErr("unrecognized --debug option syntax. " |
142 "Use --debug[:<port number>]\n"); | 138 "Use --debug[:<port number>]\n"); |
143 return false; | 139 return false; |
144 } | 140 } |
145 breakpoint_at = "main"; | 141 breakpoint_at = "main"; |
146 start_debugger = true; | 142 start_debugger = true; |
147 return true; | 143 return true; |
148 } | 144 } |
149 | 145 |
150 static bool ProcessPprofOption(const char* filename) { | |
151 ASSERT(filename != NULL); | |
152 generate_pprof_symbols_filename = filename; | |
153 return true; | |
154 } | |
155 | |
156 | 146 |
157 static bool ProcessScriptSnapshotOption(const char* filename) { | 147 static bool ProcessScriptSnapshotOption(const char* filename) { |
158 if (filename != NULL && strlen(filename) != 0) { | 148 if (filename != NULL && strlen(filename) != 0) { |
159 use_script_snapshot = true; | 149 use_script_snapshot = true; |
160 snapshot_file = File::Open(filename, File::kRead); | 150 snapshot_file = File::Open(filename, File::kRead); |
161 } | 151 } |
162 return true; | 152 return true; |
163 } | 153 } |
164 | 154 |
165 | 155 |
166 static struct { | 156 static struct { |
167 const char* option_name; | 157 const char* option_name; |
168 bool (*process)(const char* option); | 158 bool (*process)(const char* option); |
169 } main_options[] = { | 159 } main_options[] = { |
170 // Standard options shared with dart2js. | 160 // Standard options shared with dart2js. |
171 { "--version", ProcessVersionOption }, | 161 { "--version", ProcessVersionOption }, |
172 { "--help", ProcessHelpOption }, | 162 { "--help", ProcessHelpOption }, |
173 { "-h", ProcessHelpOption }, | 163 { "-h", ProcessHelpOption }, |
174 { "--verbose", ProcessVerboseOption }, | 164 { "--verbose", ProcessVerboseOption }, |
175 { "-v", ProcessVerboseOption }, | 165 { "-v", ProcessVerboseOption }, |
176 { "--package-root=", ProcessPackageRootOption }, | 166 { "--package-root=", ProcessPackageRootOption }, |
177 { "-p", ProcessPackageRootOption }, | 167 { "-p", ProcessPackageRootOption }, |
178 // VM specific options to the standalone dart program. | 168 // VM specific options to the standalone dart program. |
179 { "--break_at=", ProcessBreakpointOption }, | 169 { "--break_at=", ProcessBreakpointOption }, |
180 { "--compile_all", ProcessCompileAllOption }, | 170 { "--compile_all", ProcessCompileAllOption }, |
181 { "--debug", ProcessDebugOption }, | 171 { "--debug", ProcessDebugOption }, |
182 { "--generate_pprof_symbols=", ProcessPprofOption }, | |
183 { "--use_script_snapshot=", ProcessScriptSnapshotOption }, | 172 { "--use_script_snapshot=", ProcessScriptSnapshotOption }, |
184 { NULL, NULL } | 173 { NULL, NULL } |
185 }; | 174 }; |
186 | 175 |
187 | 176 |
188 static bool ProcessMainOptions(const char* option) { | 177 static bool ProcessMainOptions(const char* option) { |
189 int i = 0; | 178 int i = 0; |
190 const char* name = main_options[0].option_name; | 179 const char* name = main_options[0].option_name; |
191 while (name != NULL) { | 180 while (name != NULL) { |
192 int length = strlen(name); | 181 int length = strlen(name); |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
269 const char* kPrintFlags2 = "--print_flags"; | 258 const char* kPrintFlags2 = "--print_flags"; |
270 if ((strncmp(argv[i], kPrintFlags1, strlen(kPrintFlags1)) == 0) || | 259 if ((strncmp(argv[i], kPrintFlags1, strlen(kPrintFlags1)) == 0) || |
271 (strncmp(argv[i], kPrintFlags2, strlen(kPrintFlags2)) == 0)) { | 260 (strncmp(argv[i], kPrintFlags2, strlen(kPrintFlags2)) == 0)) { |
272 *print_flags_seen = true; | 261 *print_flags_seen = true; |
273 } | 262 } |
274 vm_options->AddArgument(argv[i]); | 263 vm_options->AddArgument(argv[i]); |
275 i++; | 264 i++; |
276 } | 265 } |
277 } | 266 } |
278 | 267 |
279 if (generate_pprof_symbols_filename != NULL) { | |
280 Dart_InitPprofSupport(); | |
281 } | |
282 | 268 |
283 // Get the script name. | 269 // Get the script name. |
284 if (i < argc) { | 270 if (i < argc) { |
285 *script_name = argv[i]; | 271 *script_name = argv[i]; |
286 i++; | 272 i++; |
287 } else { | 273 } else { |
288 return -1; | 274 return -1; |
289 } | 275 } |
290 | 276 |
291 // Parse out options to be passed to dart main. | 277 // Parse out options to be passed to dart main. |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
366 } | 352 } |
367 Dart_Handle native_name = DartUtils::NewString("_nativeArguments"); | 353 Dart_Handle native_name = DartUtils::NewString("_nativeArguments"); |
368 if (Dart_IsError(native_name)) { | 354 if (Dart_IsError(native_name)) { |
369 return native_name; | 355 return native_name; |
370 } | 356 } |
371 | 357 |
372 return Dart_SetField(runtime_options_class, native_name, dart_arguments); | 358 return Dart_SetField(runtime_options_class, native_name, dart_arguments); |
373 } | 359 } |
374 | 360 |
375 | 361 |
376 static void DumpPprofSymbolInfo() { | |
377 if (generate_pprof_symbols_filename != NULL) { | |
378 Dart_EnterScope(); | |
379 File* pprof_file = | |
380 File::Open(generate_pprof_symbols_filename, File::kWriteTruncate); | |
381 ASSERT(pprof_file != NULL); | |
382 void* buffer; | |
383 int buffer_size; | |
384 Dart_GetPprofSymbolInfo(&buffer, &buffer_size); | |
385 if (buffer_size > 0) { | |
386 ASSERT(buffer != NULL); | |
387 pprof_file->WriteFully(buffer, buffer_size); | |
388 } | |
389 delete pprof_file; // Closes the file. | |
390 Dart_ExitScope(); | |
391 } | |
392 } | |
393 | |
394 | |
395 #define CHECK_RESULT(result) \ | 362 #define CHECK_RESULT(result) \ |
396 if (Dart_IsError(result)) { \ | 363 if (Dart_IsError(result)) { \ |
397 *error = strdup(Dart_GetError(result)); \ | 364 *error = strdup(Dart_GetError(result)); \ |
398 Dart_ExitScope(); \ | 365 Dart_ExitScope(); \ |
399 Dart_ShutdownIsolate(); \ | 366 Dart_ShutdownIsolate(); \ |
400 return false; \ | 367 return false; \ |
401 } \ | 368 } \ |
402 | 369 |
403 | 370 |
404 // Returns true on success, false on failure. | 371 // Returns true on success, false on failure. |
(...skipping 337 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
742 if (Dart_IsError(result)) { | 709 if (Dart_IsError(result)) { |
743 return ErrorExit("%s\n", Dart_GetError(result)); | 710 return ErrorExit("%s\n", Dart_GetError(result)); |
744 } | 711 } |
745 // Keep handling messages until the last active receive port is closed. | 712 // Keep handling messages until the last active receive port is closed. |
746 result = Dart_RunLoop(); | 713 result = Dart_RunLoop(); |
747 if (Dart_IsError(result)) { | 714 if (Dart_IsError(result)) { |
748 return ErrorExit("%s\n", Dart_GetError(result)); | 715 return ErrorExit("%s\n", Dart_GetError(result)); |
749 } | 716 } |
750 | 717 |
751 Dart_ExitScope(); | 718 Dart_ExitScope(); |
752 // Dump symbol information for the profiler. | |
753 DumpPprofSymbolInfo(); | |
754 // Shutdown the isolate. | 719 // Shutdown the isolate. |
755 Dart_ShutdownIsolate(); | 720 Dart_ShutdownIsolate(); |
756 // Terminate process exit-code handler. | 721 // Terminate process exit-code handler. |
757 Process::TerminateExitCodeHandler(); | 722 Process::TerminateExitCodeHandler(); |
758 // Free copied argument strings if converted. | 723 // Free copied argument strings if converted. |
759 if (argv_converted) { | 724 if (argv_converted) { |
760 for (int i = 0; i < argc; i++) free(argv[i]); | 725 for (int i = 0; i < argc; i++) free(argv[i]); |
761 } | 726 } |
762 | 727 |
763 return Process::GlobalExitCode(); | 728 return Process::GlobalExitCode(); |
764 } | 729 } |
OLD | NEW |