diff options
author | Rodrigo Kumpera <kumpera@gmail.com> | 2016-01-27 21:38:13 +0300 |
---|---|---|
committer | Rodrigo Kumpera <kumpera@gmail.com> | 2016-01-27 21:38:13 +0300 |
commit | 6a724e9a6ed3b8e497f35ea959daf83b4e125512 (patch) | |
tree | 1897646649ce41ef1e593b9cb412238f3b491303 | |
parent | 97122fe004a34e80b93823d19e6e30602d2696ac (diff) | |
parent | a997c1c404d9a330d3cbfcfaa95510c023713cde (diff) |
Merge pull request #2520 from kumpera/loader-error-cleanup5
[mono-error] Another round of loader-error
-rwxr-xr-x | mono/dis/dump.c | 15 | ||||
-rwxr-xr-x | mono/dis/get.c | 49 | ||||
-rw-r--r-- | mono/metadata/attach.c | 6 | ||||
-rw-r--r-- | mono/metadata/coree.c | 4 | ||||
-rw-r--r-- | mono/metadata/debug-helpers.c | 7 | ||||
-rw-r--r-- | mono/metadata/loader.c | 32 | ||||
-rw-r--r-- | mono/metadata/marshal.c | 5 | ||||
-rw-r--r-- | mono/metadata/metadata-verify.c | 8 | ||||
-rw-r--r-- | mono/metadata/reflection.c | 6 | ||||
-rw-r--r-- | mono/mini/aot-compiler.c | 4 | ||||
-rw-r--r-- | mono/mini/aot-runtime.c | 70 | ||||
-rw-r--r-- | mono/mini/debugger-agent.c | 5 | ||||
-rw-r--r-- | mono/mini/driver.c | 33 | ||||
-rw-r--r-- | mono/mini/dwarfwriter.c | 10 | ||||
-rw-r--r-- | mono/mini/method-to-ir.c | 43 | ||||
-rw-r--r-- | mono/mini/mini-runtime.c | 8 | ||||
-rw-r--r-- | mono/mini/mini-trampolines.c | 6 |
17 files changed, 208 insertions, 103 deletions
diff --git a/mono/dis/dump.c b/mono/dis/dump.c index d54e382434c..a593d26cacb 100755 --- a/mono/dis/dump.c +++ b/mono/dis/dump.c @@ -944,6 +944,7 @@ dump_table_customattr (MonoImage *m) fprintf (output, "Custom Attributes Table (1..%d)\n", t->rows); for (i = 1; i <= t->rows; i++) { + MonoError error; guint32 cols [MONO_CUSTOM_ATTR_SIZE]; guint32 mtoken; char * desc; @@ -966,12 +967,18 @@ dump_table_customattr (MonoImage *m) break; } method = get_method (m, mtoken, NULL); - meth = mono_get_method (m, mtoken, NULL); - params = custom_attr_params (m, mono_method_signature (meth), mono_metadata_blob_heap (m, cols [MONO_CUSTOM_ATTR_VALUE])); - fprintf (output, "%d: %s: %s [%s]\n", i, desc, method, params); + meth = mono_get_method_checked (m, mtoken, NULL, NULL, &error); + if (meth) { + params = custom_attr_params (m, mono_method_signature (meth), mono_metadata_blob_heap (m, cols [MONO_CUSTOM_ATTR_VALUE])); + fprintf (output, "%d: %s: %s [%s]\n", i, desc, method, params); + g_free (params); + } else { + fprintf (output, "Could not decode method due to %s", mono_error_get_message (&error)); + mono_error_cleanup (&error); + } + g_free (desc); g_free (method); - g_free (params); } } diff --git a/mono/dis/get.c b/mono/dis/get.c index de99c35081d..3dbc1f7a79b 100755 --- a/mono/dis/get.c +++ b/mono/dis/get.c @@ -20,6 +20,7 @@ #include <mono/utils/mono-compiler.h> #include <mono/metadata/class.h> #include <mono/metadata/marshal.h> +#include <mono/metadata/metadata-internals.h> extern gboolean substitute_with_mscorlib_p; @@ -1900,6 +1901,7 @@ get_memberref_parent (MonoImage *m, guint32 mrp_token, MonoGenericContainer *con static char * get_method_core (MonoImage *m, guint32 token, gboolean fullsig, MonoGenericContainer *container) { + MonoError error; int idx = mono_metadata_token_index (token); guint32 member_cols [MONO_MEMBERREF_SIZE], method_cols [MONO_METHOD_SIZE]; char *sig = NULL, *esname; @@ -1908,7 +1910,7 @@ get_method_core (MonoImage *m, guint32 token, gboolean fullsig, MonoGenericConta MonoMethod *mh; MonoGenericContainer *type_container = container; - mh = mono_get_method_full (m, token, NULL, (MonoGenericContext *) container); + mh = mono_get_method_checked (m, token, NULL, (MonoGenericContext *) container, &error); if (mh) { if (mono_method_signature (mh)->is_inflated) container = mono_method_get_generic_container (((MonoMethodInflated *) mh)->declaring); @@ -1920,8 +1922,10 @@ get_method_core (MonoImage *m, guint32 token, gboolean fullsig, MonoGenericConta name = g_strdup_printf ("%s%s%s", sig ? sig : "", sig ? "::" : "", esname); g_free (sig); g_free (esname); - } else + } else { name = NULL; + mono_error_cleanup (&error); + } switch (mono_metadata_token_code (token)){ case MONO_TOKEN_METHOD_DEF: @@ -2005,13 +2009,14 @@ get_method (MonoImage *m, guint32 token, MonoGenericContainer *container) char * get_methoddef (MonoImage *m, guint32 idx) { - guint32 cols [MONO_METHOD_SIZE]; + MonoError error; + guint32 cols [MONO_METHOD_SIZE]; char *sig; const char *name; MonoMethod *mh; - mh = mono_get_method (m, MONO_TOKEN_METHOD_DEF | idx, NULL); + mh = mono_get_method_checked (m, MONO_TOKEN_METHOD_DEF | idx, NULL, NULL, &error); if (mh) { sig = dis_stringify_type (m, &mh->klass->byval_arg, FALSE); name = g_strdup_printf ("%s%s%s", @@ -2019,13 +2024,15 @@ get_methoddef (MonoImage *m, guint32 idx) sig ? "::" : "", mh->name); g_free (sig); - } else - name = NULL; - mono_metadata_decode_row (&m->tables [MONO_TABLE_METHOD], - idx - 1, cols, MONO_METHOD_SIZE); - sig = get_methodref_signature (m, cols [MONO_METHOD_SIGNATURE], name); + } else { + name = g_strdup_printf ("!bad-method-name!"); + mono_error_cleanup (&error); + } + mono_metadata_decode_row (&m->tables [MONO_TABLE_METHOD], + idx - 1, cols, MONO_METHOD_SIZE); + sig = get_methodref_signature (m, cols [MONO_METHOD_SIGNATURE], name); - return sig; + return sig; } char * @@ -2068,7 +2075,8 @@ get_method_type_param (MonoImage *m, guint32 blob_signature, MonoGenericContaine char * get_methodspec (MonoImage *m, int idx, guint32 token, const char *fancy_name, MonoGenericContainer *type_container) { - GString *res = g_string_new (""); + MonoError error; + GString *res = g_string_new (""); guint32 member_cols [MONO_MEMBERREF_SIZE], method_cols [MONO_METHOD_SIZE]; char *s, *type_param; const char *ptr; @@ -2097,8 +2105,13 @@ get_methodspec (MonoImage *m, int idx, guint32 token, const char *fancy_name, Mo ptr = mono_metadata_blob_heap (m, sig); mono_metadata_decode_value (ptr, &ptr); - mh = mono_get_method_full (m, method_dor_to_token (token), NULL, (MonoGenericContext *) type_container); - g_assert (mh); + mh = mono_get_method_checked (m, method_dor_to_token (token), NULL, (MonoGenericContext *) type_container, &error); + if (!mh) { + g_string_append_printf (res, "Could not decode method token 0x%x due to %s", token, mono_error_get_message (&error)); + mono_error_cleanup (&error); + return g_string_free (res, FALSE); + } + container = mono_method_get_generic_container (mh); if (!container) container = type_container; @@ -3098,8 +3111,9 @@ get_method_override (MonoImage *m, guint32 token, MonoGenericContainer *containe decl = method_dor_to_token (cols [MONO_METHODIMPL_DECLARATION]); if (token == impl) { + MonoError error; MonoMethod *mh = NULL; - mh = mono_get_method_full (m, decl, NULL, (MonoGenericContext *) container); + mh = mono_get_method_checked (m, decl, NULL, (MonoGenericContext *) container, &error); if (mh && (mh->klass && (mh->klass->generic_class || mh->klass->generic_container))) { char *meth_str; @@ -3110,7 +3124,12 @@ get_method_override (MonoImage *m, guint32 token, MonoGenericContainer *containe g_free (meth_str); return ret; } else { - return get_method_core (m, decl, FALSE, container); + char *meth_str = get_method_core (m, decl, FALSE, container); + char *ret = g_strdup_printf ("Could not decode method override %s due to %s", meth_str, mono_error_get_message (&error)); + + mono_error_cleanup (&error); + g_free (meth_str); + return ret; } } } diff --git a/mono/metadata/attach.c b/mono/metadata/attach.c index 4f5024a72f0..e41bbf7d02b 100644 --- a/mono/metadata/attach.c +++ b/mono/metadata/attach.c @@ -265,6 +265,7 @@ mono_attach_cleanup (void) static int mono_attach_load_agent (MonoDomain *domain, char *agent, char *args, MonoObject **exc) { + MonoError error; MonoAssembly *agent_assembly; MonoImage *image; MonoMethod *method; @@ -292,9 +293,10 @@ mono_attach_load_agent (MonoDomain *domain, char *agent, char *args, MonoObject return 1; } - method = mono_get_method (image, entry, NULL); + method = mono_get_method_checked (image, entry, NULL, NULL, &error); if (method == NULL){ - g_print ("The entry point method of assembly '%s' could not be loaded\n", agent); + g_print ("The entry point method of assembly '%s' could not be loaded due to %s\n", agent, mono_error_get_message (&error)); + mono_error_cleanup (&error); g_free (agent); return 1; } diff --git a/mono/metadata/coree.c b/mono/metadata/coree.c index d722271ebb7..7c4be6afe7e 100644 --- a/mono/metadata/coree.c +++ b/mono/metadata/coree.c @@ -136,6 +136,7 @@ BOOL STDMETHODCALLTYPE _CorDllMain(HINSTANCE hInst, DWORD dwReason, LPVOID lpRes /* Called by ntdll.dll reagardless of entry point after _CorValidateImage. */ __int32 STDMETHODCALLTYPE _CorExeMain(void) { + MonoError error; MonoDomain* domain; MonoAssembly* assembly; MonoImage* image; @@ -179,9 +180,10 @@ __int32 STDMETHODCALLTYPE _CorExeMain(void) ExitProcess (1); } - method = mono_get_method (image, entry, NULL); + method = mono_get_method_checked (image, entry, NULL, NULL, &error); if (method == NULL) { g_free (file_name); + mono_error_cleanup (&error); /* FIXME don't swallow the error */ MessageBox (NULL, L"The entry point method could not be loaded.", NULL, MB_ICONERROR); mono_runtime_quit (); ExitProcess (1); diff --git a/mono/metadata/debug-helpers.c b/mono/metadata/debug-helpers.c index db4b765fbde..27c885bc41b 100644 --- a/mono/metadata/debug-helpers.c +++ b/mono/metadata/debug-helpers.c @@ -541,12 +541,17 @@ mono_method_desc_search_in_image (MonoMethodDesc *desc, MonoImage *image) mono_image_get_table_info (image, MONO_TABLE_TYPEDEF); methods = mono_image_get_table_info (image, MONO_TABLE_METHOD); for (i = 0; i < mono_table_info_get_rows (methods); ++i) { + MonoError error; guint32 token = mono_metadata_decode_row_col (methods, i, MONO_METHOD_NAME); const char *n = mono_metadata_string_heap (image, token); if (strcmp (n, desc->name)) continue; - method = mono_get_method (image, MONO_TOKEN_METHOD_DEF | (i + 1), NULL); + method = mono_get_method_checked (image, MONO_TOKEN_METHOD_DEF | (i + 1), NULL, NULL, &error); + if (!method) { + mono_error_cleanup (&error); + continue; + } if (mono_method_desc_full_match (desc, method)) return method; } diff --git a/mono/metadata/loader.c b/mono/metadata/loader.c index 0566fe2d102..55a02988f30 100644 --- a/mono/metadata/loader.c +++ b/mono/metadata/loader.c @@ -534,17 +534,14 @@ field_from_memberref (MonoImage *image, guint32 token, MonoClass **retklass, /* * mono_field_from_token: * @deprecated use the _checked variant + * Notes: runtime code MUST not use this function */ MonoClassField* mono_field_from_token (MonoImage *image, guint32 token, MonoClass **retklass, MonoGenericContext *context) { MonoError error; MonoClassField *res = mono_field_from_token_checked (image, token, retklass, context, &error); - mono_loader_assert_no_error (); - if (!mono_error_ok (&error)) { - mono_loader_set_error_from_mono_error (&error); - mono_error_cleanup (&error); - } + g_assert (mono_error_ok (&error)); return res; } @@ -899,20 +896,15 @@ inflate_generic_header (MonoMethodHeader *header, MonoGenericContext *context) /* * token is the method_ref/def/spec token used in a call IL instruction. + * @deprecated use the _checked variant + * Notes: runtime code MUST not use this function */ MonoMethodSignature* mono_method_get_signature_full (MonoMethod *method, MonoImage *image, guint32 token, MonoGenericContext *context) { MonoError error; MonoMethodSignature *res = mono_method_get_signature_checked (method, image, token, context, &error); - - mono_loader_assert_no_error (); - - if (!res) { - g_assert (!mono_error_ok (&error)); - mono_loader_set_error_from_mono_error (&error); - mono_error_cleanup (&error); /* FIXME Don't swallow the error */ - } + g_assert (mono_error_ok (&error)); return res; } @@ -1001,19 +993,17 @@ mono_method_get_signature_checked (MonoMethod *method, MonoImage *image, guint32 return sig; } +/* + * token is the method_ref/def/spec token used in a call IL instruction. + * @deprecated use the _checked variant + * Notes: runtime code MUST not use this function + */ MonoMethodSignature* mono_method_get_signature (MonoMethod *method, MonoImage *image, guint32 token) { MonoError error; MonoMethodSignature *res = mono_method_get_signature_checked (method, image, token, NULL, &error); - - mono_loader_assert_no_error (); - - if (!res) { - g_assert (!mono_error_ok (&error)); - mono_loader_set_error_from_mono_error (&error); - mono_error_cleanup (&error); /* FIXME Don't swallow the error */ - } + g_assert (mono_error_ok (&error)); return res; } diff --git a/mono/metadata/marshal.c b/mono/metadata/marshal.c index 8ae146eccde..3c6768041b2 100644 --- a/mono/metadata/marshal.c +++ b/mono/metadata/marshal.c @@ -8155,6 +8155,7 @@ mono_marshal_get_managed_wrapper (MonoMethod *method, MonoClass *delegate_klass, gpointer mono_marshal_get_vtfixup_ftnptr (MonoImage *image, guint32 token, guint16 type) { + MonoError error; MonoMethod *method; MonoMethodSignature *sig; MonoMethodBuilder *mb; @@ -8162,7 +8163,9 @@ mono_marshal_get_vtfixup_ftnptr (MonoImage *image, guint32 token, guint16 type) g_assert (token); - method = mono_get_method (image, token, NULL); + method = mono_get_method_checked (image, token, NULL, NULL, &error); + if (!method) + g_error ("Could not load vtfixup token 0x%x due to %s", token, mono_error_get_message (&error)); g_assert (method); if (type & (VTFIXUP_TYPE_FROM_UNMANAGED | VTFIXUP_TYPE_FROM_UNMANAGED_RETAIN_APPDOMAIN)) { diff --git a/mono/metadata/metadata-verify.c b/mono/metadata/metadata-verify.c index 65f3bba5686..753e5269e92 100644 --- a/mono/metadata/metadata-verify.c +++ b/mono/metadata/metadata-verify.c @@ -2925,6 +2925,7 @@ verify_cattr_table (VerifyContext *ctx) static void verify_cattr_table_full (VerifyContext *ctx) { + MonoError error; MonoTableInfo *table = &ctx->image->tables [MONO_TABLE_CUSTOMATTRIBUTE]; MonoMethod *ctor; const char *ptr; @@ -2949,7 +2950,12 @@ verify_cattr_table_full (VerifyContext *ctx) ADD_ERROR (ctx, g_strdup_printf ("Invalid CustomAttribute constructor row %d Token 0x%08x", i, data [MONO_CUSTOM_ATTR_TYPE])); } - ctor = mono_get_method (ctx->image, mtoken, NULL); + ctor = mono_get_method_checked (ctx->image, mtoken, NULL, NULL, &error); + + if (!ctor) { + ADD_ERROR (ctx, g_strdup_printf ("Invalid CustomAttribute content row %d Could not load ctor due to %s", i, mono_error_get_message (&error))); + mono_error_cleanup (&error); + } /*This can't fail since this is checked in is_valid_cattr_blob*/ g_assert (decode_signature_header (ctx, data [MONO_CUSTOM_ATTR_VALUE], &size, &ptr)); diff --git a/mono/metadata/reflection.c b/mono/metadata/reflection.c index 96316adef5b..c564c516788 100644 --- a/mono/metadata/reflection.c +++ b/mono/metadata/reflection.c @@ -9155,6 +9155,7 @@ mono_custom_attrs_from_index (MonoImage *image, guint32 idx) ainfo->num_attrs = len; ainfo->image = image; for (i = len, tmp = list; i != 0; --i, tmp = tmp->next) { + MonoError error; mono_metadata_decode_row (ca, GPOINTER_TO_UINT (tmp->data), cols, MONO_CUSTOM_ATTR_SIZE); mtoken = cols [MONO_CUSTOM_ATTR_TYPE] >> MONO_CUSTOM_ATTR_TYPE_BITS; switch (cols [MONO_CUSTOM_ATTR_TYPE] & MONO_CUSTOM_ATTR_TYPE_MASK) { @@ -9169,9 +9170,10 @@ mono_custom_attrs_from_index (MonoImage *image, guint32 idx) break; } attr = &ainfo->attrs [i - 1]; - attr->ctor = mono_get_method (image, mtoken, NULL); + attr->ctor = mono_get_method_checked (image, mtoken, NULL, NULL, &error); if (!attr->ctor) { - g_warning ("Can't find custom attr constructor image: %s mtoken: 0x%08x", image->name, mtoken); + g_warning ("Can't find custom attr constructor image: %s mtoken: 0x%08x due to %s", image->name, mtoken, mono_error_get_message (&error)); + mono_loader_set_error_from_mono_error (&error); g_list_free (list); g_free (ainfo); return NULL; diff --git a/mono/mini/aot-compiler.c b/mono/mini/aot-compiler.c index 1e994651997..0c02a8e416f 100644 --- a/mono/mini/aot-compiler.c +++ b/mono/mini/aot-compiler.c @@ -3695,10 +3695,12 @@ add_wrappers (MonoAotCompile *acfg) #if 0 /* remoting-invoke wrappers */ for (i = 0; i < acfg->image->tables [MONO_TABLE_METHOD].rows; ++i) { + MonoError error; MonoMethodSignature *sig; token = MONO_TOKEN_METHOD_DEF | (i + 1); - method = mono_get_method (acfg->image, token, NULL); + method = mono_get_method_checked (acfg->image, token, NULL, NULL, &error); + g_assert (mono_error_ok (&error)); /* FIXME don't swallow the error */ sig = mono_method_signature (method); diff --git a/mono/mini/aot-runtime.c b/mono/mini/aot-runtime.c index 850670d0c7b..437d82f05f8 100644 --- a/mono/mini/aot-runtime.c +++ b/mono/mini/aot-runtime.c @@ -1218,9 +1218,11 @@ decode_method_ref_with_target (MonoAotModule *module, MethodRef *ref, MonoMethod if (!image) return FALSE; - ref->method = mono_get_method_full (image, ref->token, NULL, NULL); - if (!ref->method) + ref->method = mono_get_method_checked (image, ref->token, NULL, NULL, &error); + if (!ref->method) { + mono_error_cleanup (&error); /* FIXME don't swallow the error */ return FALSE; + } memset (&ctx, 0, sizeof (ctx)); @@ -1229,7 +1231,8 @@ decode_method_ref_with_target (MonoAotModule *module, MethodRef *ref, MonoMethod ctx.method_inst = NULL; ref->method = mono_class_inflate_generic_method_full_checked (ref->method, klass, &ctx, &error); - g_assert (mono_error_ok (&error)); /* FIXME don't swallow the error */ + if (!ref->method) + g_error ("AOT runtime could not load method due to %s", mono_error_get_message (&error)); /* FIXME don't swallow the error */ } memset (&ctx, 0, sizeof (ctx)); @@ -1238,7 +1241,9 @@ decode_method_ref_with_target (MonoAotModule *module, MethodRef *ref, MonoMethod return FALSE; ref->method = mono_class_inflate_generic_method_full_checked (ref->method, klass, &ctx, &error); - g_assert (mono_error_ok (&error)); /* FIXME don't swallow the error */ + if (!ref->method) + g_error ("AOT runtime could not load method due to %s", mono_error_get_message (&error)); /* FIXME don't swallow the error */ + } else if (image_index == MONO_AOT_METHODREF_ARRAY) { MonoClass *klass; int method_type; @@ -1300,8 +1305,10 @@ decode_method_ref (MonoAotModule *module, MethodRef *ref, guint8 *buf, guint8 ** static MonoMethod* decode_resolve_method_ref_with_target (MonoAotModule *module, MonoMethod *target, guint8 *buf, guint8 **endbuf) { + MonoError error; MethodRef ref; gboolean res; + MonoMethod *result; res = decode_method_ref_with_target (module, &ref, target, buf, endbuf); if (!res) @@ -1310,7 +1317,10 @@ decode_resolve_method_ref_with_target (MonoAotModule *module, MonoMethod *target return ref.method; if (!ref.image) return NULL; - return mono_get_method (ref.image, ref.token, NULL); + result = mono_get_method_checked (ref.image, ref.token, NULL, NULL, &error); + if (!result) + mono_error_cleanup (&error); /* FIXME don't swallow the error */ + return result; } static MonoMethod* @@ -3313,8 +3323,11 @@ mono_aot_find_jit_info (MonoDomain *domain, MonoImage *image, gpointer addr) /* Happens when a random address is passed in which matches a not-yey called wrapper encoded using its name */ return NULL; } else { + MonoError error; token = mono_metadata_make_token (MONO_TABLE_METHOD, method_index + 1); - method = mono_get_method (image, token, NULL); + method = mono_get_method_checked (image, token, NULL, NULL, &error); + if (!method) + g_error ("AOT runtime could not load method due to %s", mono_error_get_message (&error)); /* FIXME don't swallow the error */ } } /* FIXME: */ @@ -3391,10 +3404,14 @@ decode_patch (MonoAotModule *aot_module, MonoMemPool *mp, MonoJumpInfo *ji, guin ji->type = MONO_PATCH_INFO_ABS; } else { - if (ref.method) + if (ref.method) { ji->data.method = ref.method; - else - ji->data.method = mono_get_method (ref.image, ref.token, NULL); + }else { + MonoError error; + ji->data.method = mono_get_method_checked (ref.image, ref.token, NULL, NULL, &error); + if (!ji->data.method) + g_error ("AOT Runtime could not load method due to %s", mono_error_get_message (&error)); /* FIXME don't swallow the error */ + } g_assert (ji->data.method); mono_class_init (ji->data.method->klass); } @@ -3771,8 +3788,11 @@ load_method (MonoDomain *domain, MonoAotModule *amodule, MonoImage *image, MonoM if (mono_trace_is_traced (G_LOG_LEVEL_DEBUG, MONO_TRACE_AOT)) { char *full_name; - if (!method) - method = mono_get_method (image, token, NULL); + if (!method) { + MonoError error; + method = mono_get_method_checked (image, token, NULL, NULL, &error); + g_assert (mono_error_ok (&error)); /* FIXME don't swallow the error */ + } full_name = mono_method_full_name (method, TRUE); mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_AOT, "AOT: NOT FOUND: %s.", full_name); g_free (full_name); @@ -3803,8 +3823,12 @@ load_method (MonoDomain *domain, MonoAotModule *amodule, MonoImage *image, MonoM if (mono_jit_stats.methods_aot >= mono_last_aot_method) return NULL; else if (mono_jit_stats.methods_aot == mono_last_aot_method - 1) { - if (!method) - method = mono_get_method (image, token, NULL); + if (!method) { + MonoError error; + method = mono_get_method_checked (image, token, NULL, NULL, &error); + if (!method) + mono_error_cleanup (&error);/* FIXME don't swallow the error */ + } if (method) { char *name = mono_method_full_name (method, TRUE); g_print ("LAST AOT METHOD: %s.\n", name); @@ -3824,8 +3848,12 @@ load_method (MonoDomain *domain, MonoAotModule *amodule, MonoImage *image, MonoM if (mono_trace_is_traced (G_LOG_LEVEL_DEBUG, MONO_TRACE_AOT)) { char *full_name; - if (!method) - method = mono_get_method (image, token, NULL); + if (!method) { + MonoError error; + method = mono_get_method_checked (image, token, NULL, NULL, &error); + if (!method) + g_error ("AOT runtime could not load method due to %s", mono_error_get_message (&error)); /* FIXME don't swallow the error */ + } full_name = mono_method_full_name (method, TRUE); @@ -3853,8 +3881,10 @@ load_method (MonoDomain *domain, MonoAotModule *amodule, MonoImage *image, MonoM MonoJitInfo *jinfo; if (!method) { - method = mono_get_method (amodule->assembly->image, token, NULL); - g_assert (method); + MonoError error; + method = mono_get_method_checked (amodule->assembly->image, token, NULL, NULL, &error); + if (!method) + g_error ("AOT runtime could not load method due to %s", mono_error_get_message (&error)); /* FIXME don't swallow the error */ } mono_profiler_method_jit (method); jinfo = mono_jit_info_table_find (domain, (char*)code); @@ -4329,7 +4359,8 @@ mono_aot_get_method (MonoDomain *domain, MonoMethod *method) ctx.method_inst = mono_metadata_get_generic_inst (1, args); m = mono_marshal_get_native_wrapper (mono_class_inflate_generic_method_checked (m, &ctx, &error), TRUE, TRUE); - g_assert (mono_error_ok (&error)); /* FIXME don't swallow the error */ + if (!m) + g_error ("AOT runtime could not load method due to %s", mono_error_get_message (&error)); /* FIXME don't swallow the error */ /* * Get the code for the <object> instantiation which should be emitted into @@ -4363,7 +4394,8 @@ mono_aot_get_method (MonoDomain *domain, MonoMethod *method) ctx.method_inst = mono_metadata_get_generic_inst (1, args); m = mono_marshal_get_native_wrapper (mono_class_inflate_generic_method_checked (m, &ctx, &error), TRUE, TRUE); - g_assert (mono_error_ok (&error)); /* FIXME don't swallow the error */ + if (!m) + g_error ("AOT runtime could not load method due to %s", mono_error_get_message (&error)); /* FIXME don't swallow the error */ /* Avoid recursion */ if (method == m) diff --git a/mono/mini/debugger-agent.c b/mono/mini/debugger-agent.c index 62598bbb405..f0b4d4f0201 100644 --- a/mono/mini/debugger-agent.c +++ b/mono/mini/debugger-agent.c @@ -7629,7 +7629,10 @@ assembly_commands (int command, guint8 *p, guint8 *end, Buffer *buf) if (token == 0) { buffer_add_id (buf, 0); } else { - m = mono_get_method (ass->image, token, NULL); + MonoError error; + m = mono_get_method_checked (ass->image, token, NULL, NULL, &error); + if (!m) + mono_error_cleanup (&error); /* FIXME don't swallow the error */ buffer_add_methodid (buf, domain, m); } } diff --git a/mono/mini/driver.c b/mono/mini/driver.c index c801bd9ed21..2bf88c38789 100644 --- a/mono/mini/driver.c +++ b/mono/mini/driver.c @@ -382,9 +382,12 @@ mini_regression_step (MonoImage *image, int verbose, int *total_run, int *total, if (mini_stats_fd) fprintf (mini_stats_fd, "["); for (i = 0; i < mono_image_get_table_rows (image, MONO_TABLE_METHOD); ++i) { - MonoMethod *method = mono_get_method (image, MONO_TOKEN_METHOD_DEF | (i + 1), NULL); - if (!method) + MonoError error; + MonoMethod *method = mono_get_method_checked (image, MONO_TOKEN_METHOD_DEF | (i + 1), NULL, NULL, &error); + if (!method) { + mono_error_cleanup (&error); /* FIXME don't swallow the error */ continue; + } if (strncmp (method->name, "test_", 5) == 0) { MonoCompile *cfg; @@ -475,9 +478,12 @@ mini_regression (MonoImage *image, int verbose, int *total_run) /* load the metadata */ for (i = 0; i < mono_image_get_table_rows (image, MONO_TABLE_METHOD); ++i) { - method = mono_get_method (image, MONO_TOKEN_METHOD_DEF | (i + 1), NULL); - if (!method) + MonoError error; + method = mono_get_method_checked (image, MONO_TOKEN_METHOD_DEF | (i + 1), NULL, NULL, &error); + if (!method) { + mono_error_cleanup (&error); continue; + } mono_class_init (method->klass); if (!strncmp (method->name, "test_", 5) && mini_stats_fd) { @@ -905,15 +911,18 @@ compile_all_methods_thread_main_inner (CompileAllThreadArgs *args) int i, count = 0, fail_count = 0; for (i = 0; i < mono_image_get_table_rows (image, MONO_TABLE_METHOD); ++i) { + MonoError error; guint32 token = MONO_TOKEN_METHOD_DEF | (i + 1); MonoMethodSignature *sig; if (mono_metadata_has_generic_params (image, token)) continue; - method = mono_get_method (image, token, NULL); - if (!method) + method = mono_get_method_checked (image, token, NULL, NULL, &error); + if (!method) { + mono_error_cleanup (&error); /* FIXME don't swallow the error */ continue; + } if ((method->iflags & METHOD_IMPL_ATTRIBUTE_INTERNAL_CALL) || (method->flags & METHOD_ATTRIBUTE_PINVOKE_IMPL) || (method->iflags & METHOD_IMPL_ATTRIBUTE_RUNTIME) || @@ -990,6 +999,7 @@ compile_all_methods (MonoAssembly *ass, int verbose, guint32 opts, guint32 recom int mono_jit_exec (MonoDomain *domain, MonoAssembly *assembly, int argc, char *argv[]) { + MonoError error; MonoImage *image = mono_assembly_get_image (assembly); MonoMethod *method; guint32 entry = mono_image_get_entry_point (image); @@ -1001,9 +1011,10 @@ mono_jit_exec (MonoDomain *domain, MonoAssembly *assembly, int argc, char *argv[ return 1; } - method = mono_get_method (image, entry, NULL); + method = mono_get_method_checked (image, entry, NULL, NULL, &error); if (method == NULL){ - g_print ("The entry point method could not be loaded\n"); + g_print ("The entry point method could not be loaded due to %s\n", mono_error_get_message (&error)); + mono_error_cleanup (&error); mono_environment_exitcode_set (1); return 1; } @@ -1074,6 +1085,7 @@ static void main_thread_handler (gpointer user_data) static int load_agent (MonoDomain *domain, char *desc) { + MonoError error; char* col = strchr (desc, ':'); char *agent, *args; MonoAssembly *agent_assembly; @@ -1112,9 +1124,10 @@ load_agent (MonoDomain *domain, char *desc) return 1; } - method = mono_get_method (image, entry, NULL); + method = mono_get_method_checked (image, entry, NULL, NULL, &error); if (method == NULL){ - g_print ("The entry point method of assembly '%s' could not be loaded\n", agent); + g_print ("The entry point method of assembly '%s' could not be loaded due to %s\n", agent, &error); + mono_error_cleanup (&error); g_free (agent); return 1; } diff --git a/mono/mini/dwarfwriter.c b/mono/mini/dwarfwriter.c index 771c1be1e7f..f925ccf3f9c 100644 --- a/mono/mini/dwarfwriter.c +++ b/mono/mini/dwarfwriter.c @@ -1429,10 +1429,14 @@ token_handler (MonoDisHelper *dh, MonoMethod *method, guint32 token) case CEE_NEWOBJ: case CEE_CALL: case CEE_CALLVIRT: - if (method->wrapper_type) + if (method->wrapper_type) { cmethod = (MonoMethod *)data; - else - cmethod = mono_get_method_full (method->klass->image, token, NULL, NULL); + } else { + MonoError error; + cmethod = mono_get_method_checked (method->klass->image, token, NULL, NULL, &error); + if (!cmethod) + g_error ("Could not load method due to %s", mono_error_get_message (&error)); /* FIXME don't swallow the error */ + } desc = mono_method_full_name (cmethod, TRUE); res = g_strdup_printf ("<%s>", desc); g_free (desc); diff --git a/mono/mini/method-to-ir.c b/mono/mini/method-to-ir.c index a202b20cf38..85cf2aca184 100644 --- a/mono/mini/method-to-ir.c +++ b/mono/mini/method-to-ir.c @@ -7374,19 +7374,19 @@ exception_exit: } static inline MonoMethod * -mini_get_method_allow_open (MonoMethod *m, guint32 token, MonoClass *klass, MonoGenericContext *context) +mini_get_method_allow_open (MonoMethod *m, guint32 token, MonoClass *klass, MonoGenericContext *context, MonoError *error) { MonoMethod *method; + mono_error_init (error); + if (m->wrapper_type != MONO_WRAPPER_NONE) { method = (MonoMethod *)mono_method_get_wrapper_data (m, token); if (context) { - MonoError error; - method = mono_class_inflate_generic_method_checked (method, context, &error); - g_assert (mono_error_ok (&error)); /* FIXME don't swallow the error */ + method = mono_class_inflate_generic_method_checked (method, context, error); } } else { - method = mono_get_method_full (m->klass->image, token, klass, context); + method = mono_get_method_checked (m->klass->image, token, klass, context, error); } return method; @@ -7395,10 +7395,16 @@ mini_get_method_allow_open (MonoMethod *m, guint32 token, MonoClass *klass, Mono static inline MonoMethod * mini_get_method (MonoCompile *cfg, MonoMethod *m, guint32 token, MonoClass *klass, MonoGenericContext *context) { - MonoMethod *method = mini_get_method_allow_open (m, token, klass, context); + MonoError error; + MonoMethod *method = mini_get_method_allow_open (m, token, klass, context, cfg ? &cfg->error : &error); - if (method && cfg && !cfg->gshared && mono_class_is_open_constructed_type (&method->klass->byval_arg)) - return NULL; + if (method && cfg && !cfg->gshared && mono_class_is_open_constructed_type (&method->klass->byval_arg)) { + mono_error_set_bad_image (&cfg->error, cfg->method->klass->image, "Method with open type while not compiling gshared"); + method = NULL; + } + + if (!method && !cfg) + mono_error_cleanup (&error); /* FIXME don't swallow the error */ return method; } @@ -8981,9 +8987,7 @@ mono_method_to_ir (MonoCompile *cfg, MonoMethod *method, MonoBasicBlock *start_b token = read32 (ip + 1); /* FIXME: check the signature matches */ cmethod = mini_get_method (cfg, method, token, NULL, generic_context); - - if (!cmethod || mono_loader_get_last_error ()) - LOAD_ERROR; + CHECK_CFG_ERROR; if (cfg->gshared && mono_method_check_context_used (cmethod)) GENERIC_SHARING_FAILURE (CEE_JMP); @@ -9183,6 +9187,8 @@ mono_method_to_ir (MonoCompile *cfg, MonoMethod *method, MonoBasicBlock *start_b ins = NULL; cmethod = mini_get_method (cfg, method, token, NULL, generic_context); + CHECK_CFG_ERROR; + cil_method = cmethod; if (constrained_class) { @@ -9228,7 +9234,8 @@ mono_method_to_ir (MonoCompile *cfg, MonoMethod *method, MonoBasicBlock *start_b if (!dont_verify && !cfg->skip_visibility) { MonoMethod *target_method = cil_method; if (method->is_inflated) { - target_method = mini_get_method_allow_open (method, token, NULL, &(mono_method_get_generic_container (method_definition)->context)); + target_method = mini_get_method_allow_open (method, token, NULL, &(mono_method_get_generic_container (method_definition)->context), &cfg->error); + CHECK_CFG_ERROR; } if (!mono_method_can_access_method (method_definition, target_method) && !mono_method_can_access_method (method, cil_method)) @@ -10782,8 +10789,8 @@ mono_method_to_ir (MonoCompile *cfg, MonoMethod *method, MonoBasicBlock *start_b CHECK_OPSIZE (5); token = read32 (ip + 1); cmethod = mini_get_method (cfg, method, token, NULL, generic_context); - if (!cmethod || mono_loader_get_last_error ()) - LOAD_ERROR; + CHECK_CFG_ERROR; + fsig = mono_method_get_signature_checked (cmethod, image, token, generic_context, &cfg->error); CHECK_CFG_ERROR; @@ -13045,8 +13052,8 @@ mono_method_to_ir (MonoCompile *cfg, MonoMethod *method, MonoBasicBlock *start_b CHECK_OPSIZE (6); n = read32 (ip + 2); cmethod = mini_get_method (cfg, method, n, NULL, generic_context); - if (!cmethod || mono_loader_get_last_error ()) - LOAD_ERROR; + CHECK_CFG_ERROR; + mono_class_init (cmethod->klass); mono_save_token_info (cfg, image, n, cmethod); @@ -13122,8 +13129,8 @@ mono_method_to_ir (MonoCompile *cfg, MonoMethod *method, MonoBasicBlock *start_b CHECK_OPSIZE (6); n = read32 (ip + 2); cmethod = mini_get_method (cfg, method, n, NULL, generic_context); - if (!cmethod || mono_loader_get_last_error ()) - LOAD_ERROR; + CHECK_CFG_ERROR; + mono_class_init (cmethod->klass); context_used = mini_method_check_context_used (cfg, cmethod); diff --git a/mono/mini/mini-runtime.c b/mono/mini/mini-runtime.c index 514dbbeefaf..159e3e4affb 100644 --- a/mono/mini/mini-runtime.c +++ b/mono/mini/mini-runtime.c @@ -4118,7 +4118,13 @@ mono_precompile_assembly (MonoAssembly *ass, void *user_data) printf ("PRECOMPILE: %s.\n", mono_image_get_filename (image)); for (i = 0; i < mono_image_get_table_rows (image, MONO_TABLE_METHOD); ++i) { - method = mono_get_method (image, MONO_TOKEN_METHOD_DEF | (i + 1), NULL); + MonoError error; + + method = mono_get_method_checked (image, MONO_TOKEN_METHOD_DEF | (i + 1), NULL, NULL, &error); + if (!method) { + mono_error_cleanup (&error); /* FIXME don't swallow the error */ + continue; + } if (method->flags & METHOD_ATTRIBUTE_ABSTRACT) continue; if (method->is_generic || method->klass->generic_container) diff --git a/mono/mini/mini-trampolines.c b/mono/mini/mini-trampolines.c index d40ace4cd3e..f1fe616b969 100644 --- a/mono/mini/mini-trampolines.c +++ b/mono/mini/mini-trampolines.c @@ -954,8 +954,10 @@ mono_aot_trampoline (mgreg_t *regs, guint8 *code, guint8 *token_info, addr = mono_aot_get_method_from_token (mono_domain_get (), image, token); if (!addr) { - method = mono_get_method (image, token, NULL); - g_assert (method); + MonoError error; + method = mono_get_method_checked (image, token, NULL, NULL, &error); + if (!method) + g_error ("Could not load AOT trampoline due to %s", mono_error_get_message (&error)); /* Use the generic code */ return mono_magic_trampoline (regs, code, method, tramp); |