Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JIT: Added DOTNET_JitRawHexCode/JitRawHexCodeFile #94896

Merged
merged 3 commits into from
Nov 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 24 additions & 61 deletions src/coreclr/jit/codegencommon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2097,78 +2097,41 @@ void CodeGen::genEmitUnwindDebugGCandEH()
getDisAssembler().disAsmCode((BYTE*)*codePtr, finalHotCodeSize, (BYTE*)coldCodePtr, finalColdCodeSize);
#endif // LATE_DISASM

/* Report any exception handlers to the VM */

genReportEH();

#ifdef JIT32_GCENCODER
#ifdef DEBUG
void* infoPtr =
#endif // DEBUG
#endif
// Create and store the GC info for this method.
genCreateAndStoreGCInfo(codeSize, prologSize, epilogSize DEBUGARG(codePtr));

#ifdef DEBUG
FILE* dmpf = jitstdout();

compiler->opts.dmpHex = false;
if (!strcmp(compiler->info.compMethodName, "<name of method you want the hex dump for"))
{
FILE* codf;
errno_t ec = fopen_s(&codf, "C:\\JIT.COD", "at"); // NOTE: file append mode
if (ec != 0)
{
assert(codf);
dmpf = codf;
compiler->opts.dmpHex = true;
}
}
if (compiler->opts.dmpHex)
if (JitConfig.JitRawHexCode().contains(compiler->info.compMethodHnd, compiler->info.compClassHnd,
&compiler->info.compMethodInfo->args))
{
size_t consSize = GetEmitter()->emitDataSize();
BYTE* addr = (BYTE*)*codePtr + compiler->GetEmitter()->writeableOffset;

fprintf(dmpf, "Generated code for %s:\n", compiler->info.compFullName);
fprintf(dmpf, "\n");

if (codeSize)
const WCHAR* rawHexCodeFilePath = JitConfig.JitRawHexCodeFile();
if (rawHexCodeFilePath)
{
fprintf(dmpf, " Code at %p [%04X bytes]\n", dspPtr(*codePtr), codeSize);
FILE* hexDmpf;
errno_t ec = _wfopen_s(&hexDmpf, rawHexCodeFilePath, W("at")); // NOTE: file append mode
if (ec == 0)
{
assert(hexDmpf);
hexDump(hexDmpf, addr, codeSize);
fclose(hexDmpf);
}
}
if (consSize)
else
{
fprintf(dmpf, " Const at %p [%04X bytes]\n", dspPtr(consPtr), consSize);
}
#ifdef JIT32_GCENCODER
size_t infoSize = compiler->compInfoBlkSize;
if (infoSize)
fprintf(dmpf, " Info at %p [%04X bytes]\n", dspPtr(infoPtr), infoSize);
#endif // JIT32_GCENCODER
FILE* dmpf = jitstdout();

fprintf(dmpf, "\n");

if (codeSize)
{
hexDump(dmpf, "Code", (BYTE*)*codePtr, codeSize);
fprintf(dmpf, "Generated native code for %s:\n", compiler->info.compFullName);
hexDump(dmpf, addr, codeSize);
fprintf(dmpf, "\n\n");
}
if (consSize)
{
hexDump(dmpf, "Const", (BYTE*)consPtr, consSize);
}
#ifdef JIT32_GCENCODER
if (infoSize)
hexDump(dmpf, "Info", (BYTE*)infoPtr, infoSize);
#endif // JIT32_GCENCODER

fflush(dmpf);
}
#endif // DEBUG

if (dmpf != jitstdout())
{
fclose(dmpf);
}
/* Report any exception handlers to the VM */

#endif // DEBUG
genReportEH();

// Create and store the GC info for this method.
genCreateAndStoreGCInfo(codeSize, prologSize, epilogSize DEBUGARG(codePtr));

/* Tell the emitter that we're done with this function */

Expand Down
1 change: 0 additions & 1 deletion src/coreclr/jit/compiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2835,7 +2835,6 @@ void Compiler::compInitOptions(JitFlags* jitFlags)
opts.dspInstrs = false;
opts.dspLines = false;
opts.varNames = false;
opts.dmpHex = false;
opts.disAsmSpilled = false;
opts.disAddr = false;
opts.dspCode = false;
Expand Down
1 change: 0 additions & 1 deletion src/coreclr/jit/compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -9711,7 +9711,6 @@ XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
bool dspDebugInfo; // Display the Debug info reported to the VM
bool dspInstrs; // Display the IL instructions intermixed with the native code output
bool dspLines; // Display source-code lines intermixed with native code output
bool dmpHex; // Display raw bytes in hex of native code output
bool varNames; // Display variables names in native code output
bool disAsmSpilled; // Display native code when any register spilling occurs
bool disasmWithGC; // Display GC info interleaved with disassembly.
Expand Down
5 changes: 5 additions & 0 deletions src/coreclr/jit/jitconfigvalues.h
Original file line number Diff line number Diff line change
Expand Up @@ -676,6 +676,11 @@ CONFIG_INTEGER(JitEnableCrossBlockLocalAssertionProp, W("JitEnableCrossBlockLoca
CONFIG_STRING(JitFunctionFile, W("JitFunctionFile"))
#endif // DEBUG

#if defined(DEBUG)
CONFIG_METHODSET(JitRawHexCode, W("JitRawHexCode"))
CONFIG_STRING(JitRawHexCodeFile, W("JitRawHexCodeFile"))
#endif // DEBUG

#if defined(DEBUG)
#if defined(TARGET_ARM64)
// JitSaveFpLrWithCalleeSavedRegisters:
Expand Down
13 changes: 2 additions & 11 deletions src/coreclr/jit/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1319,7 +1319,7 @@ int SimpleSprintf_s(_In_reads_(cbBufSize - (pWriteStart - pBufStart)) char* pWri

#ifdef DEBUG

void hexDump(FILE* dmpf, const char* name, BYTE* addr, size_t size)
void hexDump(FILE* dmpf, BYTE* addr, size_t size)
{
if (!size)
{
Expand All @@ -1328,19 +1328,10 @@ void hexDump(FILE* dmpf, const char* name, BYTE* addr, size_t size)

assert(addr);

fprintf(dmpf, "Hex dump of %s:\n", name);

for (unsigned i = 0; i < size; i++)
{
if ((i % 16) == 0)
TIHan marked this conversation as resolved.
Show resolved Hide resolved
{
fprintf(dmpf, "\n %04X: ", i);
}

fprintf(dmpf, "%02X ", *addr++);
fprintf(dmpf, "%02X", *addr++);
}

fprintf(dmpf, "\n\n");
}

#endif // DEBUG
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/jit/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ int SimpleSprintf_s(_In_reads_(cbBufSize - (pWriteStart - pBufStart)) char* pWri
...);

#ifdef DEBUG
void hexDump(FILE* dmpf, const char* name, BYTE* addr, size_t size);
void hexDump(FILE* dmpf, BYTE* addr, size_t size);
#endif // DEBUG

/******************************************************************************
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ bool RecordVariable(const WCHAR* key)
W("JitInlinePolicyDumpXml"),
W("JitInlineReplayFile"),
W("JitFunctionFile")
W("JitRawHexCode"),
W("JitRawHexCodeFile")
};

for (const WCHAR* ignoredVar : s_ignoredVars)
Expand Down
Loading