Skip to content

Commit dce18f5

Browse files
authored
Fix output of FieldRef token (#3170)
***NO_CI***
1 parent f12acf5 commit dce18f5

File tree

3 files changed

+22
-9
lines changed

3 files changed

+22
-9
lines changed

src/CLR/Diagnostics/Diagnostics_stub.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//
1+
//
22
// Copyright (c) .NET Foundation and Contributors
33
// Portions Copyright (c) Microsoft Corporation. All rights reserved.
44
// See LICENSE file in the project root for full license information.
@@ -112,7 +112,7 @@ __nfweak const CLR_UINT8 *CLR_SkipBodyOfOpcodeCompressed(const CLR_UINT8 *ip, CL
112112

113113
#if defined(NANOCLR_TRACE_INSTRUCTIONS)
114114

115-
__nfweak void CLR_RT_Assembly::DumpToken(CLR_UINT32 tk)
115+
__nfweak void CLR_RT_Assembly::DumpToken(CLR_UINT32 tk, const CLR_RT_TypeSpec_Index *genericType)
116116
{
117117
NATIVE_PROFILE_CLR_DIAGNOSTICS();
118118
}

src/CLR/Diagnostics/Info.cpp

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,7 @@ const CLR_UINT8 *CLR_SkipBodyOfOpcodeCompressed(const CLR_UINT8 *ip, CLR_OPCODE
413413

414414
#if defined(NANOCLR_TRACE_INSTRUCTIONS)
415415

416-
void CLR_RT_Assembly::DumpToken(CLR_UINT32 token)
416+
void CLR_RT_Assembly::DumpToken(CLR_UINT32 token, const CLR_RT_TypeSpec_Index *genericType)
417417
{
418418
NATIVE_PROFILE_CLR_DIAGNOSTICS();
419419
CLR_UINT32 index = CLR_DataFromTk(token);
@@ -443,14 +443,27 @@ void CLR_RT_Assembly::DumpToken(CLR_UINT32 token)
443443
}
444444
case TBL_FieldRef:
445445
{
446-
LOOKUP_ELEMENT_REF(index, FieldRef, FIELDREF, FieldDef);
447-
if (s)
446+
const CLR_RECORD_FIELDREF *fr = GetFieldRef(index);
447+
const auto &xref = crossReferenceFieldRef[index];
448+
449+
// If the caller passed in a closed‐generic TypeSpec, use that …
450+
if (genericType->data != CLR_EmptyToken)
448451
{
449-
CLR_RT_DUMP::FIELD(*s);
452+
// Build the closed‐generic owner name
453+
char rgType[256], *sz = rgType;
454+
size_t cb = sizeof(rgType);
455+
g_CLR_RT_TypeSystem.BuildTypeName(*genericType, sz, cb);
456+
457+
// Append the field name
458+
CLR_SafeSprintf(sz, cb, "::%s", GetString(fr->name));
459+
CLR_Debug::Printf("%s", rgType);
450460
}
451461
else
452462
{
453-
CLR_Debug::Printf("%s", GetString(p->name));
463+
// Otherwise fall back to the old FieldDef path
464+
CLR_RT_FieldDef_Index fd;
465+
fd.Set(assemblyIndex, xref.target.data);
466+
CLR_RT_DUMP::FIELD(fd);
454467
}
455468
break;
456469
}
@@ -662,7 +675,7 @@ void CLR_RT_Assembly::DumpOpcodeDirect(
662675

663676
if (IsOpParamToken(opParam))
664677
{
665-
DumpToken(CLR_ReadTokenCompressed(ip, op));
678+
DumpToken(CLR_ReadTokenCompressed(ip, op), call.genericType);
666679
}
667680
else
668681
{

src/CLR/Include/nanoCLR_Runtime.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1558,7 +1558,7 @@ struct CLR_RT_Assembly : public CLR_RT_HeapBlock_Node // EVENT HEAP - NO RELOCAT
15581558
DECL_POSTFIX;
15591559

15601560
private:
1561-
void DumpToken(CLR_UINT32 tk) DECL_POSTFIX;
1561+
void DumpToken(CLR_UINT32 tk, const CLR_RT_TypeSpec_Index *genericType) DECL_POSTFIX;
15621562
void DumpSignature(CLR_SIG sig) DECL_POSTFIX;
15631563
void DumpSignature(CLR_PMETADATA &p) DECL_POSTFIX;
15641564
void DumpSignatureToken(CLR_PMETADATA &p) DECL_POSTFIX;

0 commit comments

Comments
 (0)