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_adb.cc b/src/jdwp/jdwp_adb.cc
index f6b977e..eb6eec2 100644
--- a/src/jdwp/jdwp_adb.cc
+++ b/src/jdwp/jdwp_adb.cc
@@ -170,7 +170,7 @@
 
   if (ret <= 0) {
     if (ret < 0) {
-      PLOG(WARNING) << "receiving file descriptor from ADB failed (socket " << netState->controlSock << ")";
+      PLOG(WARNING) << "Receiving file descriptor from ADB failed (socket " << netState->controlSock << ")";
     }
     close(netState->controlSock);
     netState->controlSock = -1;
diff --git a/src/jdwp/jdwp_handler.cc b/src/jdwp/jdwp_handler.cc
index b30a6a2..a11c805 100644
--- a/src/jdwp/jdwp_handler.cc
+++ b/src/jdwp/jdwp_handler.cc
@@ -925,13 +925,13 @@
 
   LOG(VERBOSE) << StringPrintf("  Req for status of thread 0x%llx", threadId);
 
-  uint32_t threadStatus;
-  uint32_t suspendStatus;
+  JDWP::JdwpThreadStatus threadStatus;
+  JDWP::JdwpSuspendStatus suspendStatus;
   if (!Dbg::GetThreadStatus(threadId, &threadStatus, &suspendStatus)) {
     return ERR_INVALID_THREAD;
   }
 
-  LOG(VERBOSE) << "    --> " << JdwpThreadStatus(threadStatus) << ", " << JdwpSuspendStatus(suspendStatus);
+  LOG(VERBOSE) << "    --> " << threadStatus << ", " << suspendStatus;
 
   expandBufAdd4BE(pReply, threadStatus);
   expandBufAdd4BE(pReply, suspendStatus);
diff --git a/src/jdwp/jdwp_main.cc b/src/jdwp/jdwp_main.cc
index 98490e2..ad0610d 100644
--- a/src/jdwp/jdwp_main.cc
+++ b/src/jdwp/jdwp_main.cc
@@ -211,7 +211,7 @@
    * mid-request, though, we could see this.
    */
   if (eventThreadId != 0) {
-    LOG(WARNING) << "resetting state while event in progress";
+    LOG(WARNING) << "Resetting state while event in progress";
     DCHECK(false);
   }
 }
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;
   }