Skip to content

Commit 05067f3

Browse files
Ignore missing SPMI data when printing string literals
1 parent 9df2042 commit 05067f3

File tree

3 files changed

+33
-13
lines changed

3 files changed

+33
-13
lines changed

src/coreclr/jit/compiler.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8279,6 +8279,8 @@ class Compiler
82798279

82808280
const char* eeGetClassAssemblyName(CORINFO_CLASS_HANDLE clsHnd);
82818281

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

src/coreclr/jit/eeinterface.cpp

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

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

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)