This is an archive of the discontinued LLVM Phabricator instance.

[LiveDebugValues] Allow EntryValue with OP_deref expressions
ClosedPublic

Authored by fdeazeve on Jan 26 2023, 10:55 AM.

Details

Summary

With D68945, more DBG_VALUEs were created without the indirect operand,
instead relying on OP_deref to accomplish the same effect.

At the time, however, we were not able to handle arbitrary expressions
in combination with OP_LLVM_entry_value, so D71416 prevented the use of
such operation in the presence of expressions.

As per the comment in DIExpression::isValid, "we support only entry
values of a simple register location." As such, a simple deref operation
should be supported. In fact, D80345 added support for indirect
DBG_VALUEs.

Taken the patches above into consideration, this commit relaxes the
restrictions on which expressions are allowed for entry value
candidates: the expression must be either empty or a single dereference
operator.

This patch is useful for D141381, which adds support for storing the
address of ABI-indirect parameters on the stack.

Depends on D142160

Diff Detail

Event Timeline

fdeazeve created this revision.Jan 26 2023, 10:55 AM
Herald added a project: Restricted Project. · View Herald TranscriptJan 26 2023, 10:55 AM
Herald added a subscriber: hiraditya. · View Herald Transcript
fdeazeve requested review of this revision.Jan 26 2023, 10:55 AM
Herald added a project: Restricted Project. · View Herald TranscriptJan 26 2023, 10:55 AM

I've tagged everyone who was involved one way or another in the previous patches related to this, hopefully I haven't missed anyone

Hello. I am wondering, have you checked how both `GDB`` and `LLDB`` act with this example?

Hello. I am wondering, have you checked how both `GDB`` and `LLDB`` act with this example?

I believe we don't have much to check in this example, as there are no callers for the function here.
However, the test lldb/test/API/functionalities/param_entry_vals/basic_entry_values/ has a function with this exact behaviour (see func15).
It produces this dwarf for the callee:

0x0000065f:   DW_TAG_subprogram
                DW_AT_low_pc	(0x00000000000001f8)
                DW_AT_high_pc	(0x0000000000000228)
                DW_AT_frame_base	(DW_OP_reg29 W29)
                DW_AT_call_all_calls	(true)
                DW_AT_linkage_name	("_Z6func1537StructPassedViaPointerToTemporaryCopy")
                DW_AT_name	("func15")
                DW_AT_decl_file	("lldb/test/API/functionalities/param_entry_vals/basic_entry_values/main.cpp")
                DW_AT_decl_line	(157)
                DW_AT_external	(true)

0x00000678:     DW_TAG_formal_parameter
                  DW_AT_location	(0x000003ef: 
                     [0x00000000000001f8, 0x0000000000000204): DW_OP_breg0 W0+0
                     [0x0000000000000204, 0x0000000000000228): DW_OP_entry_value(DW_OP_reg0 W0))
                  DW_AT_name	("S")
                  DW_AT_decl_file	("lldb/test/API/functionalities/param_entry_vals/basic_entry_values/main.cpp")
                  DW_AT_decl_line	(157)
                  DW_AT_type	(0x00000749 "StructPassedViaPointerToTemporaryCopy")

And then, on the caller's side (main):

0x0000093d:     DW_TAG_call_site
                  DW_AT_call_origin	(0x0000065f)
                  DW_AT_call_return_pc	(0x00000000000002dc)

0x0000094a:       DW_TAG_call_site_parameter
                    DW_AT_location	(DW_OP_reg0 W0)
                    DW_AT_call_value	(DW_OP_breg31 WSP+8)

LLDB is able -- in fact this is what the test is testing -- to recover the parameter with those two pieces of information.

I have not checked whether GDB has support for this dwarf OP.

Yeah, GDB had implemented it as GNU extension even before LLDB.
All in all, I don't see any obstacle to use the entry_value for this case. GCC also produces the same location entry for the variable b.

Have you checked the InstrRefBased implementation of the LiveDebugValues Pass?

LGTM, but I'll leave to @djtodoro to approve. Support in the other flavour of LiveDebugValues would indeed be appreciated.

fdeazeve added a comment.EditedJan 27 2023, 9:03 AM

Have you checked the InstrRefBased implementation of the LiveDebugValues Pass?

Oops, I wrote that down as something I had to do prior to posting this but forgot to :(
Will update the patch shortly!

fdeazeve updated this revision to Diff 492849.Jan 27 2023, 11:05 AM

Added support in InstrRefBased. Updated the existing test to test both
implementations.

LGTM, but I agree with Djordje that we should also check that at least LLDB can support this. Maybe someone with access to GDB can comment with another data point.
It will be a fun project to mock up an unwinder in lldb/unittests/Expression/DWARFExpression test for this ;-)

llvm/test/DebugInfo/MIR/X86/dbgcall-site-reference.mir
20

This DWARF expression looked suspicious to me, but I think it's actually correct. IIUC, this will unwind the call stack push the value of reg4 onto the DWARF stack. Because the DWARF expression isn't a DW_OP_reg and also doesn't end with DW_OP_stack_value this is still a memory location.

fdeazeve added a comment.EditedJan 27 2023, 1:49 PM

LGTM, but I agree with Djordje that we should also check that at least LLDB can support this. Maybe someone with access to GDB can comment with another data point.
It will be a fun project to mock up an unwinder in lldb/unittests/Expression/DWARFExpression test for this ;-)

Just to make sure we're on the same page, this test is producing virtually the same dwarf as the one I posted previously, which I confirmed to work with LLDB, or is there something fundamentally different that I'm missing here?

aprantl accepted this revision.Jan 27 2023, 3:52 PM

LGTM, but I agree with Djordje that we should also check that at least LLDB can support this. Maybe someone with access to GDB can comment with another data point.
It will be a fun project to mock up an unwinder in lldb/unittests/Expression/DWARFExpression test for this ;-)

Just to make sure we're on the same page, this test is producing virtually the same dwarf as the one I posted previously, which I confirmed to work with LLDB, or is there something fundamentally different that I'm missing here?

If you already confirmed that LLDB can deal with this correctly, that's great!

This revision is now accepted and ready to land.Jan 27 2023, 3:52 PM
djtodoro accepted this revision.Jan 29 2023, 2:48 AM

LGTM.

jmorse accepted this revision.Jan 30 2023, 1:16 AM

LGTM3

This revision was landed with ongoing or failed builds.Jan 31 2023, 6:43 AM
This revision was automatically updated to reflect the committed changes.