Skip to content

Commit f9ce5db

Browse files
Ignore missing SPMI data when printing string literals (#118303)
1 parent 35ffd43 commit f9ce5db

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
@@ -12176,19 +12176,7 @@ void Compiler::gtDispConst(GenTree* tree)
1217612176
break;
1217712177
}
1217812178

12179-
constexpr int maxLiteralLength = 256;
12180-
char16_t str[maxLiteralLength] = {};
12181-
int len = info.compCompHnd->getStringLiteral(cnsStr->gtScpHnd, cnsStr->gtSconCPX, str, maxLiteralLength);
12182-
if (len < 0)
12183-
{
12184-
printf("<unknown string literal>");
12185-
}
12186-
else
12187-
{
12188-
char dst[maxLiteralLength];
12189-
convertUtf16ToUtf8ForPrinting(str, len, dst, maxLiteralLength);
12190-
printf("\"%.50s%s\"", dst, len > 50 ? "..." : "");
12191-
}
12179+
eePrintStringLiteral(cnsStr->gtScpHnd, cnsStr->gtSconCPX);
1219212180
}
1219312181
break;
1219412182

0 commit comments

Comments
 (0)