Fix detaching a debugger while threads are suspended.
The interesting part of this change is in "thread_list.cc".
I've done a TODO in TagFromClass, but haven't seen it make any practical
difference in a debugger. I also tightened up the types in GetThreadStatus
while investigating the fact that we report some threads as "RUNNING, SUSPENDED",
which makes no sense until you realize that TS_RUNNING corresponds to both
our kRunnable thread state and our kNative thread state, the latter of which
may actually be a suspended thread.
I've also made us fail faster in the "address in use" jdwp failure case,
and tidied up a bunch of the capitalization in logging.
Change-Id: I0fe705791d07db31c4615addce44da4fdfbfd0d1
diff --git a/src/jdwp/jdwp_socket.cc b/src/jdwp/jdwp_socket.cc
index 351e456..b832133 100644
--- a/src/jdwp/jdwp_socket.cc
+++ b/src/jdwp/jdwp_socket.cc
@@ -80,7 +80,7 @@
}
};
-static JdwpNetState* netStartup(short port);
+static JdwpNetState* netStartup(short port, bool probe);
/*
* Set up some stuff for transport=dt_socket.
@@ -92,11 +92,11 @@
if (options->port != 0) {
/* try only the specified port */
port = options->port;
- state->netState = netStartup(port);
+ state->netState = netStartup(port, false);
} else {
/* scan through a range of ports, binding to the first available */
for (port = kBasePort; port <= kMaxPort; port++) {
- state->netState = netStartup(port);
+ state->netState = netStartup(port, true);
if (state->netState != NULL) {
break;
}
@@ -108,7 +108,7 @@
}
} else {
port = options->port; // used in a debug msg later
- state->netState = netStartup(-1);
+ state->netState = netStartup(-1, false);
}
if (options->suspend) {
@@ -139,10 +139,9 @@
*
* Returns 0 on success.
*/
-static JdwpNetState* netStartup(short port) {
+static JdwpNetState* netStartup(short port, bool probe) {
int one = 1;
JdwpNetState* netState = new JdwpNetState;
-
if (port < 0) {
return netState;
}
@@ -151,13 +150,13 @@
netState->listenSock = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
if (netState->listenSock < 0) {
- PLOG(ERROR) << "Socket create failed";
+ PLOG(probe ? ERROR : FATAL) << "Socket create failed";
goto fail;
}
/* allow immediate re-use */
if (setsockopt(netState->listenSock, SOL_SOCKET, SO_REUSEADDR, &one, sizeof(one)) < 0) {
- PLOG(ERROR) << "setsockopt(SO_REUSEADDR) failed";
+ PLOG(probe ? ERROR : FATAL) << "setsockopt(SO_REUSEADDR) failed";
goto fail;
}
@@ -170,15 +169,14 @@
inet_aton("127.0.0.1", &addr.addrInet.sin_addr);
if (bind(netState->listenSock, &addr.addrPlain, sizeof(addr)) != 0) {
- PLOG(VERBOSE) << "attempt to bind to port " << port << " failed";
+ PLOG(probe ? ERROR : FATAL) << "Attempt to bind to port " << port << " failed";
goto fail;
}
netState->listenPort = port;
- LOG(VERBOSE) << "+++ bound to port " << netState->listenPort;
if (listen(netState->listenSock, 5) != 0) {
- PLOG(ERROR) << "Listen failed";
+ PLOG(probe ? ERROR : FATAL) << "Listen failed";
goto fail;
}