Skip to content

Commit 731364d

Browse files
authored
Start tracking debug info for inlined statements (#61220)
* Refactor IL_OFFSETX into DebugInfo Remove IL_OFFSETX in favor of a DebugInfo structure. Previously we were packing extra information into the upper bits of IL_OFFSETX, which are now separate bit fields on a new ILLocation structure. DebugInfo contains an ILLocation and also an inline context, which will be used in the future when tracking debug info inside of inlinees. Another problem with IL_OFFSETX was that there were several sentinel values used to describe prologs, epilogs and no mappings. However these were only used in code-gen, so refactor codegen to track this separately instead of having to muddle it into IL_OFFSETX. This makes it clearer what we can expect from IL offsets during JIT. This change is no-diff and PIN also shows that TP is not negatively affected; in fact, there seems to be a small TP gain, maybe because we don't have to handle sentinel values anymore. * Track debug information in statements from inlinees Add support for tracking debug information in statements coming from inlinees. Changes: * Turn on compDbgInfo in inlinees. We use the implicit boundaries from the inline root, but we do not use any explicit boundaries. That is, we do not query the EE for explicit boundaries for the inlinee. * Create InlineContexts eagerly and use them during import. All DebugInfo created in the JIT is in a "consistent" state, meaning that we never see an IL location set without a corresponding inline context. This was difficult before as InlineContexts would be created quite late, after the importer for the inlinee had run. We now create it eagerly and attach it to debug info during importation. Later, when we figure out whether an inline succeeded or not, we mark it as succeeded or failed. * Stop carrying InlineContext around unconditionally in Statement. The inline context is now only part of the debug info, which may not be set. Inlining needs the inline context to create new inline contexts and to check for recursive inlines. Previously it retrieved it from the inline statement, but due to the above change we now have to get it from somewhere else. To do this we now keep it unconditionally together with InlineCandidateInfo so that we can retrieve it later. * Validate all created debug information when associated with a statement. This is done by creating a bitvector containing IL locations that mark the beginning of IL instructions, and validating that all IL offsets point to these when Statement::SetDebugInfo is called. * While we track debug info in statements from inlinees, the runtime side is still not hooked up. Currently we track the information until we get to rationalize, where we normalize all debug info back to the root inserted as GT_IL_OFFSET nodes. The change is free of any diffs due to this normalization. We also track IL offsets as part of basic blocks: these are also normalized to be in the root.
1 parent 8d93078 commit 731364d

40 files changed

+1098
-1007
lines changed

src/coreclr/inc/cordebuginfo.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ class ICorDebugInfo
5252
struct OffsetMapping
5353
{
5454
uint32_t nativeOffset;
55-
uint32_t ilOffset;
55+
uint32_t ilOffset; // IL offset or one of the special values in MappingTypes
5656
SourceTypes source; // The debugger needs this so that
5757
// we don't put Edit and Continue breakpoints where
5858
// the stack isn't empty. We can put regular breakpoints

src/coreclr/jit/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ set( JIT_SOURCES
8080
codegenlinear.cpp
8181
compiler.cpp
8282
copyprop.cpp
83+
debuginfo.cpp
8384
disasm.cpp
8485
earlyprop.cpp
8586
ee_il_dll.cpp
@@ -178,6 +179,7 @@ if (CLR_CMAKE_TARGET_WIN32)
178179
compmemkind.h
179180
compphases.h
180181
dataflow.h
182+
debuginfo.h
181183
decomposelongs.h
182184
disasm.h
183185
emit.h

src/coreclr/jit/codegen.h

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -434,10 +434,10 @@ class CodeGen final : public CodeGenInterface
434434
CORINFO_METHOD_HANDLE methHnd,
435435
INDEBUG_LDISASM_COMMA(CORINFO_SIG_INFO* sigInfo)
436436
void* addr
437-
X86_ARG(int argSize),
437+
X86_ARG(int argSize),
438438
emitAttr retSize
439439
MULTIREG_HAS_SECOND_GC_RET_ONLY_ARG(emitAttr secondRetSize),
440-
IL_OFFSETX ilOffset,
440+
const DebugInfo& di,
441441
regNumber base,
442442
bool isJump);
443443
// clang-format on
@@ -447,10 +447,10 @@ class CodeGen final : public CodeGenInterface
447447
CORINFO_METHOD_HANDLE methHnd,
448448
INDEBUG_LDISASM_COMMA(CORINFO_SIG_INFO* sigInfo)
449449
GenTreeIndir* indir
450-
X86_ARG(int argSize),
450+
X86_ARG(int argSize),
451451
emitAttr retSize
452452
MULTIREG_HAS_SECOND_GC_RET_ONLY_ARG(emitAttr secondRetSize),
453-
IL_OFFSETX ilOffset,
453+
const DebugInfo& di,
454454
bool isJump);
455455
// clang-format on
456456

@@ -552,15 +552,16 @@ XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
552552
*/
553553

554554
#ifdef DEBUG
555-
void genIPmappingDisp(unsigned mappingNum, Compiler::IPmappingDsc* ipMapping);
555+
void genIPmappingDisp(unsigned mappingNum, IPmappingDsc* ipMapping);
556556
void genIPmappingListDisp();
557557
#endif // DEBUG
558558

559-
void genIPmappingAdd(IL_OFFSETX offset, bool isLabel);
560-
void genIPmappingAddToFront(IL_OFFSETX offset);
559+
IPmappingDsc* genCreateIPMapping(IPmappingDscKind kind, const DebugInfo& di, bool isLabel);
560+
void genIPmappingAdd(IPmappingDscKind kind, const DebugInfo& di, bool isLabel);
561+
void genIPmappingAddToFront(IPmappingDscKind kind, const DebugInfo& di, bool isLabel);
561562
void genIPmappingGen();
562563

563-
void genEnsureCodeEmitted(IL_OFFSETX offsx);
564+
void genEnsureCodeEmitted(const DebugInfo& di);
564565

565566
//-------------------------------------------------------------------------
566567
// scope info for the variables

src/coreclr/jit/codegenarm.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1632,8 +1632,7 @@ void CodeGen::genEmitHelperCall(unsigned helper, int argSize, emitAttr retSize,
16321632
GetEmitter()->emitIns_Call(emitter::EC_INDIR_R, compiler->eeFindHelper(helper),
16331633
INDEBUG_LDISASM_COMMA(nullptr) NULL, // addr
16341634
argSize, retSize, gcInfo.gcVarPtrSetCur, gcInfo.gcRegGCrefSetCur,
1635-
gcInfo.gcRegByrefSetCur,
1636-
BAD_IL_OFFSET, // ilOffset
1635+
gcInfo.gcRegByrefSetCur, DebugInfo(),
16371636
callTargetReg, // ireg
16381637
REG_NA, 0, 0, // xreg, xmul, disp
16391638
false // isJump
@@ -1643,7 +1642,7 @@ void CodeGen::genEmitHelperCall(unsigned helper, int argSize, emitAttr retSize,
16431642
{
16441643
GetEmitter()->emitIns_Call(emitter::EC_FUNC_TOKEN, compiler->eeFindHelper(helper),
16451644
INDEBUG_LDISASM_COMMA(nullptr) addr, argSize, retSize, gcInfo.gcVarPtrSetCur,
1646-
gcInfo.gcRegGCrefSetCur, gcInfo.gcRegByrefSetCur, BAD_IL_OFFSET, REG_NA, REG_NA, 0,
1645+
gcInfo.gcRegGCrefSetCur, gcInfo.gcRegByrefSetCur, DebugInfo(), REG_NA, REG_NA, 0,
16471646
0, /* ilOffset, ireg, xreg, xmul, disp */
16481647
false /* isJump */
16491648
);

src/coreclr/jit/codegenarm64.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3846,10 +3846,9 @@ void CodeGen::genEmitHelperCall(unsigned helper, int argSize, emitAttr retSize,
38463846

38473847
GetEmitter()->emitIns_Call(callType, compiler->eeFindHelper(helper), INDEBUG_LDISASM_COMMA(nullptr) addr, argSize,
38483848
retSize, EA_UNKNOWN, gcInfo.gcVarPtrSetCur, gcInfo.gcRegGCrefSetCur,
3849-
gcInfo.gcRegByrefSetCur, BAD_IL_OFFSET, /* IL offset */
3850-
callTarget, /* ireg */
3851-
REG_NA, 0, 0, /* xreg, xmul, disp */
3852-
false /* isJump */
3849+
gcInfo.gcRegByrefSetCur, DebugInfo(), callTarget, /* ireg */
3850+
REG_NA, 0, 0, /* xreg, xmul, disp */
3851+
false /* isJump */
38533852
);
38543853

38553854
regMaskTP killMask = compiler->compHelperCallKillSet((CorInfoHelpFunc)helper);

src/coreclr/jit/codegenarmarch.cpp

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2463,16 +2463,14 @@ void CodeGen::genCallInstruction(GenTreeCall* call)
24632463
}
24642464
}
24652465

2466-
// We need to propagate the IL offset information to the call instruction, so we can emit
2466+
DebugInfo di;
2467+
// We need to propagate the debug information to the call instruction, so we can emit
24672468
// an IL to native mapping record for the call, to support managed return value debugging.
24682469
// We don't want tail call helper calls that were converted from normal calls to get a record,
24692470
// so we skip this hash table lookup logic in that case.
2470-
2471-
IL_OFFSETX ilOffset = BAD_IL_OFFSET;
2472-
2473-
if (compiler->opts.compDbgInfo && compiler->genCallSite2ILOffsetMap != nullptr && !call->IsTailCall())
2471+
if (compiler->opts.compDbgInfo && compiler->genCallSite2DebugInfoMap != nullptr && !call->IsTailCall())
24742472
{
2475-
(void)compiler->genCallSite2ILOffsetMap->Lookup(call, &ilOffset);
2473+
(void)compiler->genCallSite2DebugInfoMap->Lookup(call, &di);
24762474
}
24772475

24782476
CORINFO_SIG_INFO* sigInfo = nullptr;
@@ -2512,7 +2510,7 @@ void CodeGen::genCallInstruction(GenTreeCall* call)
25122510
nullptr, // addr
25132511
retSize
25142512
MULTIREG_HAS_SECOND_GC_RET_ONLY_ARG(secondRetSize),
2515-
ilOffset,
2513+
di,
25162514
target->GetRegNum(),
25172515
call->IsFastTailCall());
25182516
// clang-format on
@@ -2552,7 +2550,7 @@ void CodeGen::genCallInstruction(GenTreeCall* call)
25522550
nullptr, // addr
25532551
retSize
25542552
MULTIREG_HAS_SECOND_GC_RET_ONLY_ARG(secondRetSize),
2555-
ilOffset,
2553+
di,
25562554
targetAddrReg,
25572555
call->IsFastTailCall());
25582556
// clang-format on
@@ -2600,7 +2598,7 @@ void CodeGen::genCallInstruction(GenTreeCall* call)
26002598
INDEBUG_LDISASM_COMMA(sigInfo)
26012599
NULL,
26022600
retSize,
2603-
ilOffset,
2601+
di,
26042602
tmpReg,
26052603
call->IsFastTailCall());
26062604
// clang-format on
@@ -2615,7 +2613,7 @@ void CodeGen::genCallInstruction(GenTreeCall* call)
26152613
addr,
26162614
retSize
26172615
MULTIREG_HAS_SECOND_GC_RET_ONLY_ARG(secondRetSize),
2618-
ilOffset,
2616+
di,
26192617
REG_NA,
26202618
call->IsFastTailCall());
26212619
// clang-format on

0 commit comments

Comments
 (0)