18#if !defined(DART_IO_SECURE_SOCKET_DISABLED)
40 "error",
"warning",
"info",
"all",
nullptr,
45bool Options::enable_vm_service_ =
false;
47#define OPTION_FIELD(variable) Options::variable##_
49#define STRING_OPTION_DEFINITION(name, variable) \
50 const char* OPTION_FIELD(variable) = nullptr; \
51 DEFINE_STRING_OPTION(name, OPTION_FIELD(variable))
53#undef STRING_OPTION_DEFINITION
55#define BOOL_OPTION_DEFINITION(name, variable) \
56 bool OPTION_FIELD(variable) = false; \
57 DEFINE_BOOL_OPTION(name, OPTION_FIELD(variable))
62#undef BOOL_OPTION_DEFINITION
64#define SHORT_BOOL_OPTION_DEFINITION(short_name, long_name, variable) \
65 bool OPTION_FIELD(variable) = false; \
66 DEFINE_BOOL_OPTION_SHORT(short_name, long_name, OPTION_FIELD(variable))
68#undef SHORT_BOOL_OPTION_DEFINITION
70#define ENUM_OPTION_DEFINITION(name, type, variable) \
71 DEFINE_ENUM_OPTION(name, type, OPTION_FIELD(variable))
73#undef ENUM_OPTION_DEFINITION
75#define CB_OPTION_DEFINITION(callback) \
76 static bool callback##Helper(const char* arg, CommandLineOptions* o) { \
77 return Options::callback(arg, o); \
79 DEFINE_CB_OPTION(callback##Helper)
81#undef CB_OPTION_DEFINITION
83#if !defined(DART_PRECOMPILED_RUNTIME)
84DFE* Options::dfe_ =
nullptr;
95 vm_options->
AddArgument(
"--reload_every_optimized=false");
100#if !defined(DART_PRECOMPILED_RUNTIME)
114 vm_options->
AddArgument(
"--reload_every_optimized=false");
116 vm_options->
AddArgument(
"--reload_every_back_off");
120 vm_options->
AddArgument(
"--reload_force_rollback");
121#if !defined(DART_PRECOMPILED_RUNTIME)
136 "Usage: dart [<vm-flags>] <dart-script-file> [<script-arguments>]\n"
138 "Executes the Dart script <dart-script-file> with "
139 "the given list of <script-arguments>.\n"
141 if (!Options::verbose_option()) {
146" Enable assert statements.\n"
149" Display this message (add -v or --verbose for information about\n"
152" Where to find a package spec file.\n"
153"--define=<key>=<value> or -D<key>=<value>\n"
154" Define an environment declaration. To specify multiple declarations,\n"
155" use multiple instances of this option.\n"
157"--observe[=<port>[/<bind-address>]]\n"
158" The observe flag is a convenience flag used to run a program with a\n"
159" set of options which are often useful for debugging under Observatory.\n"
160" These options are currently:\n"
161" --enable-vm-service[=<port>[/<bind-address>]]\n"
163" --pause-isolates-on-exit\n"
164" --pause-isolates-on-unhandled-exceptions\n"
165" --warn-on-pause-with-no-debugger\n"
166" --timeline-streams=\"Compiler, Dart, GC\"\n"
167" This set is subject to change.\n"
168" Please see these options (--help --verbose) for further documentation.\n"
169"--write-service-info=<file_uri>\n"
170" Outputs information necessary to connect to the VM service to the\n"
171" specified file in JSON format. Useful for clients which are unable to\n"
172" listen to stdout for the Dart VM service listening message.\n"
174"--snapshot-kind=<snapshot_kind>\n"
175"--snapshot=<file_name>\n"
176" These snapshot options are used to generate a snapshot of the loaded\n"
178" <snapshot-kind> controls the kind of snapshot, it could be\n"
179" kernel(default) or app-jit\n"
180" <file_name> specifies the file into which the snapshot is written\n"
182" Print the SDK version.\n");
185"Supported options:\n"
188" Enable assert statements.\n"
191" Display this message (add -v or --verbose for information about\n"
194" Where to find a package spec file.\n"
195"--define=<key>=<value> or -D<key>=<value>\n"
196" Define an environment declaration. To specify multiple declarations,\n"
197" use multiple instances of this option.\n"
199"--observe[=<port>[/<bind-address>]]\n"
200" The observe flag is a convenience flag used to run a program with a\n"
201" set of options which are often useful for debugging under Observatory.\n"
202" These options are currently:\n"
203" --enable-vm-service[=<port>[/<bind-address>]]\n"
205" --pause-isolates-on-exit\n"
206" --pause-isolates-on-unhandled-exceptions\n"
207" --warn-on-pause-with-no-debugger\n"
208" --timeline-streams=\"Compiler, Dart, GC\"\n"
209" This set is subject to change.\n"
210" Please see these options for further documentation.\n"
213" Print the VM version.\n"
216" enables tracing of library and script loading\n"
219"--enable-vm-service[=<port>[/<bind-address>]]\n"
220" Enables the VM service and listens on specified port for connections\n"
221" (default port number is 8181, default bind address is localhost).\n"
223"--disable-service-auth-codes\n"
224" Disables the requirement for an authentication code to communicate with\n"
225" the VM service. Authentication codes help protect against CSRF attacks,\n"
226" so it is not recommended to disable them unless behind a firewall on a\n"
229"--enable-service-port-fallback\n"
230" When the VM service is told to bind to a particular port, fallback to 0 if\n"
231" it fails to bind instead of failing to start.\n"
234"--root-certs-file=<path>\n"
235" The path to a file containing the trusted root certificates to use for\n"
236" secure socket connections.\n"
237"--root-certs-cache=<path>\n"
238" The path to a cache directory containing the trusted root certificates to\n"
239" use for secure socket connections.\n"
240#
if defined(DART_HOST_OS_LINUX) || \
241 defined(DART_HOST_OS_ANDROID) || \
242 defined(DART_HOST_OS_FUCHSIA)
243"--namespace=<path>\n"
244" The path to a directory that dart:io calls will treat as the root of the\n"
248"The following options are only used for VM development and may\n"
249"be changed in any future version:\n");
250 const char* print_flags =
"--print_flags";
261 &Options::environment_);
265#if defined(DART_PRECOMPILED_RUNTIME)
268 DestroyEnvironment();
271void Options::DestroyEnvironment() {
272 if (environment_ !=
nullptr) {
274 p = environment_->
Next(
p)) {
279 environment_ =
nullptr;
283#if defined(DART_PRECOMPILED_RUNTIME)
291char** Options::GetEnvArguments(
int* argc) {
293 const char* env_args_str =
std::getenv(
"DART_VM_OPTIONS");
294 if (env_args_str ==
nullptr) {
299 intptr_t n = strlen(env_args_str);
311 for (
int i = 0;
i < n; ++
i) {
313 if (env_args_str[
i] ==
',' &&
i + 1 != n) {
318 env_argv_ =
new char*[arg_count];
319 env_argc_ = arg_count;
324 char* rest =
const_cast<char*
>(env_args_str);
327 while ((token = strtok_r(rest,
",", &rest)) !=
nullptr) {
336char** Options::env_argv_ =
nullptr;
337int Options::env_argc_ = 0;
339void Options::DestroyEnvArgv() {
340 for (
int i = 0;
i < env_argc_; ++
i) {
348bool Options::ExtractPortAndAddress(
const char* option_value,
352 const char* default_ip) {
361 if (*option_value ==
'\0') {
362 *out_ip = default_ip;
363 *out_port = default_port;
367 if ((*option_value !=
'=') && (*option_value !=
':')) {
371 int port = atoi(option_value + 1);
372 const char* slash = strstr(option_value,
"/");
373 if (slash ==
nullptr) {
374 *out_ip = default_ip;
386static bool IsOption(
const char* arg,
const char* option) {
387 if (arg[0] !=
'-' || arg[1] !=
'-') {
391 for (
int i = 0; option[
i] !=
'\0';
i++) {
397 if ((c ==
'_' ?
'-' : c) != option[
i]) {
406bool Options::ProcessEnableVmServiceOption(
const char* arg,
407 CommandLineOptions* vm_options) {
411 if (
value ==
nullptr) {
414 if (!ExtractPortAndAddress(
415 value, &vm_service_server_port_, &vm_service_server_ip_,
418 "unrecognized --enable-vm-service option syntax. "
419 "Use --enable-vm-service[=<port number>[/<bind address>]]\n");
422#if !defined(DART_PRECOMPILED_RUNTIME)
425 enable_vm_service_ =
true;
433bool Options::ProcessObserveOption(
const char* arg,
434 CommandLineOptions* vm_options) {
437 if (
value ==
nullptr) {
440 if (!ExtractPortAndAddress(
441 value, &vm_service_server_port_, &vm_service_server_ip_,
444 "unrecognized --observe option syntax. "
445 "Use --observe[=<port number>[/<bind address>]]\n");
450 vm_options->AddArgument(
"--pause-isolates-on-exit");
451 vm_options->AddArgument(
"--pause-isolates-on-unhandled-exceptions");
452 vm_options->AddArgument(
"--profiler");
453 vm_options->AddArgument(
"--warn-on-pause-with-no-debugger");
454 vm_options->AddArgument(
"--timeline-streams=\"Compiler,Dart,GC\"");
455#if !defined(DART_PRECOMPILED_RUNTIME)
458 enable_vm_service_ =
true;
467bool Options::ProcessVMDebuggingOptions(
const char* arg,
468 CommandLineOptions* vm_options) {
469#define IS_DEBUG_OPTION(name, arg) \
470 if (strncmp(name, arg, strlen(name)) == 0) { \
471 vm_options->AddArgument(arg); \
481#define HANDLE_DARTDEV_VM_DEBUG_OPTIONS(V, arg) \
482 V("--enable-asserts", arg) \
483 V("--pause-isolates-on-exit", arg) \
484 V("--no-pause-isolates-on-exit", arg) \
485 V("--pause-isolates-on-start", arg) \
486 V("--no-pause-isolates-on-start", arg) \
487 V("--pause-isolates-on-unhandled-exception", arg) \
488 V("--no-pause-isolates-on-unhandled-exception", arg) \
489 V("--warn-on-pause-with-no-debugger", arg) \
490 V("--no-warn-on-pause-with-no-debugger", arg) \
491 V("--timeline-streams", arg) \
492 V("--timeline-recorder", arg) \
493 V("--enable-experiment", arg)
496#undef IS_DEBUG_OPTION
497#undef HANDLE_DARTDEV_VM_DEBUG_OPTIONS
505 bool parsing_dart_vm_options,
509 bool* print_flags_seen,
510 bool* verbose_debug_seen) {
512#if !defined(DART_PRECOMPILED_RUNTIME)
514 ASSERT(!parsing_dart_vm_options);
516 if (!parsing_dart_vm_options) {
526 bool enable_dartdev_analytics =
false;
527 bool disable_dartdev_analytics =
false;
528 char* packages_argument =
nullptr;
532 bool skipVmOption =
false;
541 *print_flags_seen =
true;
543 *verbose_debug_seen =
true;
545 enable_dartdev_analytics =
true;
548 disable_dartdev_analytics =
true;
551 disable_dartdev_analytics =
true;
576 packages_argument =
argv[
i];
581#if !defined(DART_PRECOMPILED_RUNTIME)
585 Options::disable_dart_dev_ =
true;
587 if (Options::deterministic()) {
594#if !defined(DART_IO_SECURE_SOCKET_DISABLED)
598 Options::long_ssl_cert_evaluation());
600 Options::bypass_trusting_system_roots());
604 Options::delayed_filewatch_callback());
609 bool implicitly_use_dart_dev =
false;
610 bool run_script =
false;
613#if !defined(DART_PRECOMPILED_RUNTIME)
620 bool is_potential_file_path =
true;
622 if (Options::disable_dart_dev() ||
623 (Options::snapshot_filename() !=
nullptr) ||
624 (is_potential_file_path && !enable_vm_service_)) {
629#if !defined(DART_PRECOMPILED_RUNTIME)
633 if (!Options::disable_dart_dev() && enable_vm_service_) {
638 if (is_potential_file_path) {
639 implicitly_use_dart_dev =
true;
644#if !defined(DART_PRECOMPILED_RUNTIME)
645 else if (!Options::disable_dart_dev()) {
650 if (((Options::help_option() && !Options::verbose_option()) ||
659 else if (enable_dartdev_analytics || disable_dartdev_analytics) {
664 ?
"--enable-analytics"
665 :
"--disable-analytics");
671 else if (!Options::help_option() && !Options::version_option()) {
680 else if (!parsing_dart_vm_options || Options::help_option() ||
681 Options::version_option()) {
684 USE(enable_dartdev_analytics);
685 USE(disable_dartdev_analytics);
686 USE(packages_argument);
688 const char** vm_argv = temp_vm_options.
arguments();
689 int vm_argc = temp_vm_options.
count();
693#if !defined(DART_PRECOMPILED_RUNTIME)
696 if (parsing_dart_vm_options) {
709 if (!implicitly_use_dart_dev) {
712 while (tmp_i < argc) {
723 bool first_option =
true;
726 if (implicitly_use_dart_dev && first_option) {
750#if !defined(DART_PRECOMPILED_RUNTIME)
753 packages_argument !=
nullptr) {
757 first_option =
false;
764 if ((snapshot_deps_filename_ !=
nullptr) && (depfile_ !=
nullptr)) {
768 if (snapshot_deps_filename_ !=
nullptr) {
769 depfile_ = snapshot_deps_filename_;
770 snapshot_deps_filename_ =
nullptr;
773 if ((packages_file_ !=
nullptr) && (strlen(packages_file_) == 0)) {
777 if ((gen_snapshot_kind_ !=
kNone) && (snapshot_filename_ ==
nullptr)) {
779 "Generating a snapshot requires a filename (--snapshot).\n");
782 if ((gen_snapshot_kind_ ==
kNone) && (depfile_ !=
nullptr) &&
783 (snapshot_filename_ ==
nullptr) &&
784 (depfile_output_filename_ ==
nullptr)) {
786 "Generating a depfile requires an output filename"
787 " (--depfile-output-filename or --snapshot).\n");
792 "Specifying an option to generate a snapshot and"
793 " run using a snapshot is invalid.\n");
798 if ((snapshot_filename_ !=
nullptr) && (gen_snapshot_kind_ ==
kNone)) {
Entry * Next(Entry *p) const
static void PrintErr(const char *format,...) PRINTF_ATTRIBUTE(1
static void Print(const char *format,...) PRINTF_ATTRIBUTE(1
static char * StrDup(const char *s)
static char * StrNDup(const char *s, intptr_t n)
const char ** arguments() const
void AddArguments(const char **argv, int argc)
void AddArgument(const char *argument)
void set_use_dfe(bool value=true)
void set_frontend_filename(const char *name)
void set_use_incremental_compiler(bool value)
static bool should_run_dart_dev()
static void PrintUsageErrorOnRun()
static void set_should_run_dart_dev(bool enable)
static bool ShouldParseCommand(const char *script_uri)
static void set_delayed_filewatch_callback(bool value)
static bool TryProcess(const char *option, CommandLineOptions *options)
static bool IsValidShortFlag(const char *name)
static const char * ProcessOption(const char *option, const char *name)
static bool ProcessEnvironmentOption(const char *arg, CommandLineOptions *vm_options, dart::SimpleHashMap **environment)
static bool IsValidFlag(const char *name)
static void PrintVersion()
static bool ParseArguments(int argc, char **argv, bool vm_run_app_snapshot, bool parsing_dart_vm_options, CommandLineOptions *vm_options, char **script_name, CommandLineOptions *dart_options, bool *print_flags_seen, bool *verbose_debug_seen)
static void set_long_ssl_cert_evaluation(bool long_ssl_cert_evaluation)
static void set_bypass_trusting_system_roots(bool bypass_trusting_system_roots)
static void set_root_certs_file(const char *root_certs_file)
static void set_root_certs_cache(const char *root_certs_cache)
static void set_short_socket_read(bool short_socket_read)
static void set_short_socket_write(bool short_socket_write)
const uint8_t uint32_t uint32_t GError ** error
#define BOOL_OPTIONS_LIST(V)
#define STRING_OPTIONS_LIST(V)
#define ENUM_OPTION_DEFINITION(name, type, variable)
#define HANDLE_DARTDEV_VM_DEBUG_OPTIONS(V, arg)
#define IS_DEBUG_OPTION(name, arg)
#define SHORT_BOOL_OPTION_DEFINITION(short_name, long_name, variable)
#define STRING_OPTION_DEFINITION(name, variable)
#define BOOL_OPTION_DEFINITION(name, variable)
#define CB_OPTION_DEFINITION(callback)
#define DEBUG_BOOL_OPTIONS_LIST(V)
#define ENUM_OPTIONS_LIST(V)
#define SHORT_BOOL_OPTIONS_LIST(V)
#define CB_OPTIONS_LIST(V)
static bool IsOption(const char *arg, const char *option)
static const char *const kVerbosityLevelNames[]
DEFINE_BOOL_OPTION_CB(hot_reload_test_mode, hot_reload_test_mode_callback)
DEFINE_STRING_OPTION_CB(dfe, { Options::dfe() ->set_frontend_filename(value);})
static bool ProcessEnvironmentOption(const char *arg, CommandLineOptions *vm_options)
static bool vm_run_app_snapshot
static void hot_reload_rollback_test_mode_callback(CommandLineOptions *vm_options)
static constexpr const char * DEFAULT_VM_SERVICE_SERVER_IP
static constexpr int DEFAULT_VM_SERVICE_SERVER_PORT
static void hot_reload_test_mode_callback(CommandLineOptions *vm_options)
static constexpr int INVALID_VM_SERVICE_SERVER_PORT
static const char *const kSnapshotKindNames[]
DART_EXPORT const char * Dart_VersionString()
DART_EXPORT char * Dart_SetVMFlags(int argc, const char **argv)
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir Path to the cache directory This is different from the persistent_cache_path in embedder which is used for Skia shader cache icu native lib Path to the library file that exports the ICU data vm service The hostname IP address on which the Dart VM Service should be served If not defaults to or::depending on whether ipv6 is specified vm service port