| 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 22 matching lines...) Expand all Loading... |
| 33 | 33 |
| 34 // Global state that indicates whether pprof symbol information is | 34 // Global state that indicates whether pprof symbol information is |
| 35 // to be generated or not. | 35 // to be generated or not. |
| 36 static const char* generate_pprof_symbols_filename = NULL; | 36 static const char* generate_pprof_symbols_filename = NULL; |
| 37 | 37 |
| 38 | 38 |
| 39 // Global state that stores a pointer to the application script snapshot. | 39 // Global state that stores a pointer to the application script snapshot. |
| 40 static bool use_script_snapshot = false; | 40 static bool use_script_snapshot = false; |
| 41 static File* snapshot_file = NULL; | 41 static File* snapshot_file = NULL; |
| 42 | 42 |
| 43 | |
| 44 // Global state that stores a file name for flow graph debugging output. | |
| 45 // NULL if no output is generated. | |
| 46 static File* flow_graph_file = NULL; | |
| 47 | |
| 48 // Global state that indicates whether there is a debug breakpoint. | 43 // Global state that indicates whether there is a debug breakpoint. |
| 49 // This pointer points into an argv buffer and does not need to be | 44 // This pointer points into an argv buffer and does not need to be |
| 50 // free'd. | 45 // free'd. |
| 51 static const char* breakpoint_at = NULL; | 46 static const char* breakpoint_at = NULL; |
| 52 | 47 |
| 53 | 48 |
| 54 // Global state that indicates whether we should open a connection | 49 // Global state that indicates whether we should open a connection |
| 55 // and listen for a debugger to connect. | 50 // and listen for a debugger to connect. |
| 56 static bool start_debugger = false; | 51 static bool start_debugger = false; |
| 57 static const int DEFAULT_DEBUG_PORT = 5858; | 52 static const int DEFAULT_DEBUG_PORT = 5858; |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 176 | 171 |
| 177 static bool ProcessScriptSnapshotOption(const char* filename) { | 172 static bool ProcessScriptSnapshotOption(const char* filename) { |
| 178 if (filename != NULL && strlen(filename) != 0) { | 173 if (filename != NULL && strlen(filename) != 0) { |
| 179 use_script_snapshot = true; | 174 use_script_snapshot = true; |
| 180 snapshot_file = File::Open(filename, File::kRead); | 175 snapshot_file = File::Open(filename, File::kRead); |
| 181 } | 176 } |
| 182 return true; | 177 return true; |
| 183 } | 178 } |
| 184 | 179 |
| 185 | 180 |
| 186 static bool ProcessFlowGraphOption(const char* flowgraph_option) { | |
| 187 ASSERT(flowgraph_option != NULL); | |
| 188 flow_graph_file = File::Open("flowgraph.cfg", File::kWriteTruncate); | |
| 189 ASSERT(flow_graph_file != NULL); | |
| 190 return true; | |
| 191 } | |
| 192 | |
| 193 | |
| 194 static struct { | 181 static struct { |
| 195 const char* option_name; | 182 const char* option_name; |
| 196 bool (*process)(const char* option); | 183 bool (*process)(const char* option); |
| 197 } main_options[] = { | 184 } main_options[] = { |
| 198 // Standard options shared with dart2js. | 185 // Standard options shared with dart2js. |
| 199 { "--help", ProcessHelpOption }, | 186 { "--help", ProcessHelpOption }, |
| 200 { "-h", ProcessHelpOption }, | 187 { "-h", ProcessHelpOption }, |
| 201 { "--verbose", ProcessVerboseOption }, | 188 { "--verbose", ProcessVerboseOption }, |
| 202 { "-v", ProcessVerboseOption }, | 189 { "-v", ProcessVerboseOption }, |
| 203 { "--package-root=", ProcessPackageRootOption }, | 190 { "--package-root=", ProcessPackageRootOption }, |
| 204 { "-p", ProcessPackageRootOption }, | 191 { "-p", ProcessPackageRootOption }, |
| 205 // VM specific options to the standalone dart program. | 192 // VM specific options to the standalone dart program. |
| 206 { "--break_at=", ProcessBreakpointOption }, | 193 { "--break_at=", ProcessBreakpointOption }, |
| 207 { "--compile_all", ProcessCompileAllOption }, | 194 { "--compile_all", ProcessCompileAllOption }, |
| 208 { "--debug", ProcessDebugOption }, | 195 { "--debug", ProcessDebugOption }, |
| 209 { "--generate_flow_graph", ProcessFlowGraphOption }, | |
| 210 { "--generate_perf_events_symbols", ProcessPerfEventsOption }, | 196 { "--generate_perf_events_symbols", ProcessPerfEventsOption }, |
| 211 { "--generate_pprof_symbols=", ProcessPprofOption }, | 197 { "--generate_pprof_symbols=", ProcessPprofOption }, |
| 212 { "--use_script_snapshot=", ProcessScriptSnapshotOption }, | 198 { "--use_script_snapshot=", ProcessScriptSnapshotOption }, |
| 213 { NULL, NULL } | 199 { NULL, NULL } |
| 214 }; | 200 }; |
| 215 | 201 |
| 216 | 202 |
| 217 static bool ProcessMainOptions(const char* option) { | 203 static bool ProcessMainOptions(const char* option) { |
| 218 int i = 0; | 204 int i = 0; |
| 219 const char* name = main_options[0].option_name; | 205 const char* name = main_options[0].option_name; |
| 220 while (name != NULL) { | 206 while (name != NULL) { |
| 221 int length = strlen(name); | 207 int length = strlen(name); |
| 222 if (strncmp(option, name, length) == 0) { | 208 if (strncmp(option, name, length) == 0) { |
| 223 return main_options[i].process(option + length); | 209 return main_options[i].process(option + length); |
| 224 } | 210 } |
| 225 i += 1; | 211 i += 1; |
| 226 name = main_options[i].option_name; | 212 name = main_options[i].option_name; |
| 227 } | 213 } |
| 228 return false; | 214 return false; |
| 229 } | 215 } |
| 230 | 216 |
| 231 | 217 |
| 232 static void WriteToPerfEventsFile(const char* buffer, int64_t num_bytes) { | 218 static void WriteToPerfEventsFile(const char* buffer, int64_t num_bytes) { |
| 233 ASSERT(perf_events_symbols_file != NULL); | 219 ASSERT(perf_events_symbols_file != NULL); |
| 234 perf_events_symbols_file->WriteFully(buffer, num_bytes); | 220 perf_events_symbols_file->WriteFully(buffer, num_bytes); |
| 235 } | 221 } |
| 236 | 222 |
| 237 | 223 |
| 238 static void WriteToFlowGraphFile(const char* buffer, int64_t num_bytes) { | |
| 239 ASSERT(flow_graph_file != NULL); | |
| 240 flow_graph_file->WriteFully(buffer, num_bytes); | |
| 241 } | |
| 242 | |
| 243 | |
| 244 // Parse out the command line arguments. Returns -1 if the arguments | 224 // Parse out the command line arguments. Returns -1 if the arguments |
| 245 // are incorrect, 0 otherwise. | 225 // are incorrect, 0 otherwise. |
| 246 static int ParseArguments(int argc, | 226 static int ParseArguments(int argc, |
| 247 char** argv, | 227 char** argv, |
| 248 CommandLineOptions* vm_options, | 228 CommandLineOptions* vm_options, |
| 249 char** executable_name, | 229 char** executable_name, |
| 250 char** script_name, | 230 char** script_name, |
| 251 CommandLineOptions* dart_options, | 231 CommandLineOptions* dart_options, |
| 252 bool* print_flags_seen) { | 232 bool* print_flags_seen) { |
| 253 const char* kPrefix = "--"; | 233 const char* kPrefix = "--"; |
| (...skipping 26 matching lines...) Expand all Loading... |
| 280 } | 260 } |
| 281 | 261 |
| 282 if (perf_events_symbols_file != NULL) { | 262 if (perf_events_symbols_file != NULL) { |
| 283 Dart_InitPerfEventsSupport(&WriteToPerfEventsFile); | 263 Dart_InitPerfEventsSupport(&WriteToPerfEventsFile); |
| 284 } | 264 } |
| 285 | 265 |
| 286 if (generate_pprof_symbols_filename != NULL) { | 266 if (generate_pprof_symbols_filename != NULL) { |
| 287 Dart_InitPprofSupport(); | 267 Dart_InitPprofSupport(); |
| 288 } | 268 } |
| 289 | 269 |
| 290 if (flow_graph_file != NULL) { | |
| 291 Dart_InitFlowGraphPrinting(&WriteToFlowGraphFile); | |
| 292 } | |
| 293 | |
| 294 // Get the script name. | 270 // Get the script name. |
| 295 if (i < argc) { | 271 if (i < argc) { |
| 296 *script_name = argv[i]; | 272 *script_name = argv[i]; |
| 297 i++; | 273 i++; |
| 298 } else { | 274 } else { |
| 299 return -1; | 275 return -1; |
| 300 } | 276 } |
| 301 | 277 |
| 302 // Parse out options to be passed to dart main. | 278 // Parse out options to be passed to dart main. |
| 303 while (i < argc) { | 279 while (i < argc) { |
| (...skipping 442 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 746 Dart_ExitScope(); | 722 Dart_ExitScope(); |
| 747 // Dump symbol information for the profiler. | 723 // Dump symbol information for the profiler. |
| 748 DumpPprofSymbolInfo(); | 724 DumpPprofSymbolInfo(); |
| 749 // Shutdown the isolate. | 725 // Shutdown the isolate. |
| 750 Dart_ShutdownIsolate(); | 726 Dart_ShutdownIsolate(); |
| 751 // Terminate process exit-code handler. | 727 // Terminate process exit-code handler. |
| 752 Process::TerminateExitCodeHandler(); | 728 Process::TerminateExitCodeHandler(); |
| 753 | 729 |
| 754 return 0; | 730 return 0; |
| 755 } | 731 } |
| OLD | NEW |