Chromium Code Reviews| 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 21 matching lines...) Expand all Loading... | |
| 32 // Global state that stores the import URL map specified on the | 32 // Global state that stores the import URL map specified on the |
| 33 // command line. | 33 // command line. |
| 34 static CommandLineOptions* import_map_options = NULL; | 34 static CommandLineOptions* import_map_options = NULL; |
| 35 | 35 |
| 36 | 36 |
| 37 // Global state that indicates whether pprof symbol information is | 37 // Global state that indicates whether pprof symbol information is |
| 38 // to be generated or not. | 38 // to be generated or not. |
| 39 static const char* generate_pprof_symbols_filename = NULL; | 39 static const char* generate_pprof_symbols_filename = NULL; |
| 40 | 40 |
| 41 | 41 |
| 42 // Global state that stores a file name for flow graph debugging output. | |
| 43 // NULL if no output is generated. | |
| 44 static File* flow_graph_file = NULL; | |
| 45 | |
| 42 // Global state that indicates whether there is a debug breakpoint. | 46 // Global state that indicates whether there is a debug breakpoint. |
| 43 // This pointer points into an argv buffer and does not need to be | 47 // This pointer points into an argv buffer and does not need to be |
| 44 // free'd. | 48 // free'd. |
| 45 static const char* breakpoint_at = NULL; | 49 static const char* breakpoint_at = NULL; |
| 46 | 50 |
| 47 | 51 |
| 48 // Global state that indicates whether we should open a connection | 52 // Global state that indicates whether we should open a connection |
| 49 // and listen for a debugger to connect. | 53 // and listen for a debugger to connect. |
| 50 static bool start_debugger = false; | 54 static bool start_debugger = false; |
| 51 static const int DEFAULT_DEBUG_PORT = 5858; | 55 static const int DEFAULT_DEBUG_PORT = 5858; |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 122 start_debugger = true; | 126 start_debugger = true; |
| 123 } | 127 } |
| 124 | 128 |
| 125 | 129 |
| 126 static void ProcessPprofOption(const char* filename) { | 130 static void ProcessPprofOption(const char* filename) { |
| 127 ASSERT(filename != NULL); | 131 ASSERT(filename != NULL); |
| 128 generate_pprof_symbols_filename = filename; | 132 generate_pprof_symbols_filename = filename; |
| 129 } | 133 } |
| 130 | 134 |
| 131 | 135 |
| 136 static void ProcessFlowGraphOption(const char* flowgraph_option) { | |
| 137 ASSERT(flowgraph_option != NULL); | |
| 138 flow_graph_file = File::Open("flowgraph.cfg", File::kWriteTruncate); | |
| 139 ASSERT(flow_graph_file != NULL); | |
|
siva
2012/06/04 18:23:57
Where is flow_graph_file closed?
Florian Schneider
2012/06/06 11:06:10
At process exit. I could close it explicitly righ
siva
2012/06/06 17:02:47
I disagree, correctness not conciseness is the yar
Florian Schneider
2012/06/07 09:32:26
I view this as an experimental flag.
How about ab
| |
| 140 } | |
| 141 | |
| 142 | |
| 132 static void ProcessImportMapOption(const char* map) { | 143 static void ProcessImportMapOption(const char* map) { |
| 133 ASSERT(map != NULL); | 144 ASSERT(map != NULL); |
| 134 import_map_options->AddArgument(map); | 145 import_map_options->AddArgument(map); |
| 135 } | 146 } |
| 136 | 147 |
| 137 | 148 |
| 138 static struct { | 149 static struct { |
| 139 const char* option_name; | 150 const char* option_name; |
| 140 void (*process)(const char* option); | 151 void (*process)(const char* option); |
| 141 } main_options[] = { | 152 } main_options[] = { |
| 142 { "--break_at=", ProcessBreakpointOption }, | 153 { "--break_at=", ProcessBreakpointOption }, |
| 143 { "--compile_all", ProcessCompileAllOption }, | 154 { "--compile_all", ProcessCompileAllOption }, |
| 144 { "--debug", ProcessDebugOption }, | 155 { "--debug", ProcessDebugOption }, |
| 145 { "--generate_pprof_symbols=", ProcessPprofOption }, | 156 { "--generate_pprof_symbols=", ProcessPprofOption }, |
| 146 { "--import_map=", ProcessImportMapOption }, | 157 { "--import_map=", ProcessImportMapOption }, |
| 147 { "--package-root=", ProcessPackageRootOption }, | 158 { "--package-root=", ProcessPackageRootOption }, |
| 159 { "--generate_flow_graph", ProcessFlowGraphOption }, | |
| 148 { NULL, NULL } | 160 { NULL, NULL } |
| 149 }; | 161 }; |
| 150 | 162 |
| 151 | 163 |
| 152 static bool ProcessMainOptions(const char* option) { | 164 static bool ProcessMainOptions(const char* option) { |
| 153 int i = 0; | 165 int i = 0; |
| 154 const char* name = main_options[0].option_name; | 166 const char* name = main_options[0].option_name; |
| 155 while (name != NULL) { | 167 while (name != NULL) { |
| 156 int length = strlen(name); | 168 int length = strlen(name); |
| 157 if (strncmp(option, name, length) == 0) { | 169 if (strncmp(option, name, length) == 0) { |
| 158 main_options[i].process(option + length); | 170 main_options[i].process(option + length); |
| 159 return true; | 171 return true; |
| 160 } | 172 } |
| 161 i += 1; | 173 i += 1; |
| 162 name = main_options[i].option_name; | 174 name = main_options[i].option_name; |
| 163 } | 175 } |
| 164 return false; | 176 return false; |
| 165 } | 177 } |
| 166 | 178 |
| 167 | 179 |
| 180 static void WriteToFlowGraphFile(const char* buffer, int64_t num_bytes) { | |
| 181 ASSERT(flow_graph_file != NULL); | |
| 182 flow_graph_file->WriteFully(buffer, num_bytes); | |
| 183 } | |
| 184 | |
| 185 | |
| 168 // Parse out the command line arguments. Returns -1 if the arguments | 186 // Parse out the command line arguments. Returns -1 if the arguments |
| 169 // are incorrect, 0 otherwise. | 187 // are incorrect, 0 otherwise. |
| 170 static int ParseArguments(int argc, | 188 static int ParseArguments(int argc, |
| 171 char** argv, | 189 char** argv, |
| 172 CommandLineOptions* vm_options, | 190 CommandLineOptions* vm_options, |
| 173 char** executable_name, | 191 char** executable_name, |
| 174 char** script_name, | 192 char** script_name, |
| 175 CommandLineOptions* dart_options) { | 193 CommandLineOptions* dart_options) { |
| 176 const char* kPrefix = "--"; | 194 const char* kPrefix = "--"; |
| 177 const intptr_t kPrefixLen = strlen(kPrefix); | 195 const intptr_t kPrefixLen = strlen(kPrefix); |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 188 i++; | 206 i++; |
| 189 } else { | 207 } else { |
| 190 vm_options->AddArgument(argv[i]); | 208 vm_options->AddArgument(argv[i]); |
| 191 i++; | 209 i++; |
| 192 } | 210 } |
| 193 } | 211 } |
| 194 if (generate_pprof_symbols_filename != NULL) { | 212 if (generate_pprof_symbols_filename != NULL) { |
| 195 Dart_InitPprofSupport(); | 213 Dart_InitPprofSupport(); |
| 196 } | 214 } |
| 197 | 215 |
| 216 if (flow_graph_file != NULL) { | |
| 217 Dart_InitFlowGraphPrinting(&WriteToFlowGraphFile); | |
| 218 } | |
| 219 | |
| 198 // Get the script name. | 220 // Get the script name. |
| 199 if (i < argc) { | 221 if (i < argc) { |
| 200 *script_name = argv[i]; | 222 *script_name = argv[i]; |
| 201 i++; | 223 i++; |
| 202 } else { | 224 } else { |
| 203 return -1; | 225 return -1; |
| 204 } | 226 } |
| 205 | 227 |
| 206 // Parse out options to be passed to dart main. | 228 // Parse out options to be passed to dart main. |
| 207 while (i < argc) { | 229 while (i < argc) { |
| (...skipping 550 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 758 DumpPprofSymbolInfo(); | 780 DumpPprofSymbolInfo(); |
| 759 // Shutdown the isolate. | 781 // Shutdown the isolate. |
| 760 Dart_ShutdownIsolate(); | 782 Dart_ShutdownIsolate(); |
| 761 // Terminate process exit-code handler. | 783 // Terminate process exit-code handler. |
| 762 Process::TerminateExitCodeHandler(); | 784 Process::TerminateExitCodeHandler(); |
| 763 | 785 |
| 764 free(const_cast<char*>(original_working_directory)); | 786 free(const_cast<char*>(original_working_directory)); |
| 765 | 787 |
| 766 return 0; | 788 return 0; |
| 767 } | 789 } |
| OLD | NEW |