Move super class verification to class linker

Verify super classes in the class linker and chain exceptions when super
class verification fails. Add support for dumping chained exceptions to
Throwable::Dump. Improve verifier error detail messages.

Fixes problem where super class verification would leave a pending
exception that would be tripped over elsewhere.

Change-Id: I3ca850fc66674c8601132d7ec40bebbf9c108ae3
diff --git a/src/object.cc b/src/object.cc
index 7f6e451..f90031a 100644
--- a/src/object.cc
+++ b/src/object.cc
@@ -1337,6 +1337,13 @@
   return result;
 }
 
+void Throwable::SetCause(Throwable* cause) {
+  CHECK(cause != NULL);
+  CHECK(cause != this);
+  CHECK(GetFieldObject<Throwable*>(OFFSET_OF_OBJECT_MEMBER(Throwable, cause_), false) == NULL);
+  SetFieldObject(OFFSET_OF_OBJECT_MEMBER(Throwable, cause_), cause, false);
+}
+
 bool Throwable::IsCheckedException() const {
   Class* error = Runtime::Current()->GetClassLinker()->FindSystemClass("Ljava/lang/Error;");
   if (InstanceOf(error)) {
@@ -1367,6 +1374,11 @@
       result += "\n";
     }
   }
+  Throwable* cause = GetFieldObject<Throwable*>(OFFSET_OF_OBJECT_MEMBER(Throwable, cause_), false);
+  if (cause != NULL) {
+    result += "Caused by: ";
+    result += cause->Dump();
+  }
   return result;
 }