From 3be6e9d904baa13d7cf51dfc6742dea12e766b2e Mon Sep 17 00:00:00 2001 From: Sebastien Hertz Date: Thu, 5 Feb 2015 16:30:58 +0100 Subject: Read JDWP options from runtime Allocates JDWP::JdwpOptions on the heap and copies parsed options to avoid the need to include jdwp/jdwp.h into runtime.h file. Also does some minor cleanup and removes the old JDWP options parsing code that became dead code after we move it to the new command-line parser. Bug: 19275792 Change-Id: I71901c89fbf2cc3c1901a089e2a98b4326c6ee70 --- cmdline/cmdline_types.h | 53 ++++++++++++++++++++++++++++++++----------------- 1 file changed, 35 insertions(+), 18 deletions(-) (limited to 'cmdline') diff --git a/cmdline/cmdline_types.h b/cmdline/cmdline_types.h index 92210235e8..45f9b5635c 100644 --- a/cmdline/cmdline_types.h +++ b/cmdline/cmdline_types.h @@ -56,6 +56,23 @@ struct CmdlineType : CmdlineTypeParser { template <> struct CmdlineType : CmdlineTypeParser { + /* + * Handle one of the JDWP name/value pairs. + * + * JDWP options are: + * help: if specified, show help message and bail + * transport: may be dt_socket or dt_shmem + * address: for dt_socket, "host:port", or just "port" when listening + * server: if "y", wait for debugger to attach; if "n", attach to debugger + * timeout: how long to wait for debugger to connect / listen + * + * Useful with server=n (these aren't supported yet): + * onthrow=: connect to debugger when exception thrown + * onuncaught=y|n: connect to debugger when uncaught exception thrown + * launch=: launch the debugger itself + * + * The "transport" option is required, as is "address" if server=n. + */ Result Parse(const std::string& options) { VLOG(jdwp) << "ParseJdwpOptions: " << options; @@ -70,20 +87,20 @@ struct CmdlineType : CmdlineTypeParser { std::vector pairs; Split(options, ',', &pairs); - JDWP::JdwpOptions jdwp_options = JDWP::JdwpOptions(); + JDWP::JdwpOptions jdwp_options; std::stringstream error_stream; - for (size_t i = 0; i < pairs.size(); ++i) { - std::string::size_type equals = pairs[i].find('='); - if (equals == std::string::npos) { + for (const std::string& jdwp_option : pairs) { + std::string::size_type equals_pos = jdwp_option.find('='); + if (equals_pos == std::string::npos) { return Result::Failure(s + - "Can't parse JDWP option '" + pairs[i] + "' in '" + options + "'"); + "Can't parse JDWP option '" + jdwp_option + "' in '" + options + "'"); } - if (!ParseJdwpOption(pairs[i].substr(0, equals), - pairs[i].substr(equals + 1), + if (!ParseJdwpOption(jdwp_option.substr(0, equals_pos), + jdwp_option.substr(equals_pos + 1), error_stream, - jdwp_options)) { + &jdwp_options)) { return Result::Failure(error_stream.str()); } } @@ -100,30 +117,30 @@ struct CmdlineType : CmdlineTypeParser { bool ParseJdwpOption(const std::string& name, const std::string& value, std::ostream& error_stream, - JDWP::JdwpOptions& jdwp_options) { + JDWP::JdwpOptions* jdwp_options) { if (name == "transport") { if (value == "dt_socket") { - jdwp_options.transport = JDWP::kJdwpTransportSocket; + jdwp_options->transport = JDWP::kJdwpTransportSocket; } else if (value == "dt_android_adb") { - jdwp_options.transport = JDWP::kJdwpTransportAndroidAdb; + jdwp_options->transport = JDWP::kJdwpTransportAndroidAdb; } else { error_stream << "JDWP transport not supported: " << value; return false; } } else if (name == "server") { if (value == "n") { - jdwp_options.server = false; + jdwp_options->server = false; } else if (value == "y") { - jdwp_options.server = true; + jdwp_options->server = true; } else { error_stream << "JDWP option 'server' must be 'y' or 'n'"; return false; } } else if (name == "suspend") { if (value == "n") { - jdwp_options.suspend = false; + jdwp_options->suspend = false; } else if (value == "y") { - jdwp_options.suspend = true; + jdwp_options->suspend = true; } else { error_stream << "JDWP option 'suspend' must be 'y' or 'n'"; return false; @@ -131,10 +148,10 @@ struct CmdlineType : CmdlineTypeParser { } else if (name == "address") { /* this is either or : */ std::string port_string; - jdwp_options.host.clear(); + jdwp_options->host.clear(); std::string::size_type colon = value.find(':'); if (colon != std::string::npos) { - jdwp_options.host = value.substr(0, colon); + jdwp_options->host = value.substr(0, colon); port_string = value.substr(colon + 1); } else { port_string = value; @@ -149,7 +166,7 @@ struct CmdlineType : CmdlineTypeParser { error_stream << "JDWP address has junk in port field: " << value; return false; } - jdwp_options.port = port; + jdwp_options->port = port; } else if (name == "launch" || name == "onthrow" || name == "oncaught" || name == "timeout") { /* valid but unsupported */ LOG(INFO) << "Ignoring JDWP option '" << name << "'='" << value << "'"; -- cgit v1.2.3