Skip to content

Commit

Permalink
JIT: Added DOTNET_JitRawHexCode/JitRawHexCodeFile (#94896)
Browse files Browse the repository at this point in the history
* Added DOTNET_JitDisasmHexDumpFile

* Feedback. Removed old hexdmp code as it was not being used.

* minor cleanup
  • Loading branch information
TIHan authored Nov 18, 2023
1 parent 925b3d4 commit 9bc37cb
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 75 deletions.
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 @@ -2836,7 +2836,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 @@ -9720,7 +9720,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 @@ -677,6 +677,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)
{
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

0 comments on commit 9bc37cb

Please sign in to comment.