Skip to content

Commit

Permalink
Allow Debugger attributes to be trimmed in Mono
Browse files Browse the repository at this point in the history
* Changed debugger-agent to allow for the Debugger Attributes to not exist.
* Removed the Debugger Attributes entries from the Descriptors.xml file.

Fix dotnet/linker#1355
  • Loading branch information
eerhardt committed Jul 20, 2020
1 parent 0372a38 commit 6e3423b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 18 deletions.
2 changes: 1 addition & 1 deletion mono/metadata/class.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
30 changes: 13 additions & 17 deletions mono/mini/debugger-agent.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -3607,37 +3611,29 @@ 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);
}

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);
}
Expand Down

0 comments on commit 6e3423b

Please sign in to comment.