[sdb] Allow boxed vtypes as this when invoking vtype methods. Fixes #30023.
authorZoltan Varga <vargaz@gmail.com>
Wed, 8 Jul 2015 21:09:08 +0000 (17:09 -0400)
committerZoltan Varga <vargaz@gmail.com>
Wed, 8 Jul 2015 21:09:32 +0000 (17:09 -0400)
mcs/class/Mono.Debugger.Soft/Test/dtest.cs
mono/mini/debugger-agent.c

index f00aad4ece07d391067354372d2da3eae945a29e..641fefd2afe9c647385e3ad22f0e18a355ee6f2e 100644 (file)
@@ -2286,6 +2286,12 @@ public class DebuggerTests
                v = s.InvokeMethod (e.Thread, m, null);
                AssertValue (42, v);
 
+               // Pass boxed struct as this
+               var boxed_this = t.NewInstance () as ObjectMirror;
+               m = t.GetMethod ("invoke_return_int");
+               v = boxed_this.InvokeMethod (e.Thread, m, null);
+               AssertValue (0, v);
+
                // Pass struct as this, receive intptr
                m = t.GetMethod ("invoke_return_intptr");
                v = s.InvokeMethod (e.Thread, m, null);
index 665df3ee6c11a8e5413ae8711914bda7b177f66a..2a52f825d9bef37957ef6702c8f691ee8b61c831 100644 (file)
@@ -5956,7 +5956,8 @@ decode_value_internal (MonoType *t, int type, MonoDomain *domain, guint8 *addr,
                !(t->type == MONO_TYPE_I && type == MONO_TYPE_VALUETYPE) &&
                !(t->type == MONO_TYPE_U && type == MONO_TYPE_VALUETYPE) &&
                !(t->type == MONO_TYPE_PTR && type == MONO_TYPE_I8) &&
-               !(t->type == MONO_TYPE_GENERICINST && type == MONO_TYPE_VALUETYPE)) {
+               !(t->type == MONO_TYPE_GENERICINST && type == MONO_TYPE_VALUETYPE) &&
+               !(t->type == MONO_TYPE_VALUETYPE && type == MONO_TYPE_OBJECT)) {
                char *name = mono_type_full_name (t);
                DEBUG_PRINTF (1, "[%p] Expected value of type %s, got 0x%0x.\n", (gpointer)GetCurrentThreadId (), name, type);
                g_free (name);
@@ -6020,9 +6021,27 @@ decode_value_internal (MonoType *t, int type, MonoDomain *domain, guint8 *addr,
                /* Fall through */
                handle_vtype:
        case MONO_TYPE_VALUETYPE:
-               err = decode_vtype (t, domain, addr,buf, &buf, limit);
-               if (err)
-                       return err;
+               if (type == MONO_TYPE_OBJECT) {
+                       /* Boxed vtype */
+                       int objid = decode_objid (buf, &buf, limit);
+                       int err;
+                       MonoObject *obj;
+
+                       err = get_object (objid, (MonoObject**)&obj);
+                       if (err)
+                               return err;
+                       if (!obj)
+                               return ERR_INVALID_ARGUMENT;
+                       if (obj->vtable->klass != mono_class_from_mono_type (t)) {
+                               DEBUG_PRINTF (1, "Expected type '%s', got object '%s'\n", mono_type_full_name (t), obj->vtable->klass->name);
+                               return ERR_INVALID_ARGUMENT;
+                       }
+                       memcpy (addr, mono_object_unbox (obj), mono_class_value_size (obj->vtable->klass, NULL));
+               } else {
+                       err = decode_vtype (t, domain, addr, buf, &buf, limit);
+                       if (err)
+                               return err;
+               }
                break;
        handle_ref:
        default: