Skip to content

Add ability to filter interpreted methods by assembly #116569

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
Jun 13, 2025
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
2 changes: 2 additions & 0 deletions docs/design/coreclr/jit/viewing-jit-dumps.md
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,8 @@ Some environment variables such as `DOTNET_JitDisasm` take a list of patterns sp
+ The simplest method list is a single method name specified using just the method name (no class name), e.g. `Main`.
+ A list of simple method names can be used, e.g., `Main Test1 Test2`.
* The string matched against depends on characters in the pattern:
+ If the pattern contains a '!' character, the string matched against is prefixed by the assembly name and an exclamation mark.
- Example: `testassembly!*` - specifies all methods from the assembly named `testassembly`.
+ If the pattern contains a ':' character, the string matched against is prefixed by the class name and a colon.
- Example: `TestClass:Main` - specifies a single method named `Main` in the class named `TestClass`.
+ If the pattern contains a '(' character, the string matched against is suffixed by the signature.
Expand Down
4 changes: 4 additions & 0 deletions src/coreclr/interpreter/compiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1199,6 +1199,8 @@ InterpCompiler::InterpCompiler(COMP_HANDLE compHnd,
m_classHnd = compHnd->getMethodClass(m_methodHnd);

m_methodName = ::PrintMethodName(compHnd, m_classHnd, m_methodHnd, &m_methodInfo->args,
/* includeAssembly */ false,
/* includeClass */ true,
/* includeClassInstantiation */ true,
/* includeMethodInstantiation */ true,
/* includeSignature */ true,
Expand Down Expand Up @@ -5062,6 +5064,8 @@ void InterpCompiler::PrintMethodName(CORINFO_METHOD_HANDLE method)
m_compHnd->getMethodSig(method, &sig, cls);

TArray<char> methodName = ::PrintMethodName(m_compHnd, cls, method, &sig,
/* includeAssembly */ false,
/* includeClass */ false,
/* includeClassInstantiation */ true,
/* includeMethodInstantiation */ true,
/* includeSignature */ true,
Expand Down
2 changes: 2 additions & 0 deletions src/coreclr/interpreter/compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ TArray<char> PrintMethodName(COMP_HANDLE comp,
CORINFO_CLASS_HANDLE clsHnd,
CORINFO_METHOD_HANDLE methHnd,
CORINFO_SIG_INFO* sig,
bool includeAssembly,
bool includeClass,
bool includeClassInstantiation,
bool includeMethodInstantiation,
bool includeSignature,
Expand Down
1 change: 1 addition & 0 deletions src/coreclr/interpreter/interpretershared.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ class MethodSet
bool m_classNameContainsInstantiation;
bool m_methodNameContainsInstantiation;
bool m_containsSignature;
bool m_containsAssemblyName;
};

const char* m_listFromConfig = nullptr;
Expand Down
16 changes: 12 additions & 4 deletions src/coreclr/interpreter/methodset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,18 @@ void MethodSet::initialize(const char* listFromConfig)
name->m_next = m_names;
name->m_patternStart = start;
name->m_patternEnd = end;
const char* colon = static_cast<const char*>(memchr(start, ':', end - start));
const char* startOfMethodName = colon != nullptr ? colon + 1 : start;
const char* exclamation = static_cast<const char*>(memchr(start, '!', end - start));
const char* startOfClassName = exclamation != nullptr ? exclamation + 1 : start;
const char* colon = static_cast<const char*>(memchr(startOfClassName, ':', end - startOfClassName));
const char* startOfMethodName = colon != nullptr ? colon + 1 : startOfClassName;

const char* parens = static_cast<const char*>(memchr(startOfMethodName, '(', end - startOfMethodName));
const char* endOfMethodName = parens != nullptr ? parens : end;
name->m_methodNameContainsInstantiation =
memchr(startOfMethodName, '[', endOfMethodName - startOfMethodName) != nullptr;

name->m_containsAssemblyName = (exclamation != nullptr);

if (colon != nullptr)
{
name->m_containsClassName = true;
Expand Down Expand Up @@ -156,12 +160,16 @@ bool MethodSet::contains(COMP_HANDLE comp,

for (MethodName* name = m_names; name != nullptr; name = name->m_next)
{
if ((prevPattern == nullptr) || (name->m_containsClassName != prevPattern->m_containsClassName) ||
if ((prevPattern == nullptr) ||
(name->m_containsAssemblyName != prevPattern->m_containsAssemblyName) ||
(name->m_containsClassName != prevPattern->m_containsClassName) ||
(name->m_classNameContainsInstantiation != prevPattern->m_classNameContainsInstantiation) ||
(name->m_methodNameContainsInstantiation != prevPattern->m_methodNameContainsInstantiation) ||
(name->m_containsSignature != prevPattern->m_containsSignature))
{
printer = PrintMethodName(comp, name->m_containsClassName ? classHnd : NO_CLASS_HANDLE, methodHnd, sigInfo,
printer = PrintMethodName(comp, classHnd, methodHnd, sigInfo,
/* includeAssembly */ name->m_containsAssemblyName,
/* includeClass */ name->m_containsClassName,
/* includeClassInstantiation */ name->m_classNameContainsInstantiation,
/* includeMethodInstantiation */ name->m_methodNameContainsInstantiation,
/* includeSignature */ name->m_containsSignature,
Expand Down
18 changes: 15 additions & 3 deletions src/coreclr/interpreter/naming.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ void AppendType(COMP_HANDLE comp, TArray<char>* printer, CORINFO_CLASS_HANDLE cl
void AppendCorInfoType(TArray<char>* printer, CorInfoType corInfoType);
void AppendTypeOrJitAlias(COMP_HANDLE comp, TArray<char>* printer, CORINFO_CLASS_HANDLE clsHnd, bool includeInstantiation);

void AppendString(TArray<char>& array, const char* str)
void AppendString(TArray<char>* array, const char* str)
{
if (str != nullptr)
{
size_t strLen = strlen(str);
array.Append(str, static_cast<int32_t>(strLen));
array->Append(str, static_cast<int32_t>(strLen));
}
}

Expand Down Expand Up @@ -145,6 +145,8 @@ void AppendMethodName(COMP_HANDLE comp,
CORINFO_CLASS_HANDLE clsHnd,
CORINFO_METHOD_HANDLE methHnd,
CORINFO_SIG_INFO* sig,
bool includeAssembly,
bool includeClass,
bool includeClassInstantiation,
bool includeMethodInstantiation,
bool includeSignature,
Expand All @@ -153,7 +155,14 @@ void AppendMethodName(COMP_HANDLE comp,
{
TArray<char> result;

if (clsHnd != NO_CLASS_HANDLE)
if (includeAssembly)
{
const char *pAssemblyName = comp->getClassAssemblyName(clsHnd);
AppendString(printer, pAssemblyName);
printer->Add('!');
}

if (includeClass)
{
AppendType(comp, printer, clsHnd, includeClassInstantiation);
printer->Add(':');
Expand Down Expand Up @@ -268,6 +277,8 @@ TArray<char> PrintMethodName(COMP_HANDLE comp,
CORINFO_CLASS_HANDLE clsHnd,
CORINFO_METHOD_HANDLE methHnd,
CORINFO_SIG_INFO* sig,
bool includeAssembly,
bool includeClass,
bool includeClassInstantiation,
bool includeMethodInstantiation,
bool includeSignature,
Expand All @@ -276,6 +287,7 @@ TArray<char> PrintMethodName(COMP_HANDLE comp,
{
TArray<char> printer;
AppendMethodName(comp, &printer, clsHnd, methHnd, sig,
includeAssembly, includeClass,
includeClassInstantiation, includeMethodInstantiation,
includeSignature, includeReturnType, includeThisSpecifier);
printer.Add('\0'); // Ensure null-termination
Expand Down
2 changes: 2 additions & 0 deletions src/coreclr/jit/compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -8321,6 +8321,8 @@ class Compiler
CORINFO_CLASS_HANDLE clsHnd,
CORINFO_METHOD_HANDLE methodHnd,
CORINFO_SIG_INFO* sig,
bool includeAssembly,
bool includeClass,
bool includeClassInstantiation,
bool includeMethodInstantiation,
bool includeSignature,
Expand Down
27 changes: 23 additions & 4 deletions src/coreclr/jit/eeinterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -248,9 +248,11 @@ void AppendCorInfoTypeWithModModifiers(StringPrinter* printer, CorInfoTypeWithMo
//
// Arguments:
// printer - the printer
// clsHnd - Handle for the owning class, or NO_CLASS_HANDLE to not print the class.
// clsHnd - Handle for the owning class.
// sig - The signature of the method.
// includeClassInstantiation - Whether to print the class instantiation. Only valid when clsHnd is passed.
// includeAssembly - Whether to print the assembly name.
// includeClass - Whether to print the class name.
// includeClassInstantiation - Whether to print the class instantiation. Only valid when includeClass is passed.
// includeMethodInstantiation - Whether to print the method instantiation. Requires the signature to be passed.
// includeSignature - Whether to print the signature.
// includeReturnType - Whether to include the return type at the end.
Expand All @@ -261,6 +263,8 @@ void Compiler::eePrintMethod(StringPrinter* printer,
CORINFO_CLASS_HANDLE clsHnd,
CORINFO_METHOD_HANDLE methHnd,
CORINFO_SIG_INFO* sig,
bool includeAssembly,
bool includeClass,
bool includeClassInstantiation,
bool includeMethodInstantiation,
bool includeSignature,
Expand All @@ -275,7 +279,14 @@ void Compiler::eePrintMethod(StringPrinter* printer,
return;
}

if (clsHnd != NO_CLASS_HANDLE)
if (includeAssembly)
{
const char* pAssemblyName = info.compCompHnd->getClassAssemblyName(clsHnd);
printer->Append(pAssemblyName);
printer->Append('!');
}

if (includeClass)
{
eePrintType(printer, clsHnd, includeClassInstantiation);
printer->Append(':');
Expand Down Expand Up @@ -432,6 +443,8 @@ const char* Compiler::eeGetMethodFullName(
CORINFO_SIG_INFO sig;
eeGetMethodSig(hnd, &sig);
eePrintMethod(&p, clsHnd, hnd, &sig,
/* includeAssembly */ false,
/* includeClass */ true,
/* includeClassInstantiation */ true,
/* includeMethodInstantiation */ true,
/* includeSignature */ true, includeReturnType, includeThisSpecifier);
Expand All @@ -448,6 +461,8 @@ const char* Compiler::eeGetMethodFullName(
success = eeRunFunctorWithSPMIErrorTrap([&]() {
eePrintMethod(&p, clsHnd, hnd,
/* sig */ nullptr,
/* includeAssembly */ false,
/* includeClass */ true,
/* includeClassInstantiation */ false,
/* includeMethodInstantiation */ false,
/* includeSignature */ false,
Expand All @@ -464,8 +479,10 @@ const char* Compiler::eeGetMethodFullName(
p.Truncate(0);

success = eeRunFunctorWithSPMIErrorTrap([&]() {
eePrintMethod(&p, nullptr, hnd,
eePrintMethod(&p, NO_CLASS_HANDLE, hnd,
/* sig */ nullptr,
/* includeAssembly */ false,
/* includeClass */ false,
/* includeClassInstantiation */ false,
/* includeMethodInstantiation */ false,
/* includeSignature */ false,
Expand Down Expand Up @@ -504,6 +521,8 @@ const char* Compiler::eeGetMethodName(CORINFO_METHOD_HANDLE methHnd, char* buffe
bool success = eeRunFunctorWithSPMIErrorTrap([&]() {
eePrintMethod(&p, NO_CLASS_HANDLE, methHnd,
/* sig */ nullptr,
/* includeAssembly */ false,
/* includeClass */ false,
/* includeClassInstantiation */ false,
/* includeMethodInstantiation */ false,
/* includeSignature */ false,
Expand Down
13 changes: 9 additions & 4 deletions src/coreclr/jit/jitconfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,18 @@ void JitConfigValues::MethodSet::initialize(const char* listFromConfig, ICorJitH
name->m_next = m_names;
name->m_patternStart = start;
name->m_patternEnd = end;
const char* colon = static_cast<const char*>(memchr(start, ':', end - start));
const char* startOfMethodName = colon != nullptr ? colon + 1 : start;
const char* exclamation = static_cast<const char*>(memchr(start, '!', end - start));
const char* startOfClassName = exclamation != nullptr ? exclamation + 1 : start;
const char* colon = static_cast<const char*>(memchr(startOfClassName, ':', end - startOfClassName));
const char* startOfMethodName = colon != nullptr ? colon + 1 : startOfClassName;

const char* parens = static_cast<const char*>(memchr(startOfMethodName, '(', end - startOfMethodName));
const char* endOfMethodName = parens != nullptr ? parens : end;
name->m_methodNameContainsInstantiation =
memchr(startOfMethodName, '[', endOfMethodName - startOfMethodName) != nullptr;

name->m_containsAssemblyName = (exclamation != nullptr);

if (colon != nullptr)
{
name->m_containsClassName = true;
Expand Down Expand Up @@ -164,8 +168,9 @@ bool JitConfigValues::MethodSet::contains(CORINFO_METHOD_HANDLE methodHnd,
{
printer.Truncate(0);
bool success = comp->eeRunFunctorWithSPMIErrorTrap([&]() {
comp->eePrintMethod(&printer, name->m_containsClassName ? classHnd : NO_CLASS_HANDLE, methodHnd,
sigInfo,
comp->eePrintMethod(&printer, classHnd, methodHnd, sigInfo,
/* includeAssembly */ name->m_containsAssemblyName,
/* includeClass */ name->m_containsClassName,
/* includeClassInstantiation */ name->m_classNameContainsInstantiation,
/* includeMethodInstantiation */ name->m_methodNameContainsInstantiation,
/* includeSignature */ name->m_containsSignature,
Expand Down
1 change: 1 addition & 0 deletions src/coreclr/jit/jitconfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class JitConfigValues
MethodName* m_next;
const char* m_patternStart;
const char* m_patternEnd;
bool m_containsAssemblyName;
bool m_containsClassName;
bool m_classNameContainsInstantiation;
bool m_methodNameContainsInstantiation;
Expand Down
Loading