Merge "Fix thread status in THST chunk to use JDWP thread state." into dalvik-dev
diff --git a/runtime/debugger.cc b/runtime/debugger.cc
index a72ae22..e01857f 100644
--- a/runtime/debugger.cc
+++ b/runtime/debugger.cc
@@ -1661,6 +1661,38 @@
   return gRegistry->Add(group);
 }
 
+JDWP::JdwpThreadStatus Dbg::ToJdwpThreadStatus(ThreadState state) {
+  switch (state) {
+    case kBlocked:
+      return JDWP::TS_MONITOR;
+    case kNative:
+    case kRunnable:
+    case kSuspended:
+      return JDWP::TS_RUNNING;
+    case kSleeping:
+      return JDWP::TS_SLEEPING;
+    case kStarting:
+    case kTerminated:
+      return JDWP::TS_ZOMBIE;
+    case kTimedWaiting:
+    case kWaitingForDebuggerSend:
+    case kWaitingForDebuggerSuspension:
+    case kWaitingForDebuggerToAttach:
+    case kWaitingForGcToComplete:
+    case kWaitingForCheckPointsToRun:
+    case kWaitingForJniOnLoad:
+    case kWaitingForSignalCatcherOutput:
+    case kWaitingInMainDebuggerLoop:
+    case kWaitingInMainSignalCatcherLoop:
+    case kWaitingPerformingGc:
+    case kWaiting:
+      return JDWP::TS_WAIT;
+      // Don't add a 'default' here so the compiler can spot incompatible enum changes.
+  }
+  LOG(FATAL) << "Unknown thread state: " << state;
+  return JDWP::TS_ZOMBIE;
+}
+
 JDWP::JdwpError Dbg::GetThreadStatus(JDWP::ObjectId thread_id, JDWP::JdwpThreadStatus* pThreadStatus, JDWP::JdwpSuspendStatus* pSuspendStatus) {
   ScopedObjectAccess soa(Thread::Current());
 
@@ -1681,28 +1713,7 @@
     *pSuspendStatus = JDWP::SUSPEND_STATUS_SUSPENDED;
   }
 
-  switch (thread->GetState()) {
-    case kBlocked:                        *pThreadStatus = JDWP::TS_MONITOR;  break;
-    case kNative:                         *pThreadStatus = JDWP::TS_RUNNING;  break;
-    case kRunnable:                       *pThreadStatus = JDWP::TS_RUNNING;  break;
-    case kSleeping:                       *pThreadStatus = JDWP::TS_SLEEPING; break;
-    case kStarting:                       *pThreadStatus = JDWP::TS_ZOMBIE;   break;
-    case kSuspended:                      *pThreadStatus = JDWP::TS_RUNNING;  break;
-    case kTerminated:                     *pThreadStatus = JDWP::TS_ZOMBIE;   break;
-    case kTimedWaiting:                   *pThreadStatus = JDWP::TS_WAIT;     break;
-    case kWaitingForDebuggerSend:         *pThreadStatus = JDWP::TS_WAIT;     break;
-    case kWaitingForDebuggerSuspension:   *pThreadStatus = JDWP::TS_WAIT;     break;
-    case kWaitingForDebuggerToAttach:     *pThreadStatus = JDWP::TS_WAIT;     break;
-    case kWaitingForGcToComplete:         *pThreadStatus = JDWP::TS_WAIT;     break;
-    case kWaitingForCheckPointsToRun:     *pThreadStatus = JDWP::TS_WAIT;     break;
-    case kWaitingForJniOnLoad:            *pThreadStatus = JDWP::TS_WAIT;     break;
-    case kWaitingForSignalCatcherOutput:  *pThreadStatus = JDWP::TS_WAIT;     break;
-    case kWaitingInMainDebuggerLoop:      *pThreadStatus = JDWP::TS_WAIT;     break;
-    case kWaitingInMainSignalCatcherLoop: *pThreadStatus = JDWP::TS_WAIT;     break;
-    case kWaitingPerformingGc:            *pThreadStatus = JDWP::TS_WAIT;     break;
-    case kWaiting:                        *pThreadStatus = JDWP::TS_WAIT;     break;
-    // Don't add a 'default' here so the compiler can spot incompatible enum changes.
-  }
+  *pThreadStatus = ToJdwpThreadStatus(thread->GetState());
   return JDWP::ERR_NONE;
 }
 
diff --git a/runtime/debugger.h b/runtime/debugger.h
index 2282305..d0fe445 100644
--- a/runtime/debugger.h
+++ b/runtime/debugger.h
@@ -29,6 +29,7 @@
 #include "jni.h"
 #include "jvalue.h"
 #include "root_visitor.h"
+#include "thread_state.h"
 
 namespace art {
 namespace mirror {
@@ -268,6 +269,7 @@
       SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
   static JDWP::ObjectId GetMainThreadGroupId();
 
+  static JDWP::JdwpThreadStatus ToJdwpThreadStatus(ThreadState state);
   static JDWP::JdwpError GetThreadStatus(JDWP::ObjectId thread_id, JDWP::JdwpThreadStatus* pThreadStatus, JDWP::JdwpSuspendStatus* pSuspendStatus);
   static JDWP::JdwpError GetThreadDebugSuspendCount(JDWP::ObjectId thread_id, JDWP::ExpandBuf* pReply);
   // static void WaitForSuspend(JDWP::ObjectId thread_id);
diff --git a/runtime/native/org_apache_harmony_dalvik_ddmc_DdmVmInternal.cc b/runtime/native/org_apache_harmony_dalvik_ddmc_DdmVmInternal.cc
index 5ba2994..13cd978 100644
--- a/runtime/native/org_apache_harmony_dalvik_ddmc_DdmVmInternal.cc
+++ b/runtime/native/org_apache_harmony_dalvik_ddmc_DdmVmInternal.cc
@@ -114,7 +114,7 @@
 
   std::vector<uint8_t>& bytes = *reinterpret_cast<std::vector<uint8_t>*>(context);
   JDWP::Append4BE(bytes, t->GetThinLockId());
-  JDWP::Append1BE(bytes, t->GetState());
+  JDWP::Append1BE(bytes, Dbg::ToJdwpThreadStatus(t->GetState()));
   JDWP::Append4BE(bytes, t->GetTid());
   JDWP::Append4BE(bytes, utime);
   JDWP::Append4BE(bytes, stime);