summaryrefslogtreecommitdiffstats
path: root/cmdline
diff options
context:
space:
mode:
authorSebastien Hertz <shertz@google.com>2015-02-05 16:30:58 +0100
committerSebastien Hertz <shertz@google.com>2015-02-05 18:28:54 +0100
commit3be6e9d904baa13d7cf51dfc6742dea12e766b2e (patch)
tree43ad5f3655d73243ab212eefb83169471a1d87b3 /cmdline
parent24898d447640c3a45e6fc9f404b049eddc5a2709 (diff)
downloadart-3be6e9d904baa13d7cf51dfc6742dea12e766b2e.zip
art-3be6e9d904baa13d7cf51dfc6742dea12e766b2e.tar.gz
art-3be6e9d904baa13d7cf51dfc6742dea12e766b2e.tar.bz2
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
Diffstat (limited to 'cmdline')
-rw-r--r--cmdline/cmdline_types.h53
1 files changed, 35 insertions, 18 deletions
diff --git a/cmdline/cmdline_types.h b/cmdline/cmdline_types.h
index 9221023..45f9b56 100644
--- a/cmdline/cmdline_types.h
+++ b/cmdline/cmdline_types.h
@@ -56,6 +56,23 @@ struct CmdlineType<Unit> : CmdlineTypeParser<Unit> {
template <>
struct CmdlineType<JDWP::JdwpOptions> : CmdlineTypeParser<JDWP::JdwpOptions> {
+ /*
+ * 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=<exception-name>: connect to debugger when exception thrown
+ * onuncaught=y|n: connect to debugger when uncaught exception thrown
+ * launch=<command-line>: 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<JDWP::JdwpOptions> : CmdlineTypeParser<JDWP::JdwpOptions> {
std::vector<std::string> 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<JDWP::JdwpOptions> : CmdlineTypeParser<JDWP::JdwpOptions> {
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<JDWP::JdwpOptions> : CmdlineTypeParser<JDWP::JdwpOptions> {
} else if (name == "address") {
/* this is either <port> or <host>:<port> */
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<JDWP::JdwpOptions> : CmdlineTypeParser<JDWP::JdwpOptions> {
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 << "'";