[Coop] Debugger single point of exit. (mono/mono#16620)
authorJay Krell <jaykrell@microsoft.com>
Thu, 12 Sep 2019 21:57:02 +0000 (14:57 -0700)
committerRyan Lucia <rylucia@microsoft.com>
Thu, 12 Sep 2019 21:57:02 +0000 (17:57 -0400)
* [Coop] Debugger single point of exit.
Extracted from https://github.com/mono/mono/pull/16614.

* Use a label per error for code size.

Commit migrated from https://github.com/mono/mono/commit/b2a1c6cd921877ff5e854e7d09fe00225ce8ff46

src/mono/mono/mini/debugger-agent.c

index 9cdd5d1..e9bbb90 100644 (file)
@@ -8055,17 +8055,17 @@ type_commands_internal (int command, MonoClass *klass, MonoDomain *domain, guint
                attr_klass = decode_typeid (p, &p, end, NULL, &err);
                /* attr_klass can be NULL */
                if (err != ERR_NONE)
-                       return err;
+                       goto exit;
 
                cinfo = mono_custom_attrs_from_class_checked (klass, error);
                if (!is_ok (error)) {
                        mono_error_cleanup (error); /* FIXME don't swallow the error message */
-                       return ERR_LOADER_ERROR;
+                       goto loader_error;
                }
 
                err = buffer_add_cattrs (buf, domain, m_class_get_image (klass), attr_klass, cinfo);
                if (err != ERR_NONE)
-                       return err;
+                       goto exit;
                break;
        }
        case CMD_TYPE_GET_FIELD_CATTRS: {
@@ -8075,20 +8075,20 @@ type_commands_internal (int command, MonoClass *klass, MonoDomain *domain, guint
 
                field = decode_fieldid (p, &p, end, NULL, &err);
                if (err != ERR_NONE)
-                       return err;
+                       goto exit;
                attr_klass = decode_typeid (p, &p, end, NULL, &err);
                if (err != ERR_NONE)
-                       return err;
+                       goto exit;
 
                cinfo = mono_custom_attrs_from_field_checked (klass, field, error);
                if (!is_ok (error)) {
                        mono_error_cleanup (error); /* FIXME don't swallow the error message */
-                       return ERR_LOADER_ERROR;
+                       goto loader_error;
                }
 
                err = buffer_add_cattrs (buf, domain, m_class_get_image (klass), attr_klass, cinfo);
                if (err != ERR_NONE)
-                       return err;
+                       goto exit;
                break;
        }
        case CMD_TYPE_GET_PROPERTY_CATTRS: {
@@ -8098,20 +8098,20 @@ type_commands_internal (int command, MonoClass *klass, MonoDomain *domain, guint
 
                prop = decode_propertyid (p, &p, end, NULL, &err);
                if (err != ERR_NONE)
-                       return err;
+                       goto exit;
                attr_klass = decode_typeid (p, &p, end, NULL, &err);
                if (err != ERR_NONE)
-                       return err;
+                       goto exit;
 
                cinfo = mono_custom_attrs_from_property_checked (klass, prop, error);
                if (!is_ok (error)) {
                        mono_error_cleanup (error); /* FIXME don't swallow the error message */
-                       return ERR_LOADER_ERROR;
+                       goto loader_error;
                }
 
                err = buffer_add_cattrs (buf, domain, m_class_get_image (klass), attr_klass, cinfo);
                if (err != ERR_NONE)
-                       return err;
+                       goto exit;
                break;
        }
        case CMD_TYPE_GET_VALUES:
@@ -8132,7 +8132,7 @@ type_commands_internal (int command, MonoClass *klass, MonoDomain *domain, guint
 
                        err = get_object (objid, (MonoObject**)&thread_obj);
                        if (err != ERR_NONE)
-                               return err;
+                               goto exit;
 
                        thread = THREAD_TO_INTERNAL (thread_obj);
                }
@@ -8141,14 +8141,15 @@ type_commands_internal (int command, MonoClass *klass, MonoDomain *domain, guint
                for (i = 0; i < len; ++i) {
                        f = decode_fieldid (p, &p, end, NULL, &err);
                        if (err != ERR_NONE)
-                               return err;
+                               goto exit;
 
                        if (!(f->type->attrs & FIELD_ATTRIBUTE_STATIC))
-                               return ERR_INVALID_FIELDID;
+                               goto invalid_fieldid;
+
                        special_static_type = mono_class_field_get_special_static_type (f);
                        if (special_static_type != SPECIAL_STATIC_NONE) {
                                if (!(thread && special_static_type == SPECIAL_STATIC_THREAD))
-                                       return ERR_INVALID_FIELDID;
+                                       goto invalid_fieldid;
                        }
 
                        /* Check that the field belongs to the object */
@@ -8160,15 +8161,15 @@ type_commands_internal (int command, MonoClass *klass, MonoDomain *domain, guint
                                }
                        }
                        if (!found)
-                               return ERR_INVALID_FIELDID;
+                               goto invalid_fieldid;
 
                        vtable = mono_class_vtable_checked (domain, f->parent, error);
-                       if (!is_ok (error))
-                               return ERR_INVALID_FIELDID;
+                       goto_if_nok (error, invalid_fieldid);
+
                        val = (guint8 *)g_malloc (mono_class_instance_size (mono_class_from_mono_type_internal (f->type)));
                        mono_field_static_get_value_for_thread (thread ? thread : mono_thread_internal_current (), vtable, f, val, error);
-                       if (!is_ok (error))
-                               return ERR_INVALID_FIELDID;
+                       goto_if_nok (error, invalid_fieldid);
+
                        buffer_add_value (buf, f->type, val, domain);
                        g_free (val);
                }
@@ -8186,12 +8187,13 @@ type_commands_internal (int command, MonoClass *klass, MonoDomain *domain, guint
                for (i = 0; i < len; ++i) {
                        f = decode_fieldid (p, &p, end, NULL, &err);
                        if (err != ERR_NONE)
-                               return err;
+                               goto exit;
 
                        if (!(f->type->attrs & FIELD_ATTRIBUTE_STATIC))
-                               return ERR_INVALID_FIELDID;
+                               goto invalid_fieldid;
+
                        if (mono_class_field_is_special_static (f))
-                               return ERR_INVALID_FIELDID;
+                               goto invalid_fieldid;
 
                        /* Check that the field belongs to the object */
                        found = FALSE;
@@ -8202,18 +8204,18 @@ type_commands_internal (int command, MonoClass *klass, MonoDomain *domain, guint
                                }
                        }
                        if (!found)
-                               return ERR_INVALID_FIELDID;
+                               goto invalid_fieldid;
 
                        // FIXME: Check for literal/const
 
                        vtable = mono_class_vtable_checked (domain, f->parent, error);
-                       if (!is_ok (error))
-                               return ERR_INVALID_FIELDID;
+                       goto_if_nok (error, invalid_fieldid);
+
                        val = (guint8 *)g_malloc (mono_class_instance_size (mono_class_from_mono_type_internal (f->type)));
                        err = decode_value (f->type, domain, val, p, &p, end, TRUE);
                        if (err != ERR_NONE) {
                                g_free (val);
-                               return err;
+                               goto exit;
                        }
                        if (MONO_TYPE_IS_REFERENCE (f->type))
                                mono_field_static_set_value_internal (vtable, f, *(gpointer*)val);
@@ -8227,7 +8229,7 @@ type_commands_internal (int command, MonoClass *klass, MonoDomain *domain, guint
                MonoObject *o = (MonoObject*)mono_type_get_object_checked (domain, m_class_get_byval_arg (klass), error);
                if (!is_ok (error)) {
                        mono_error_cleanup (error);
-                       return ERR_INVALID_OBJECT;
+                       goto invalid_object;
                }
                buffer_add_objid (buf, o);
                break;
@@ -8259,7 +8261,7 @@ type_commands_internal (int command, MonoClass *klass, MonoDomain *domain, guint
                MonoClass *oklass = decode_typeid (p, &p, end, NULL, &err);
 
                if (err != ERR_NONE)
-                       return err;
+                       goto exit;
                if (mono_class_is_assignable_from_internal (klass, oklass))
                        buffer_add_byte (buf, 1);
                else
@@ -8281,7 +8283,7 @@ type_commands_internal (int command, MonoClass *klass, MonoDomain *domain, guint
                array = mono_class_get_methods_by_name (klass, name, flags & ~BINDING_FLAGS_IGNORE_CASE, mlisttype, TRUE, error);
                if (!is_ok (error)) {
                        mono_error_cleanup (error);
-                       return ERR_LOADER_ERROR;
+                       goto loader_error;
                }
                buffer_add_int (buf, array->len);
                for (i = 0; i < array->len; ++i) {
@@ -8303,11 +8305,10 @@ type_commands_internal (int command, MonoClass *klass, MonoDomain *domain, guint
 
                for (parent = tclass; parent; parent = m_class_get_parent (parent)) {
                        mono_class_setup_interfaces (parent, error);
-                       if (!is_ok (error))
-                               return ERR_LOADER_ERROR;
+                       goto_if_nok (error, loader_error);
+
                        collect_interfaces (parent, iface_hash, error);
-                       if (!is_ok (error))
-                               return ERR_LOADER_ERROR;
+                       goto_if_nok (error, loader_error);
                }
 
                buffer_add_int (buf, g_hash_table_size (iface_hash));
@@ -8332,11 +8333,11 @@ type_commands_internal (int command, MonoClass *klass, MonoDomain *domain, guint
                for (tindex = 0; tindex < len; ++tindex) {
                        iclass = decode_typeid (p, &p, end, NULL, &err);
                        if (err != ERR_NONE)
-                               return err;
+                               goto exit;
 
                        ioffset = mono_class_interface_offset_with_variance (klass, iclass, &variance_used);
                        if (ioffset == -1)
-                               return ERR_INVALID_ARGUMENT;
+                               goto invalid_argument;
 
                        nmethods = mono_class_num_methods (iclass);
                        buffer_add_int (buf, nmethods);
@@ -8353,8 +8354,7 @@ type_commands_internal (int command, MonoClass *klass, MonoDomain *domain, guint
        }
        case CMD_TYPE_IS_INITIALIZED: {
                MonoVTable *vtable = mono_class_vtable_checked (domain, klass, error);
-               if (!is_ok (error))
-                       return ERR_LOADER_ERROR;
+               goto_if_nok (error, loader_error);
 
                if (vtable)
                        buffer_add_int (buf, (vtable->initialized || vtable->init_failed) ? 1 : 0);
@@ -8379,10 +8379,26 @@ type_commands_internal (int command, MonoClass *klass, MonoDomain *domain, guint
                break;
        }
        default:
-               return ERR_NOT_IMPLEMENTED;
+               err = ERR_NOT_IMPLEMENTED;
+               goto exit;
        }
 
-       return ERR_NONE;
+       err = ERR_NONE;
+       goto exit;
+invalid_argument:
+       err = ERR_INVALID_ARGUMENT;
+       goto exit;
+invalid_fieldid:
+       err = ERR_INVALID_FIELDID;
+       goto exit;
+invalid_object:
+       err = ERR_INVALID_OBJECT;
+       goto exit;
+loader_error:
+       err = ERR_LOADER_ERROR;
+       goto exit;
+exit:
+       return err;
 }
 
 static ErrorCode
@@ -9424,6 +9440,7 @@ object_commands (int command, guint8 *p, guint8 *end, Buffer *buf)
        MonoClassField *f;
        MonoClass *k;
        gboolean found;
+       gboolean remote_obj = FALSE;
 
        if (command == CMD_OBJECT_REF_IS_COLLECTED) {
                objid = decode_objid (p, &p, end);
@@ -9432,16 +9449,16 @@ object_commands (int command, guint8 *p, guint8 *end, Buffer *buf)
                        buffer_add_int (buf, 1);
                else
                        buffer_add_int (buf, 0);
-               return ERR_NONE;
+               err = ERR_NONE;
+               goto exit;
        }
 
        objid = decode_objid (p, &p, end);
        err = get_object (objid, &obj);
        if (err != ERR_NONE)
-               return err;
+               goto exit;
 
        MonoClass *obj_type;
-       gboolean remote_obj = FALSE;
 
        obj_type = obj->vtable->klass;
        if (mono_class_is_transparent_proxy (obj_type)) {
@@ -9462,7 +9479,7 @@ object_commands (int command, guint8 *p, guint8 *end, Buffer *buf)
                for (i = 0; i < len; ++i) {
                        MonoClassField *f = decode_fieldid (p, &p, end, NULL, &err);
                        if (err != ERR_NONE)
-                               return err;
+                               goto exit;
 
                        /* Check that the field belongs to the object */
                        found = FALSE;
@@ -9473,26 +9490,26 @@ object_commands (int command, guint8 *p, guint8 *end, Buffer *buf)
                                }
                        }
                        if (!found)
-                               return ERR_INVALID_FIELDID;
+                               goto invalid_fieldid;
 
                        if (f->type->attrs & FIELD_ATTRIBUTE_STATIC) {
                                guint8 *val;
                                MonoVTable *vtable;
 
                                if (mono_class_field_is_special_static (f))
-                                       return ERR_INVALID_FIELDID;
+                                       goto invalid_fieldid;
 
                                g_assert (f->type->attrs & FIELD_ATTRIBUTE_STATIC);
                                vtable = mono_class_vtable_checked (obj->vtable->domain, f->parent, error);
                                if (!is_ok (error)) {
                                        mono_error_cleanup (error);
-                                       return ERR_INVALID_OBJECT;
+                                       goto invalid_object;
                                }
                                val = (guint8 *)g_malloc (mono_class_instance_size (mono_class_from_mono_type_internal (f->type)));
                                mono_field_static_get_value_checked (vtable, f, val, error);
                                if (!is_ok (error)) {
                                        mono_error_cleanup (error); /* FIXME report the error */
-                                       return ERR_INVALID_OBJECT;
+                                       goto invalid_object;
                                }
                                buffer_add_value (buf, f->type, val, obj->vtable->domain);
                                g_free (val);
@@ -9506,7 +9523,7 @@ object_commands (int command, guint8 *p, guint8 *end, Buffer *buf)
                                        field_value = mono_load_remote_field_checked(obj, obj_type, f, &field_storage, error);
                                        if (!is_ok (error)) {
                                                mono_error_cleanup (error); /* FIXME report the error */
-                                               return ERR_INVALID_OBJECT;
+                                               goto invalid_object;
                                        }
 #else
                                        g_assert_not_reached ();
@@ -9524,7 +9541,7 @@ object_commands (int command, guint8 *p, guint8 *end, Buffer *buf)
                for (i = 0; i < len; ++i) {
                        f = decode_fieldid (p, &p, end, NULL, &err);
                        if (err != ERR_NONE)
-                               return err;
+                               goto exit;
 
                        /* Check that the field belongs to the object */
                        found = FALSE;
@@ -9535,34 +9552,34 @@ object_commands (int command, guint8 *p, guint8 *end, Buffer *buf)
                                }
                        }
                        if (!found)
-                               return ERR_INVALID_FIELDID;
+                               goto invalid_fieldid;
 
                        if (f->type->attrs & FIELD_ATTRIBUTE_STATIC) {
                                guint8 *val;
                                MonoVTable *vtable;
 
                                if (mono_class_field_is_special_static (f))
-                                       return ERR_INVALID_FIELDID;
+                                       goto invalid_fieldid;
 
                                g_assert (f->type->attrs & FIELD_ATTRIBUTE_STATIC);
                                vtable = mono_class_vtable_checked (obj->vtable->domain, f->parent, error);
                                if (!is_ok (error)) {
                                        mono_error_cleanup (error);
-                                       return ERR_INVALID_FIELDID;
+                                       goto invalid_fieldid;
                                }
 
                                val = (guint8 *)g_malloc (mono_class_instance_size (mono_class_from_mono_type_internal (f->type)));
                                err = decode_value (f->type, obj->vtable->domain, val, p, &p, end, TRUE);
                                if (err != ERR_NONE) {
                                        g_free (val);
-                                       return err;
+                                       goto exit;
                                }
                                mono_field_static_set_value_internal (vtable, f, val);
                                g_free (val);
                        } else {
                                err = decode_value (f->type, obj->vtable->domain, (guint8*)obj + f->offset, p, &p, end, TRUE);
                                if (err != ERR_NONE)
-                                       return err;
+                                       goto exit;
                        }
                }
                break;
@@ -9577,10 +9594,20 @@ object_commands (int command, guint8 *p, guint8 *end, Buffer *buf)
                buffer_add_domainid (buf, obj->vtable->domain);
                break;
        default:
-               return ERR_NOT_IMPLEMENTED;
+               err = ERR_NOT_IMPLEMENTED;
+               goto exit;
        }
 
-       return ERR_NONE;
+       err = ERR_NONE;
+       goto exit;
+invalid_fieldid:
+       err = ERR_INVALID_FIELDID;
+       goto exit;
+invalid_object:
+       err = ERR_INVALID_OBJECT;
+       goto exit;
+exit:
+       return err;
 }
 
 static const char*