Implement a bit more debugger functionality.

This fixes the deadlock by making SuspendSelfForDebugger not take the thread
list lock, making it more like the equivalent code in dalvikvm.

There's also some code cleanup, and a few more of the JDWP calls jdb makes
on startup. By fixing the deadlock, attaching jdb now causes us to hit
unimplemented code relating to thread stacks. That's tomorrow's job...

Change-Id: I7eac1b95946228fa60666587ff8766bcabb28bb1
diff --git a/src/jdwp/jdwp_main.cc b/src/jdwp/jdwp_main.cc
index fa02895..12b689c 100644
--- a/src/jdwp/jdwp_main.cc
+++ b/src/jdwp/jdwp_main.cc
@@ -118,7 +118,7 @@
   /* comment this out when debugging JDWP itself */
   //android_setMinPriority(LOG_TAG, ANDROID_LOG_DEBUG);
 
-  JdwpState* state = new JdwpState(options);
+  UniquePtr<JdwpState> state(new JdwpState(options));
   switch (options->transport) {
   case kJdwpTransportSocket:
     // LOGD("prepping for JDWP over TCP");
@@ -134,8 +134,8 @@
     LOG(FATAL) << "Unknown transport: " << options->transport;
   }
 
-  if (!(*state->transport->startup)(state, options)) {
-    goto fail;
+  if (!(*state->transport->startup)(state.get(), options)) {
+    return NULL;
   }
 
   /*
@@ -151,7 +151,7 @@
    * We have bound to a port, or are trying to connect outbound to a
    * debugger.  Create the JDWP thread and let it continue the mission.
    */
-  CHECK_PTHREAD_CALL(pthread_create, (&state->pthread_, NULL, StartJdwpThread, state), "JDWP thread");
+  CHECK_PTHREAD_CALL(pthread_create, (&state->pthread_, NULL, StartJdwpThread, state.get()), "JDWP thread");
 
   /*
    * Wait until the thread finishes basic initialization.
@@ -178,7 +178,7 @@
 
     if (!state->IsActive()) {
       LOG(ERROR) << "JDWP connection failed";
-      goto fail;
+      return NULL;
     }
 
     LOG(INFO) << "JDWP connected";
@@ -190,11 +190,7 @@
      */
   }
 
-  return state;
-
-fail:
-  delete state;     // frees state
-  return NULL;
+  return state.release();
 }
 
 /*
@@ -207,7 +203,7 @@
 void JdwpState::ResetState() {
   /* could reset the serial numbers, but no need to */
 
-  UnregisterAll(this);
+  UnregisterAll();
   CHECK(eventList == NULL);
 
   /*