Skip to content

Commit 508ac66

Browse files
Ignore missing SPMI data when printing string literals
1 parent 9df2042 commit 508ac66

File tree

3 files changed

+35
-13
lines changed

3 files changed

+35
-13
lines changed

src/coreclr/jit/compiler.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8280,6 +8280,8 @@ class Compiler
82808280
const char* eeGetClassAssemblyName(CORINFO_CLASS_HANDLE clsHnd);
82818281

82828282
#if defined(DEBUG)
8283+
void eePrintStringLiteral(CORINFO_MODULE_HANDLE module, unsigned token);
8284+
82838285
unsigned eeTryGetClassSize(CORINFO_CLASS_HANDLE clsHnd);
82848286
#endif
82858287

src/coreclr/jit/eeinterface.cpp

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -692,3 +692,35 @@ void Compiler::eePrintObjectDescription(const char* prefix, CORINFO_OBJECT_HANDL
692692

693693
printf("%s '%s'", prefix, str);
694694
}
695+
696+
#ifdef DEBUG
697+
//------------------------------------------------------------------------
698+
// eePrintStringLiteral:
699+
// Print a string literal. If missing information (in SPMI),
700+
// then print a placeholder string.
701+
//
702+
// Arguments:
703+
// module - The literal's scope handle
704+
// token - The literal's token
705+
//
706+
void Compiler::eePrintStringLiteral(CORINFO_MODULE_HANDLE module, unsigned token)
707+
{
708+
const int MAX_LITERAL_LENGTH = 256;
709+
char16_t str[MAX_LITERAL_LENGTH] = {};
710+
int length = -1;
711+
eeRunFunctorWithSPMIErrorTrap([&]() {
712+
length = info.compCompHnd->getStringLiteral(module, token, str, MAX_LITERAL_LENGTH);
713+
});
714+
715+
if (length < 0)
716+
{
717+
printf("<unknown string literal>");
718+
}
719+
else
720+
{
721+
char dst[MAX_LITERAL_LENGTH];
722+
convertUtf16ToUtf8ForPrinting(str, length, dst, MAX_LITERAL_LENGTH);
723+
printf("\"%.50s%s\"", dst, length > 50 ? "..." : "");
724+
}
725+
}
726+
#endif // DEBUG

src/coreclr/jit/gentree.cpp

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12279,19 +12279,7 @@ void Compiler::gtDispConst(GenTree* tree)
1227912279
break;
1228012280
}
1228112281

12282-
constexpr int maxLiteralLength = 256;
12283-
char16_t str[maxLiteralLength] = {};
12284-
int len = info.compCompHnd->getStringLiteral(cnsStr->gtScpHnd, cnsStr->gtSconCPX, str, maxLiteralLength);
12285-
if (len < 0)
12286-
{
12287-
printf("<unknown string literal>");
12288-
}
12289-
else
12290-
{
12291-
char dst[maxLiteralLength];
12292-
convertUtf16ToUtf8ForPrinting(str, len, dst, maxLiteralLength);
12293-
printf("\"%.50s%s\"", dst, len > 50 ? "..." : "");
12294-
}
12282+
eePrintStringLiteral(cnsStr->gtScpHnd, cnsStr->gtSconCPX);
1229512283
}
1229612284
break;
1229712285

0 commit comments

Comments
 (0)