Skip to content

Commit 032d162

Browse files
committed
Add JitDisasmWithDebugInfo
Add COMPlus_JitDisasmWithDebugInfo. When set and in verbose/disasm mode, JIT will display inline comments with debug information before the instructions that debug info applies to. Change superpmi with --debuginfo to use this mode. Also small change to dotnet-pgo flow graph dump to write offsets in the same format.
1 parent 4db3531 commit 032d162

File tree

12 files changed

+105
-42
lines changed

12 files changed

+105
-42
lines changed

src/coreclr/jit/codegenlinear.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,9 @@ void CodeGen::genCodeForBBlist()
424424
}
425425
}
426426
}
427+
428+
bool addPreciseMappings =
429+
(JitConfig.JitDumpPreciseDebugInfoFile() != nullptr) || (JitConfig.JitDisasmWithDebugInfo() != 0);
427430
#endif // DEBUG
428431

429432
DebugInfo currentDI;
@@ -443,7 +446,7 @@ void CodeGen::genCodeForBBlist()
443446
}
444447

445448
#ifdef DEBUG
446-
if ((JitConfig.JitDumpPreciseDebugInfoFile() != nullptr) && ilOffset->gtStmtDI.IsValid())
449+
if (addPreciseMappings && ilOffset->gtStmtDI.IsValid())
447450
{
448451
genAddPreciseIPMappingHere(ilOffset->gtStmtDI);
449452
}

src/coreclr/jit/emit.cpp

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3381,15 +3381,24 @@ const size_t hexEncodingSize = 11;
33813381

33823382
#ifdef DEBUG
33833383
//------------------------------------------------------------------------
3384+
// emitDispInsIndent: Print indentation corresponding to an instruction's
3385+
// indentation.
3386+
//
3387+
void emitter::emitDispInsIndent()
3388+
{
3389+
size_t indent = emitComp->opts.disDiffable ? basicIndent : basicIndent + hexEncodingSize;
3390+
printf("%.*s", indent, " ");
3391+
}
3392+
//------------------------------------------------------------------------
33843393
// emitDispGCDeltaTitle: Print an appropriately indented title for a GC info delta
33853394
//
33863395
// Arguments:
33873396
// title - The type of GC info delta we're printing
33883397
//
33893398
void emitter::emitDispGCDeltaTitle(const char* title)
33903399
{
3391-
size_t indent = emitComp->opts.disDiffable ? basicIndent : basicIndent + hexEncodingSize;
3392-
printf("%.*s; %s", indent, " ", title);
3400+
emitDispInsIndent();
3401+
printf("; %s", title);
33933402
}
33943403

33953404
//------------------------------------------------------------------------
@@ -6233,7 +6242,8 @@ unsigned emitter::emitEndCodeGen(Compiler* comp,
62336242
#define DEFAULT_CODE_BUFFER_INIT 0xcc
62346243

62356244
#ifdef DEBUG
6236-
*instrCount = 0;
6245+
*instrCount = 0;
6246+
PreciseIPMapping* nextMapping = emitComp->genPreciseIPMappingsHead;
62376247
#endif
62386248
for (insGroup* ig = emitIGlist; ig != nullptr; ig = ig->igNext)
62396249
{
@@ -6402,6 +6412,33 @@ unsigned emitter::emitEndCodeGen(Compiler* comp,
64026412
#ifdef DEBUG
64036413
size_t curInstrAddr = (size_t)cp;
64046414
instrDesc* curInstrDesc = id;
6415+
6416+
if ((emitComp->opts.disAsm || emitComp->verbose) && (JitConfig.JitDisasmWithDebugInfo() != 0))
6417+
{
6418+
UNATIVE_OFFSET curCodeOffs = emitCurCodeOffs(cp);
6419+
while (nextMapping != nullptr)
6420+
{
6421+
UNATIVE_OFFSET mappingOffs = nextMapping->nativeLoc.CodeOffset(this);
6422+
6423+
if (mappingOffs > curCodeOffs)
6424+
{
6425+
// Still haven't reached instruction that next mapping belongs to.
6426+
break;
6427+
}
6428+
6429+
// We reached the mapping or went past it.
6430+
if (mappingOffs == curCodeOffs)
6431+
{
6432+
emitDispInsIndent();
6433+
printf("; ");
6434+
nextMapping->debugInfo.Dump(true);
6435+
printf("\n");
6436+
}
6437+
6438+
nextMapping = nextMapping->next;
6439+
}
6440+
}
6441+
64056442
#endif
64066443

64076444
castto(id, BYTE*) += emitIssue1Instr(ig, id, &cp);

src/coreclr/jit/emit.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1548,6 +1548,7 @@ class emitter
15481548
regPtrDsc* debugPrevRegPtrDsc;
15491549
regMaskTP debugPrevGCrefRegs;
15501550
regMaskTP debugPrevByrefRegs;
1551+
void emitDispInsIndent();
15511552
void emitDispGCDeltaTitle(const char* title);
15521553
void emitDispGCRegDelta(const char* title, regMaskTP prevRegs, regMaskTP curRegs);
15531554
void emitDispGCVarDelta();
@@ -1563,6 +1564,14 @@ class emitter
15631564
void emitDispInsAddr(BYTE* code);
15641565
void emitDispInsOffs(unsigned offs, bool doffs);
15651566
void emitDispInsHex(instrDesc* id, BYTE* code, size_t sz);
1567+
void emitDispIns(instrDesc* id,
1568+
bool isNew,
1569+
bool doffs,
1570+
bool asmfm,
1571+
unsigned offs = 0,
1572+
BYTE* pCode = nullptr,
1573+
size_t sz = 0,
1574+
insGroup* ig = nullptr);
15661575

15671576
#else // !DEBUG
15681577
#define emitVarRefOffs 0

src/coreclr/jit/emitarm.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7670,6 +7670,22 @@ void emitter::emitDispInsHelp(
76707670
printf("\n");
76717671
}
76727672

7673+
//--------------------------------------------------------------------
7674+
// emitDispIns: Dump the given instruction to jitstdout.
7675+
//
7676+
// Arguments:
7677+
// id - The instruction
7678+
// isNew - Whether the instruction is newly generated (before encoding).
7679+
// doffs - If true, always display the passed-in offset.
7680+
// asmfm - Whether the instruction should be displayed in assembly format.
7681+
// If false some additional information may be printed for the instruction.
7682+
// offset - The offset of the instruction. Only displayed if doffs is true or if
7683+
// !isNew && !asmfm.
7684+
// code - Pointer to the actual code, used for displaying the address and encoded bytes
7685+
// if turned on.
7686+
// sz - The size of the instruction, used to display the encoded bytes.
7687+
// ig - The instruction group containing the instruction.
7688+
//
76737689
void emitter::emitDispIns(
76747690
instrDesc* id, bool isNew, bool doffs, bool asmfm, unsigned offset, BYTE* code, size_t sz, insGroup* ig)
76757691
{

src/coreclr/jit/emitarm.h

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,6 @@ void emitDispInsHelp(instrDesc* id,
5252
BYTE* code = 0,
5353
size_t sz = 0,
5454
insGroup* ig = NULL);
55-
void emitDispIns(instrDesc* id,
56-
bool isNew,
57-
bool doffs,
58-
bool asmfm,
59-
unsigned offs = 0,
60-
BYTE* code = 0,
61-
size_t sz = 0,
62-
insGroup* ig = NULL);
6355

6456
#endif // DEBUG
6557

src/coreclr/jit/emitarm64.cpp

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12228,11 +12228,22 @@ void emitter::emitDispInsHex(instrDesc* id, BYTE* code, size_t sz)
1222812228
}
1222912229
}
1223012230

12231-
/****************************************************************************
12232-
*
12233-
* Display the given instruction.
12234-
*/
12235-
12231+
//--------------------------------------------------------------------
12232+
// emitDispIns: Dump the given instruction to jitstdout.
12233+
//
12234+
// Arguments:
12235+
// id - The instruction
12236+
// isNew - Whether the instruction is newly generated (before encoding).
12237+
// doffs - If true, always display the passed-in offset.
12238+
// asmfm - Whether the instruction should be displayed in assembly format.
12239+
// If false some additional information may be printed for the instruction.
12240+
// offset - The offset of the instruction. Only displayed if doffs is true or if
12241+
// !isNew && !asmfm.
12242+
// code - Pointer to the actual code, used for displaying the address and encoded bytes
12243+
// if turned on.
12244+
// sz - The size of the instruction, used to display the encoded bytes.
12245+
// ig - The instruction group containing the instruction.
12246+
//
1223612247
void emitter::emitDispIns(
1223712248
instrDesc* id, bool isNew, bool doffs, bool asmfm, unsigned offset, BYTE* pCode, size_t sz, insGroup* ig)
1223812249
{

src/coreclr/jit/emitarm64.h

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,6 @@ void emitDispShiftedReg(regNumber reg, insOpts opt, ssize_t imm, emitAttr attr);
4545
void emitDispExtendReg(regNumber reg, insOpts opt, ssize_t imm);
4646
void emitDispAddrRI(regNumber reg, insOpts opt, ssize_t imm);
4747
void emitDispAddrRRExt(regNumber reg1, regNumber reg2, insOpts opt, bool isScaled, emitAttr size);
48-
49-
void emitDispIns(instrDesc* id,
50-
bool isNew,
51-
bool doffs,
52-
bool asmfm,
53-
unsigned offs = 0,
54-
BYTE* pCode = 0,
55-
size_t sz = 0,
56-
insGroup* ig = NULL);
5748
#endif // DEBUG
5849

5950
/************************************************************************/

src/coreclr/jit/emitxarch.cpp

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8722,11 +8722,22 @@ void emitter::emitDispInsHex(instrDesc* id, BYTE* code, size_t sz)
87228722
}
87238723
}
87248724

8725-
/*****************************************************************************
8726-
*
8727-
* Display the given instruction.
8728-
*/
8729-
8725+
//--------------------------------------------------------------------
8726+
// emitDispIns: Dump the given instruction to jitstdout.
8727+
//
8728+
// Arguments:
8729+
// id - The instruction
8730+
// isNew - Whether the instruction is newly generated (before encoding).
8731+
// doffs - If true, always display the passed-in offset.
8732+
// asmfm - Whether the instruction should be displayed in assembly format.
8733+
// If false some additional information may be printed for the instruction.
8734+
// offset - The offset of the instruction. Only displayed if doffs is true or if
8735+
// !isNew && !asmfm.
8736+
// code - Pointer to the actual code, used for displaying the address and encoded bytes
8737+
// if turned on.
8738+
// sz - The size of the instruction, used to display the encoded bytes.
8739+
// ig - The instruction group containing the instruction. Not used on xarch.
8740+
//
87308741
void emitter::emitDispIns(
87318742
instrDesc* id, bool isNew, bool doffs, bool asmfm, unsigned offset, BYTE* code, size_t sz, insGroup* ig)
87328743
{

src/coreclr/jit/emitxarch.h

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -222,15 +222,6 @@ void emitDispReloc(ssize_t value);
222222
void emitDispAddrMode(instrDesc* id, bool noDetail = false);
223223
void emitDispShift(instruction ins, int cnt = 0);
224224

225-
void emitDispIns(instrDesc* id,
226-
bool isNew,
227-
bool doffs,
228-
bool asmfm,
229-
unsigned offs = 0,
230-
BYTE* code = nullptr,
231-
size_t sz = 0,
232-
insGroup* ig = nullptr);
233-
234225
const char* emitXMMregName(unsigned reg);
235226
const char* emitYMMregName(unsigned reg);
236227

src/coreclr/jit/jitconfigvalues.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,7 @@ CONFIG_INTEGER(JitDumpFgBlockID, W("JitDumpFgBlockID"), 0) // 0 == display block
233233
// bbNum and bbID
234234

235235
CONFIG_STRING(JitDumpPreciseDebugInfoFile, W("JitDumpPreciseDebugInfoFile"))
236+
CONFIG_INTEGER(JitDisasmWithDebugInfo, W("JitDisasmWithDebugInfo"), 0)
236237

237238
CONFIG_STRING(JitLateDisasmTo, W("JITLateDisasmTo"))
238239
CONFIG_STRING(JitRange, W("JitRange"))

0 commit comments

Comments
 (0)