From 6e3423b23216a40672c4b0b492b0900729910b4f Mon Sep 17 00:00:00 2001 From: eerhardt Date: Mon, 20 Jul 2020 17:46:01 +0000 Subject: [PATCH] Allow Debugger attributes to be trimmed in Mono * Changed debugger-agent to allow for the Debugger Attributes to not exist. * Removed the Debugger Attributes entries from the Descriptors.xml file. Fix mono/linker#1355 --- mono/metadata/class.c | 2 +- mono/mini/debugger-agent.c | 30 +++++++++++++----------------- 2 files changed, 14 insertions(+), 18 deletions(-) diff --git a/mono/metadata/class.c b/mono/metadata/class.c index bfd02a8eb736..bc3b46b7f760 100644 --- a/mono/metadata/class.c +++ b/mono/metadata/class.c @@ -3448,7 +3448,7 @@ mono_class_from_name (MonoImage *image, const char* name_space, const char *name * * This function works exactly like mono_class_from_name but it will abort if the class is not found. * This function should be used by the runtime for critical types to which there's no way to recover but crash - * If they are missing. Thing of System.Object or System.String. + * if they are missing. For example, System.Object or System.String. */ MonoClass * mono_class_load_from_name (MonoImage *image, const char* name_space, const char *name) diff --git a/mono/mini/debugger-agent.c b/mono/mini/debugger-agent.c index f76e887e6db8..ace0affe8d73 100644 --- a/mono/mini/debugger-agent.c +++ b/mono/mini/debugger-agent.c @@ -3598,6 +3598,10 @@ dbg_path_get_basename (const char *filename) return g_strdup (&r[1]); } +GENERATE_TRY_GET_CLASS_WITH_CACHE(hidden_klass, "System.Diagnostics", "DebuggerHiddenAttribute") +GENERATE_TRY_GET_CLASS_WITH_CACHE(step_through_klass, "System.Diagnostics", "DebuggerStepThroughAttribute") +GENERATE_TRY_GET_CLASS_WITH_CACHE(non_user_klass, "System.Diagnostics", "DebuggerNonUserCodeAttribute") + static void init_jit_info_dbg_attrs (MonoJitInfo *ji) { @@ -3607,27 +3611,19 @@ init_jit_info_dbg_attrs (MonoJitInfo *ji) if (ji->dbg_attrs_inited) return; - MONO_STATIC_POINTER_INIT (MonoClass, hidden_klass) - hidden_klass = mono_class_load_from_name (mono_defaults.corlib, "System.Diagnostics", "DebuggerHiddenAttribute"); - MONO_STATIC_POINTER_INIT_END (MonoClass, hidden_klass) - - - MONO_STATIC_POINTER_INIT (MonoClass, step_through_klass) - step_through_klass = mono_class_load_from_name (mono_defaults.corlib, "System.Diagnostics", "DebuggerStepThroughAttribute"); - MONO_STATIC_POINTER_INIT_END (MonoClass, step_through_klass) - - MONO_STATIC_POINTER_INIT (MonoClass, non_user_klass) - non_user_klass = mono_class_load_from_name (mono_defaults.corlib, "System.Diagnostics", "DebuggerNonUserCodeAttribute"); - MONO_STATIC_POINTER_INIT_END (MonoClass, non_user_klass) + // NOTE: The following Debugger attributes may not exist if they are trimmed away by the ILLinker + MonoClass *hidden_klass = mono_class_try_get_hidden_klass_class (); + MonoClass *step_through_klass = mono_class_try_get_step_through_klass_class (); + MonoClass *non_user_klass = mono_class_try_get_non_user_klass_class (); ainfo = mono_custom_attrs_from_method_checked (jinfo_get_method (ji), error); mono_error_cleanup (error); /* FIXME don't swallow the error? */ if (ainfo) { - if (mono_custom_attrs_has_attr (ainfo, hidden_klass)) + if (hidden_klass && mono_custom_attrs_has_attr (ainfo, hidden_klass)) ji->dbg_hidden = TRUE; - if (mono_custom_attrs_has_attr (ainfo, step_through_klass)) + if (step_through_klass && mono_custom_attrs_has_attr (ainfo, step_through_klass)) ji->dbg_step_through = TRUE; - if (mono_custom_attrs_has_attr (ainfo, non_user_klass)) + if (non_user_klass && mono_custom_attrs_has_attr (ainfo, non_user_klass)) ji->dbg_non_user_code = TRUE; mono_custom_attrs_free (ainfo); } @@ -3635,9 +3631,9 @@ init_jit_info_dbg_attrs (MonoJitInfo *ji) ainfo = mono_custom_attrs_from_class_checked (jinfo_get_method (ji)->klass, error); mono_error_cleanup (error); /* FIXME don't swallow the error? */ if (ainfo) { - if (mono_custom_attrs_has_attr (ainfo, step_through_klass)) + if (step_through_klass && mono_custom_attrs_has_attr (ainfo, step_through_klass)) ji->dbg_step_through = TRUE; - if (mono_custom_attrs_has_attr (ainfo, non_user_klass)) + if (non_user_klass && mono_custom_attrs_has_attr (ainfo, non_user_klass)) ji->dbg_non_user_code = TRUE; mono_custom_attrs_free (ainfo); }