Skip to content

Commit

Permalink
JIT: Fix rich debug info reporting with failed inline contexts (#98755)
Browse files Browse the repository at this point in the history
The child/sibling link ordinals would be reported as 0 in cases where
the immediate child/sibling was a failed one. This would break the
reported tree structure.

Also add some JITDUMP logging of the reported info.
  • Loading branch information
jakobbotsch authored Feb 21, 2024
1 parent 96bee8d commit 703f6e8
Showing 1 changed file with 58 additions and 14 deletions.
72 changes: 58 additions & 14 deletions src/coreclr/jit/codegencommon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7363,6 +7363,26 @@ void CodeGen::genReportRichDebugInfoToFile()

#endif

//------------------------------------------------------------------------
// SuccessfulSibling:
// Find the next sibling inline context that was successfully inlined.
//
// Parameters:
// context - the inline context. Can be nullptr in which case nullptr is returned.
//
// Returns:
// The sibling, or nullptr if there is no succesful sibling.
//
static InlineContext* SuccessfulSibling(InlineContext* context)
{
while ((context != nullptr) && !context->IsSuccess())
{
context = context->GetSibling();
}

return context;
}

//------------------------------------------------------------------------
// genRecordRichDebugInfoInlineTree:
// Recursively process a context in the inline tree and record information
Expand All @@ -7374,26 +7394,28 @@ void CodeGen::genReportRichDebugInfoToFile()
//
void CodeGen::genRecordRichDebugInfoInlineTree(InlineContext* context, ICorDebugInfo::InlineTreeNode* nodes)
{
if (context->IsSuccess())
{
// We expect 1 + NumInlines unique ordinals
assert(context->GetOrdinal() <= compiler->m_inlineStrategy->GetInlineCount());
assert(context->IsSuccess());

ICorDebugInfo::InlineTreeNode* node = &nodes[context->GetOrdinal()];
node->Method = context->GetCallee();
node->ILOffset = context->GetActualCallOffset();
node->Child = context->GetChild() == nullptr ? 0 : context->GetChild()->GetOrdinal();
node->Sibling = context->GetSibling() == nullptr ? 0 : context->GetSibling()->GetOrdinal();
}
// We expect 1 + NumInlines unique ordinals
assert(context->GetOrdinal() <= compiler->m_inlineStrategy->GetInlineCount());

if (context->GetSibling() != nullptr)
InlineContext* successfulChild = SuccessfulSibling(context->GetChild());
InlineContext* successfulSibling = SuccessfulSibling(context->GetSibling());

ICorDebugInfo::InlineTreeNode* node = &nodes[context->GetOrdinal()];
node->Method = context->GetCallee();
node->ILOffset = context->GetActualCallOffset();
node->Child = successfulChild == nullptr ? 0 : successfulChild->GetOrdinal();
node->Sibling = successfulSibling == nullptr ? 0 : successfulSibling->GetOrdinal();

if (successfulSibling != nullptr)
{
genRecordRichDebugInfoInlineTree(context->GetSibling(), nodes);
genRecordRichDebugInfoInlineTree(successfulSibling, nodes);
}

if (context->GetChild() != nullptr)
if (successfulChild != nullptr)
{
genRecordRichDebugInfoInlineTree(context->GetChild(), nodes);
genRecordRichDebugInfoInlineTree(successfulChild, nodes);
}
}

Expand Down Expand Up @@ -7443,6 +7465,28 @@ void CodeGen::genReportRichDebugInfo()
mappingIndex++;
}

#ifdef DEBUG
if (verbose)
{
printf("Reported inline tree:\n");
for (unsigned i = 0; i < numContexts; i++)
{
printf(" [#%d] %s @ %d, child = %d, sibling = %d\n", i,
compiler->eeGetMethodFullName(inlineTree[i].Method), inlineTree[i].ILOffset, inlineTree[i].Child,
inlineTree[i].Sibling);
}

printf("\nReported rich mappings:\n");
for (size_t i = 0; i < mappingIndex; i++)
{
printf(" [%zu] 0x%x <-> IL %d in #%d\n", i, mappings[i].NativeOffset, mappings[i].ILOffset,
mappings[i].Inlinee);
}

printf("\n");
}
#endif

compiler->info.compCompHnd->reportRichMappings(inlineTree, numContexts, mappings, numRichMappings);
}

Expand Down

0 comments on commit 703f6e8

Please sign in to comment.