Fix ObjectReference.InvokeMethod.

This probably broke when I rewrote the object registry, but because
the test was so crap, we may have gotten away with passing bad pointers.
(Though for me, CheckJNI was catching this.)

While I'm here, fix the argument checking, which was previously
very weak; we'd accept any reference type rather than instances of
the parameter's specific type.

Change-Id: I08c001cabde02a0509fe28df17523a2d2519d1ca
diff --git a/src/debugger.cc b/src/debugger.cc
index 64be25c..fdab63a 100644
--- a/src/debugger.cc
+++ b/src/debugger.cc
@@ -2690,10 +2690,27 @@
       return JDWP::ERR_ILLEGAL_ARGUMENT;
     }
     const char* shorty = mh.GetShorty();
+    const DexFile::TypeList* types = mh.GetParameterTypeList();
     for (size_t i = 0; i < arg_count; ++i) {
       if (shorty[i + 1] != JdwpTagToShortyChar(arg_types[i])) {
         return JDWP::ERR_ILLEGAL_ARGUMENT;
       }
+
+      if (shorty[i + 1] == 'L') {
+        // Did we really get an argument of an appropriate reference type?
+        mirror::Class* parameter_type = mh.GetClassFromTypeIdx(types->GetTypeItem(i).type_idx_);
+        mirror::Object* argument = gRegistry->Get<mirror::Object*>(arg_values[i]);
+        if (argument == ObjectRegistry::kInvalidObject) {
+          return JDWP::ERR_INVALID_OBJECT;
+        }
+        if (!argument->InstanceOf(parameter_type)) {
+          return JDWP::ERR_ILLEGAL_ARGUMENT;
+        }
+
+        // Turn the on-the-wire ObjectId into a jobject.
+        jvalue& v = reinterpret_cast<jvalue&>(arg_values[i]);
+        v.l = gRegistry->GetJObject(arg_values[i]);
+      }
     }
 
     req->receiver_ = receiver;