Skip to content

Commit

Permalink
Add JitDasmWithAddress switch to print the process address of every i…
Browse files Browse the repository at this point in the history
…nstruction (dotnet#43120)

* Add COMPlus_JitDasmWithAddress to print the address

* Remove dspEmit variable

* remove the square brackets

* review comments

* always display offset

* fix the reference of JitDasmWithAddress
  • Loading branch information
kunalspathak authored Oct 12, 2020
1 parent bcc8412 commit b8a92e5
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 37 deletions.
10 changes: 8 additions & 2 deletions src/coreclr/src/jit/compiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2814,13 +2814,13 @@ void Compiler::compInitOptions(JitFlags* jitFlags)

#ifdef DEBUG
opts.dspInstrs = false;
opts.dspEmit = false;
opts.dspLines = false;
opts.varNames = false;
opts.dmpHex = false;
opts.disAsm = false;
opts.disAsmSpilled = false;
opts.disDiffable = false;
opts.disAddr = false;
opts.dspCode = false;
opts.dspEHTable = false;
opts.dspDebugInfo = false;
Expand Down Expand Up @@ -2963,6 +2963,12 @@ void Compiler::compInitOptions(JitFlags* jitFlags)
opts.dspDiffable = true;
}

// This one applies to both Ngen/Jit Disasm output: COMPlus_JitDasmWithAddress=1
if (JitConfig.JitDasmWithAddress() != 0)
{
opts.disAddr = true;
}

if (JitConfig.JitLongAddress() != 0)
{
opts.compLongAddress = true;
Expand Down Expand Up @@ -6105,7 +6111,7 @@ int Compiler::compCompileHelper(CORINFO_MODULE_HANDLE classPtr,
#ifdef DEBUG
/* Give the function a unique number */

if (opts.disAsm || opts.dspEmit || verbose)
if (opts.disAsm || verbose)
{
compMethodID = ~info.compMethodHash() & 0xffff;
}
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/src/jit/compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -8937,14 +8937,14 @@ XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
bool dspEHTable; // Display the EH table reported to the VM
bool dspDebugInfo; // Display the Debug info reported to the VM
bool dspInstrs; // Display the IL instructions intermixed with the native code output
bool dspEmit; // Display emitter 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 disAsm; // Display native code as it is generated
bool disAsmSpilled; // Display native code when any register spilling occurs
bool disasmWithGC; // Display GC info interleaved with disassembly.
bool disDiffable; // Makes the Disassembly code 'diff-able'
bool disAddr; // Display process address next to each instruction in disassembly code
bool disAsm2; // Display native code after it is generated using external disassembler
bool dspOrder; // Display names of each of the methods that we ngen/jit
bool dspUnwind; // Display the unwind info output
Expand Down
44 changes: 17 additions & 27 deletions src/coreclr/src/jit/emit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1211,6 +1211,14 @@ void emitter::appendToCurIG(instrDesc* id)

#ifdef DEBUG

void emitter::emitDispInsAddr(BYTE* code)
{
if (emitComp->opts.disAddr)
{
printf(FMT_ADDR, DBG_ADDR(code));
}
}

void emitter::emitDispInsOffs(unsigned offs, bool doffs)
{
if (doffs)
Expand Down Expand Up @@ -5054,7 +5062,7 @@ unsigned emitter::emitEndCodeGen(Compiler* comp,
assert(coldCodeBlock);
cp = coldCodeBlock;
#ifdef DEBUG
if (emitComp->opts.disAsm || emitComp->opts.dspEmit || emitComp->verbose)
if (emitComp->opts.disAsm || emitComp->verbose)
{
printf("\n************** Beginning of cold code **************\n");
}
Expand All @@ -5077,7 +5085,7 @@ unsigned emitter::emitEndCodeGen(Compiler* comp,
#ifdef DEBUG
/* Print the IG label, but only if it is a branch label */

if (emitComp->opts.disAsm || emitComp->opts.dspEmit || emitComp->verbose)
if (emitComp->opts.disAsm || emitComp->verbose)
{
if (emitComp->verbose || emitComp->opts.disasmWithGC)
{
Expand All @@ -5086,7 +5094,12 @@ unsigned emitter::emitEndCodeGen(Compiler* comp,
}
else
{
printf("\nG_M%03u_IG%02u:\n", emitComp->compMethodID, ig->igNum);
printf("\nG_M%03u_IG%02u:", emitComp->compMethodID, ig->igNum);
if (!emitComp->opts.disDiffable)
{
printf(" ;; offset=%04XH", ig->igOffs);
}
printf("\n");
}
}
#endif // DEBUG
Expand Down Expand Up @@ -5184,7 +5197,7 @@ unsigned emitter::emitEndCodeGen(Compiler* comp,
}

#ifdef DEBUG
if (emitComp->opts.disAsm || emitComp->opts.dspEmit || emitComp->verbose)
if (emitComp->opts.disAsm || emitComp->verbose)
{
printf("\t\t\t\t\t\t;; bbWeight=%s PerfScore %.2f", refCntWtd2str(ig->igWeight), ig->igPerfScore);
}
Expand Down Expand Up @@ -6472,10 +6485,6 @@ unsigned char emitter::emitOutputByte(BYTE* dst, ssize_t val)
*castto(dst, unsigned char*) = (unsigned char)val;

#ifdef DEBUG
if (emitComp->opts.dspEmit)
{
printf("; emit_byte 0%02XH\n", val & 0xFF);
}
#ifdef TARGET_AMD64
// if we're emitting code bytes, ensure that we've already emitted the rex prefix!
assert(((val & 0xFF00000000LL) == 0) || ((val & 0xFFFFFFFF00000000LL) == 0xFFFFFFFF00000000LL));
Expand All @@ -6495,10 +6504,6 @@ unsigned char emitter::emitOutputWord(BYTE* dst, ssize_t val)
MISALIGNED_WR_I2(dst, (short)val);

#ifdef DEBUG
if (emitComp->opts.dspEmit)
{
printf("; emit_word 0%02XH,0%02XH\n", (val & 0xFF), (val >> 8) & 0xFF);
}
#ifdef TARGET_AMD64
// if we're emitting code bytes, ensure that we've already emitted the rex prefix!
assert(((val & 0xFF00000000LL) == 0) || ((val & 0xFFFFFFFF00000000LL) == 0xFFFFFFFF00000000LL));
Expand All @@ -6518,10 +6523,6 @@ unsigned char emitter::emitOutputLong(BYTE* dst, ssize_t val)
MISALIGNED_WR_I4(dst, (int)val);

#ifdef DEBUG
if (emitComp->opts.dspEmit)
{
printf("; emit_long 0%08XH\n", (int)val);
}
#ifdef TARGET_AMD64
// if we're emitting code bytes, ensure that we've already emitted the rex prefix!
assert(((val & 0xFF00000000LL) == 0) || ((val & 0xFFFFFFFF00000000LL) == 0xFFFFFFFF00000000LL));
Expand All @@ -6544,17 +6545,6 @@ unsigned char emitter::emitOutputSizeT(BYTE* dst, ssize_t val)
MISALIGNED_WR_ST(dst, val);
#endif

#ifdef DEBUG
if (emitComp->opts.dspEmit)
{
#ifdef TARGET_AMD64
printf("; emit_size_t 0%016llXH\n", val);
#else // TARGET_AMD64
printf("; emit_size_t 0%08XH\n", val);
#endif // TARGET_AMD64
}
#endif // DEBUG

return TARGET_POINTER_SIZE;
}

Expand Down
1 change: 1 addition & 0 deletions src/coreclr/src/jit/emit.h
Original file line number Diff line number Diff line change
Expand Up @@ -1508,6 +1508,7 @@ class emitter
void emitDispGCinfo();
void emitDispClsVar(CORINFO_FIELD_HANDLE fldHnd, ssize_t offs, bool reloc = false);
void emitDispFrameRef(int varx, int disp, int offs, bool asmfm);
void emitDispInsAddr(BYTE* code);
void emitDispInsOffs(unsigned offs, bool doffs);
void emitDispInsHex(instrDesc* id, BYTE* code, size_t sz);

Expand Down
10 changes: 8 additions & 2 deletions src/coreclr/src/jit/emitarm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6530,7 +6530,7 @@ size_t emitter::emitOutputInstr(insGroup* ig, instrDesc* id, BYTE** dp)
size_t expected = emitSizeOfInsDsc(id);
assert(sz == expected);

if (emitComp->opts.disAsm || emitComp->opts.dspEmit || emitComp->verbose)
if (emitComp->opts.disAsm || emitComp->verbose)
{
emitDispIns(id, false, dspOffs, true, emitCurCodeOffs(odst), *dp, (dst - *dp), ig);
}
Expand Down Expand Up @@ -6976,8 +6976,14 @@ void emitter::emitDispInsHelp(
if (code == NULL)
sz = 0;

if (!emitComp->opts.dspEmit && !isNew && !asmfm && sz)
if (!isNew && !asmfm && sz)
{
doffs = true;
}

/* Display the instruction address */

emitDispInsAddr(code);

/* Display the instruction offset */

Expand Down
10 changes: 8 additions & 2 deletions src/coreclr/src/jit/emitarm64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11462,7 +11462,7 @@ size_t emitter::emitOutputInstr(insGroup* ig, instrDesc* id, BYTE** dp)
size_t expected = emitSizeOfInsDsc(id);
assert(sz == expected);

if (emitComp->opts.disAsm || emitComp->opts.dspEmit || emitComp->verbose)
if (emitComp->opts.disAsm || emitComp->verbose)
{
emitDispIns(id, false, dspOffs, true, emitCurCodeOffs(odst), *dp, (dst - *dp), ig);
}
Expand Down Expand Up @@ -12107,8 +12107,14 @@ void emitter::emitDispIns(
if (pCode == NULL)
sz = 0;

if (!emitComp->opts.dspEmit && !isNew && !asmfm && sz)
if (!isNew && !asmfm && sz)
{
doffs = true;
}

/* Display the instruction address */

emitDispInsAddr(pCode);

/* Display the instruction offset */

Expand Down
9 changes: 7 additions & 2 deletions src/coreclr/src/jit/emitxarch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8238,11 +8238,15 @@ void emitter::emitDispIns(
// printf("[A=%08X] " , emitSimpleByrefStkMask);
// printf("[L=%02u] " , id->idCodeSize());

if (!emitComp->opts.dspEmit && !isNew && !asmfm)
if (!isNew && !asmfm)
{
doffs = true;
}

/* Display the instruction address */

emitDispInsAddr(code);

/* Display the instruction offset */

emitDispInsOffs(offset, doffs);
Expand Down Expand Up @@ -13680,7 +13684,7 @@ size_t emitter::emitOutputInstr(insGroup* ig, instrDesc* id, BYTE** dp)
assert(*dp != dst || emitInstHasNoCode(ins));

#ifdef DEBUG
if (emitComp->opts.disAsm || emitComp->opts.dspEmit || emitComp->verbose)
if (emitComp->opts.disAsm || emitComp->verbose)
{
emitDispIns(id, false, dspOffs, true, emitCurCodeOffs(*dp), *dp, (dst - *dp));
}
Expand Down Expand Up @@ -13985,6 +13989,7 @@ emitter::insExecutionCharacteristics emitter::getInsExecutionCharacteristics(ins

switch (ins)
{
case INS_align:
case INS_nop:
case INS_int3:
assert(memFmt == IF_NONE);
Expand Down
4 changes: 3 additions & 1 deletion src/coreclr/src/jit/jitconfigvalues.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ CONFIG_INTEGER(BreakOnDumpToken, W("BreakOnDumpToken"), 0xffffffff) // Breaks wh
// particular token value.
CONFIG_INTEGER(DebugBreakOnVerificationFailure, W("DebugBreakOnVerificationFailure"), 0) // Halts the jit on
// verification failure
CONFIG_INTEGER(DiffableDasm, W("JitDiffableDasm"), 0) // Make the disassembly diff-able
CONFIG_INTEGER(DiffableDasm, W("JitDiffableDasm"), 0) // Make the disassembly diff-able
CONFIG_INTEGER(JitDasmWithAddress, W("JitDasmWithAddress"), 0) // Print the process address next to each instruction of
// the disassembly
CONFIG_INTEGER(DisplayLoopHoistStats, W("JitLoopHoistStats"), 0) // Display JIT loop hoisting statistics
CONFIG_INTEGER(DisplayLsraStats, W("JitLsraStats"), 0) // Display JIT Linear Scan Register Allocator statistics
CONFIG_INTEGER(DumpJittedMethods, W("DumpJittedMethods"), 0) // Prints all jitted methods to the console
Expand Down

0 comments on commit b8a92e5

Please sign in to comment.