Skip to content

[mono][debug-helpers] Parse W: prefix in MONO_VERBOSE_METHOD to match wrappers #101766

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion docs/design/mono/mono-manpage-1.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ A number of diagnostic command line options take as argument a method
description. A method description is a textual representation that can
be used to uniquely identify a method. The syntax is as follows:

[namespace]classname:methodname[(arguments)]
[W:][namespace]classname:methodname[(arguments)]

The values in brackets are optional, like the namespace and the
arguments. The arguments themselves are either empty, or a
Expand All @@ -93,11 +93,18 @@ both a comma and a space and '\>'.

By-reference arguments should include a "&" after the typename.

If the method description is prefixed by 'W:' (or 'w:'), then it will
match a *wrapper* method that may be created by the runtime for the
specified method. (For example imported P/Invoke methods may have a
wrapper generated by the runtime.)


Examples:

*:ctor(int) // All constructors that take an int as an argument
*:Main // Methods named Main in any class
*:Main(string[]) // Methods named Main that take a string array in any class
W:UnixSignal:install // Wrappers for the UnixSignal.install DllImport

## RUNTIME OPTIONS

Expand Down
16 changes: 15 additions & 1 deletion src/mono/mono/metadata/debug-helpers.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ struct MonoMethodDesc {
char *args;
guint num_args;
gboolean include_namespace, klass_glob, name_glob;
gboolean match_wrappers;
};

// This, instead of an array of pointers, to optimize away a pointer and a relocation per string.
Expand Down Expand Up @@ -341,7 +342,7 @@ mono_context_get_desc (MonoGenericContext *context)
* Creates a method description for \p name, which conforms to the following
* specification:
*
* <code>[namespace.]classname:methodname[(args...)]</code>
* <code>[w:][namespace.]classname:methodname[(args...)]</code>
*
* in all the loaded assemblies.
*
Expand All @@ -356,7 +357,13 @@ mono_method_desc_new (const char *name, gboolean include_namespace)
char *class_name, *class_nspace, *method_name, *use_args, *end;
int use_namespace;
int generic_delim_stack;
int match_wrappers = 0;

/* if the name starts with w: or W: allow matching wrappers */
if (strstr(name, "W:") == name || strstr(name, "w:") == name) {
name += 2;
match_wrappers = 1;
}
class_nspace = g_strdup (name);
use_args = strchr (class_nspace, '(');
if (use_args) {
Expand Down Expand Up @@ -414,6 +421,8 @@ mono_method_desc_new (const char *name, gboolean include_namespace)
++end;
}
}
if (match_wrappers)
result->match_wrappers = TRUE;

return result;
}
Expand All @@ -431,6 +440,8 @@ mono_method_desc_from_method (MonoMethod *method)
result->name = g_strdup (method->name);
result->klass = g_strdup (method->klass->name);
result->name_space = g_strdup (method->klass->name_space);
if (method->wrapper_type)
result->match_wrappers = TRUE;

return result;
}
Expand Down Expand Up @@ -466,6 +477,9 @@ mono_method_desc_match (MonoMethodDesc *desc, MonoMethod *method)
char *sig;
gboolean name_match;

if (desc->match_wrappers && method->wrapper_type == MONO_WRAPPER_NONE) {
return FALSE;
}
if (desc->name_glob && !strcmp (desc->name, "*"))
return TRUE;
#if 0
Expand Down