From 45f6fb772e958c36932d7989fa513163e23f052f Mon Sep 17 00:00:00 2001 From: Bruce Forstall Date: Fri, 26 Jan 2024 12:40:56 -0800 Subject: [PATCH] Display names of handles in dumps For class/method/field handles, display their name in dumps in addition to their handle value. Also fixes a problem in assertion prop dumping where 64-bit class handle constants were truncated to 32-bit in dump. --- src/coreclr/jit/assertionprop.cpp | 7 ++++--- src/coreclr/jit/gentree.cpp | 16 ++++++++-------- src/coreclr/jit/valuenum.cpp | 14 ++++++++++++++ 3 files changed, 26 insertions(+), 11 deletions(-) diff --git a/src/coreclr/jit/assertionprop.cpp b/src/coreclr/jit/assertionprop.cpp index 195e28ee845ed..9d06c381599f0 100644 --- a/src/coreclr/jit/assertionprop.cpp +++ b/src/coreclr/jit/assertionprop.cpp @@ -856,12 +856,13 @@ void Compiler::optPrintAssertion(AssertionDsc* curAssertion, AssertionIndex asse case O2K_IND_CNS_INT: if (curAssertion->op1.kind == O1K_EXACT_TYPE) { - printf("Exact Type MT(%08X)", dspPtr(curAssertion->op2.u1.iconVal)); - assert(curAssertion->op2.HasIconFlag()); + ssize_t iconVal = curAssertion->op2.u1.iconVal; + printf("Exact Type MT(0x%p %s)", dspPtr(iconVal), eeGetClassName((CORINFO_CLASS_HANDLE)iconVal)); } else if (curAssertion->op1.kind == O1K_SUBTYPE) { - printf("MT(%08X)", dspPtr(curAssertion->op2.u1.iconVal)); + ssize_t iconVal = curAssertion->op2.u1.iconVal; + printf("MT(0x%p %s)", dspPtr(iconVal), eeGetClassName((CORINFO_CLASS_HANDLE)iconVal)); assert(curAssertion->op2.HasIconFlag()); } else if ((curAssertion->op1.kind == O1K_BOUND_OPER_BND) || diff --git a/src/coreclr/jit/gentree.cpp b/src/coreclr/jit/gentree.cpp index 1d314a39d27ae..7f559660d5272 100644 --- a/src/coreclr/jit/gentree.cpp +++ b/src/coreclr/jit/gentree.cpp @@ -11899,12 +11899,12 @@ void Compiler::gtDispConst(GenTree* tree) } else { - ssize_t dspIconVal = - tree->IsIconHandle() ? dspPtr(tree->AsIntCon()->gtIconVal) : tree->AsIntCon()->gtIconVal; + ssize_t iconVal = tree->AsIntCon()->gtIconVal; + ssize_t dspIconVal = tree->IsIconHandle() ? dspPtr(iconVal) : iconVal; if (tree->TypeGet() == TYP_REF) { - if (tree->AsIntCon()->gtIconVal == 0) + if (iconVal == 0) { printf(" null"); } @@ -11914,12 +11914,12 @@ void Compiler::gtDispConst(GenTree* tree) printf(" 0x%llx", dspIconVal); } } - else if ((tree->AsIntCon()->gtIconVal > -1000) && (tree->AsIntCon()->gtIconVal < 1000)) + else if ((iconVal > -1000) && (iconVal < 1000)) { printf(" %ld", dspIconVal); } #ifdef TARGET_64BIT - else if ((tree->AsIntCon()->gtIconVal & 0xFFFFFFFF00000000LL) != 0) + else if ((iconVal & 0xFFFFFFFF00000000LL) != 0) { if (dspIconVal >= 0) { @@ -11951,13 +11951,13 @@ void Compiler::gtDispConst(GenTree* tree) printf(" scope"); break; case GTF_ICON_CLASS_HDL: - printf(" class"); + printf(" class %s", eeGetClassName((CORINFO_CLASS_HANDLE)iconVal)); break; case GTF_ICON_METHOD_HDL: - printf(" method"); + printf(" method %s", eeGetMethodFullName((CORINFO_METHOD_HANDLE)iconVal)); break; case GTF_ICON_FIELD_HDL: - printf(" field"); + printf(" field %s", eeGetFieldName((CORINFO_FIELD_HANDLE)iconVal, true)); break; case GTF_ICON_STATIC_HDL: printf(" static"); diff --git a/src/coreclr/jit/valuenum.cpp b/src/coreclr/jit/valuenum.cpp index ebfdd52da3b55..22f48da191121 100644 --- a/src/coreclr/jit/valuenum.cpp +++ b/src/coreclr/jit/valuenum.cpp @@ -8933,6 +8933,20 @@ void ValueNumStore::vnDump(Compiler* comp, ValueNum vn, bool isPtr) ssize_t val = ConstantValue(vn); const GenTreeFlags handleFlags = GetHandleFlags(vn); printf("Hnd const: 0x%p %s", dspPtr(val), GenTree::gtGetHandleKindString(handleFlags)); + switch (handleFlags & GTF_ICON_HDL_MASK) + { + case GTF_ICON_CLASS_HDL: + printf(" %s", comp->eeGetClassName((CORINFO_CLASS_HANDLE)val)); + break; + case GTF_ICON_METHOD_HDL: + printf(" %s", comp->eeGetMethodFullName((CORINFO_METHOD_HANDLE)val)); + break; + case GTF_ICON_FIELD_HDL: + printf(" %s", comp->eeGetFieldName((CORINFO_FIELD_HANDLE)val, true)); + break; + default: + break; + } } else if (IsVNConstant(vn)) {