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_handler.cc b/src/jdwp/jdwp_handler.cc
index e5e18bb..23637db 100644
--- a/src/jdwp/jdwp_handler.cc
+++ b/src/jdwp/jdwp_handler.cc
@@ -991,7 +991,7 @@
     return ERR_THREAD_NOT_SUSPENDED;
   }
 
-  int frameCount = Dbg::GetThreadFrameCount(threadId);
+  size_t frameCount = Dbg::GetThreadFrameCount(threadId);
 
   LOG(VERBOSE) << StringPrintf("  Request for frames: threadId=%llx start=%d length=%d [count=%d]", threadId, startFrame, length, frameCount);
   if (frameCount <= 0) {
@@ -1000,8 +1000,9 @@
   if (length == (uint32_t) -1) {
     length = frameCount;
   }
-  CHECK((int) startFrame >= 0 && (int) startFrame < frameCount);
-  CHECK_LE((int) (startFrame + length), frameCount);
+  CHECK_GE(startFrame, 0U);
+  CHECK_LT(startFrame, frameCount);
+  CHECK_LE(startFrame + length, frameCount);
 
   uint32_t frames = length;
   expandBufAdd4BE(pReply, frames);
@@ -1417,7 +1418,7 @@
   LOG(VERBOSE) << StringPrintf("    --> event requestId=%#x", requestId);
 
   /* add it to the list */
-  JdwpError err = RegisterEvent(state, pEvent);
+  JdwpError err = state->RegisterEvent(pEvent);
   if (err != ERR_NONE) {
     /* registration failed, probably because event is bogus */
     EventFree(pEvent);
@@ -1437,7 +1438,7 @@
 
   LOG(VERBOSE) << StringPrintf("  Req to clear eventKind=%d requestId=%#x", eventKind, requestId);
 
-  UnregisterEventById(state, requestId);
+  state->UnregisterEventById(requestId);
 
   return ERR_NONE;
 }