diff --git a/src/coreclr/jit/codegencommon.cpp b/src/coreclr/jit/codegencommon.cpp index 225700208b4a2d..744462af3d7ab0 100644 --- a/src/coreclr/jit/codegencommon.cpp +++ b/src/coreclr/jit/codegencommon.cpp @@ -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, "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 */ diff --git a/src/coreclr/jit/compiler.cpp b/src/coreclr/jit/compiler.cpp index 355403baa92684..fa72c8139b9324 100644 --- a/src/coreclr/jit/compiler.cpp +++ b/src/coreclr/jit/compiler.cpp @@ -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; diff --git a/src/coreclr/jit/compiler.h b/src/coreclr/jit/compiler.h index 48a3278077f622..bf68511f1ee268 100644 --- a/src/coreclr/jit/compiler.h +++ b/src/coreclr/jit/compiler.h @@ -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. diff --git a/src/coreclr/jit/jitconfigvalues.h b/src/coreclr/jit/jitconfigvalues.h index 65afd348819e11..7c0c69e238c2f8 100644 --- a/src/coreclr/jit/jitconfigvalues.h +++ b/src/coreclr/jit/jitconfigvalues.h @@ -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: diff --git a/src/coreclr/jit/utils.cpp b/src/coreclr/jit/utils.cpp index 099155e85f0b98..50885fb94da722 100644 --- a/src/coreclr/jit/utils.cpp +++ b/src/coreclr/jit/utils.cpp @@ -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) { @@ -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 diff --git a/src/coreclr/jit/utils.h b/src/coreclr/jit/utils.h index 747daf9d719d46..1eaa16d67ba81e 100644 --- a/src/coreclr/jit/utils.h +++ b/src/coreclr/jit/utils.h @@ -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 /****************************************************************************** diff --git a/src/coreclr/tools/superpmi/superpmi-shim-collector/jithost.cpp b/src/coreclr/tools/superpmi/superpmi-shim-collector/jithost.cpp index 2917fdab80cb43..29cfc53e86fc73 100644 --- a/src/coreclr/tools/superpmi/superpmi-shim-collector/jithost.cpp +++ b/src/coreclr/tools/superpmi/superpmi-shim-collector/jithost.cpp @@ -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)