This is an archive of the discontinued LLVM Phabricator instance.

[lldb] Consider OP_addrx in DWARFExpression::Update_DW_OP_addr
ClosedPublic

Authored by fdeazeve on Jul 13 2023, 6:37 AM.

Details

Summary

This rewrites DW_OP_addrx inside DWARFExpression as an DW_OP_addr so that we can
update addresses that are originally located in the debug_addr section.

The full discussion behind this can be found in
https://discourse.llvm.org/t/dwarfexpression-and-dw-op-addrx/71627/12, but a
summary follows.

When SymbolFileDWARF::ParseVariableDIE creates DWARFExpressions for variables
whose location is an OP_addr, it knows how to remap addresses appropriately in
the DebugMap case. It then calls DWARFExpression::Update_DW_OP_addr, which
updates the value associated with OP_addr.

However, when we have an OP_addrx, the update function does nothing. This makes
sense, as the DWARFExpression does not have a mutable view of the debug_addr
section. In non-DebugMap flows this is not an issue, as the debug_addr contains
the correct addresses of variables. In DebugMap flows, this is problematic
because the work done by RelinkOSOAddress is lost. By updating the OP to
OP_addr, we can also update the address as required,

We also explored the alternative of relinking the debug_addr section when we are
initializing OSOs (InitOSO). However, this creates an inconsistent story for
users of DWARFExpression::GetLocation_DW_OP_addr. This function returns an
address without telling callers whether that address came from an OP_addr or an
OP_addrx. If we preemptively relink OP_addrx results without doing the same for
OP_addr results, then callers can’t know whether the address they got was an
executable address or an object file address. In other words, they can’t know
whether they need to call LinkOSOFileAddress on those results or not.

This patch addresses the majority of test failures when enabling DWARF 5 for
MachO (over 200 test failures).

Diff Detail

Event Timeline

fdeazeve created this revision.Jul 13 2023, 6:37 AM
Herald added a project: Restricted Project. · View Herald TranscriptJul 13 2023, 6:37 AM
fdeazeve requested review of this revision.Jul 13 2023, 6:37 AM
Herald added a project: Restricted Project. · View Herald TranscriptJul 13 2023, 6:37 AM
fdeazeve updated this revision to Diff 540001.Jul 13 2023, 6:40 AM

Minor comment improvements

fdeazeve added reviewers: Restricted Project, clayborg.Jul 13 2023, 6:41 AM
aprantl accepted this revision.Jul 18 2023, 1:17 PM
This revision is now accepted and ready to land.Jul 18 2023, 1:17 PM

Hi @clayborg, just wanted to make sure this doesn't fall off your radar :)
This fixes all outstanding DWARF 5 issues with Debug Maps, so it would be cool if we could get this in.

As far as I'm concerned, this doesn't look too controversial to me and it is unblocking one of the bots. I think it would be okay to tentatively land this, but be on the lookout and promptly react to any post-commit feedback from @clayborg.

LGTM. I agree with Adrian: we can go ahead and land this to unblock the bots.

This revision was automatically updated to reflect the committed changes.

Sorry for the late response, but I had verbally agreed to this approach when Felipe and I spoke about how to fix this. LGTM!