Makes objects known to the debugger GC roots, implements the THST message, and lets DDMS request stack traces.

This fills out correct data in all columns of the "Threads" table, and
double-clicking on a thread shows that thread's stack.

Change-Id: I48f63c3612e12d35269158dc3a283f07db28c8e7
diff --git a/src/stack.cc b/src/stack.cc
index 985fd38..1e1f932 100644
--- a/src/stack.cc
+++ b/src/stack.cc
@@ -18,6 +18,7 @@
 
 #include "compiler.h"
 #include "object.h"
+#include "thread_list.h"
 
 int oatVRegOffsetFromMethod(art::Method* method, int reg);
 
@@ -68,4 +69,34 @@
   return *reinterpret_cast<Method**>(next_sp);
 }
 
+class StackGetter {
+ public:
+  StackGetter(JNIEnv* env, Thread* thread) : env_(env), thread_(thread), trace_(NULL) {
+  }
+
+  static void Callback(void* arg) {
+    reinterpret_cast<StackGetter*>(arg)->Callback();
+  }
+
+  jobject GetTrace() {
+    return trace_;
+  }
+
+ private:
+  void Callback() {
+    trace_ = thread_->CreateInternalStackTrace(env_);
+  }
+
+  JNIEnv* env_;
+  Thread* thread_;
+  jobject trace_;
+};
+
+jobject GetThreadStack(JNIEnv* env, Thread* thread) {
+  ThreadList* thread_list = Runtime::Current()->GetThreadList();
+  StackGetter stack_getter(env, thread);
+  thread_list->RunWhileSuspended(thread, StackGetter::Callback, &stack_getter);
+  return stack_getter.GetTrace();
+}
+
 }  // namespace art