This is an archive of the discontinued LLVM Phabricator instance.

[DebugInfo] Do not emit entry values for composite locations
ClosedPublic

Authored by dstenb on Feb 27 2020, 9:06 AM.

Details

Summary

This is a fix for PR45009.

When working on D67492 I made DwarfExpression emit a single
DW_OP_entry_value operation covering the whole composite location
description that is produced if a register does not have a valid DWARF
number, and is instead composed of multiple register pieces. Looking
closer at the standard, I realized that that is not valid DWARF. A
DW_OP_entry_value operation's block can only be a DWARF expression or a
register location description, so it is not valid for it to hold a
composite location description like that.

See DWARFv5 sec. 2.5.1.7:

"The DW_OP_entry_value operation pushes the value that the described
location held upon entering the current subprogram. It has two
operands: an unsigned LEB128 length, followed by a block containing a
DWARF expression or a register location description (see Section
2.6.1.1.3 on page 39)."

Perhaps we instead want to emit a entry value operation per each
DW_OP_reg* operation, e.g.:

  • DW_OP_entry_value(DW_OP_regx sub_reg0), DW_OP_stack_value, DW_OP_piece 8,
  • DW_OP_entry_value(DW_OP_regx sub_reg1), DW_OP_stack_value, DW_OP_piece 8, [...]

The question then becomes how the call site should look; should a
composite location description be emitted there, and we then leave it up
to the debugger to match those two composite location descriptions?
Another alternative could be to emit a call site parameter entry for
each sub-register, but firstly I'm unsure if that is even valid DWARF,
and secondly it seems like that would complicate the collection of call
site values quite a bit. As far as I can tell GCC does not emit any
entry values / call sites in these cases, so we do not have something to
compare with, but the former seems like the more reasonable approach.

Currently when trying to emit a call site entry for a parameter composed
of multiple DWARF registers a (DwarfRegs.size() == 1) assert is
triggered in addMachineRegExpression(). Until the call site
representation is figured out, and until there is use for these entry
values in practice, this commit simply stops the invalid DWARF from
being emitted.

Diff Detail

Event Timeline

dstenb created this revision.Feb 27 2020, 9:06 AM
vsk accepted this revision.EditedFeb 27 2020, 5:15 PM

Fixing the assertion failure in this way sgtm. Re:

DW_OP_entry_value(DW_OP_regx sub_reg0), DW_OP_stack_value, DW_OP_piece 8, DW_OP_entry_value(DW_OP_regx sub_reg1), DW_OP_stack_value, DW_OP_piece 8, ...

It sounds like you expect debuggers to have some difficulty handling this expression. How come? I didn't understand this part.

My lack of familiarity with DWARF is showing now, but would DW_OP_entry_value(DW_OP_regx sub_reg0, DW_OP_piece 8, DW_OP_regx sub_reg1, DW_OP_piece 8) be valid (sorry if I've left out any necessary OP_stack_values)?

The question then becomes how the call site should look; should a
composite location description be emitted there, and we then leave it up
to the debugger to match those two composite location descriptions?

This seems reasonable to me, but I feel like I'm missing something here..

Another alternative could be to emit a call site parameter entry for
each sub-register,

I believe this would complicate the debugger support significantly, hopefully there's a simpler way to do this. Right now lldb just does a 'memcmp' to figure out whether to use an entry value. If there were a separate call site parameter entry for each subregister in the caller that forms a register used in the callee, that would have to change into a more complicated merging operation.

This revision is now accepted and ready to land.Feb 27 2020, 5:15 PM
djtodoro accepted this revision.Feb 28 2020, 12:45 AM
In D75270#1897102, @vsk wrote:

Another alternative could be to emit a call site parameter entry for
each sub-register,

I believe this would complicate the debugger support significantly, hopefully there's a simpler way to do this.

+1

In D75270, @dstenb wrote:

As far as I can tell GCC does not emit any
entry values / call sites in these cases, so we do not have something to
compare with, but the former seems like the more reasonable approach.

I think as well. What about GDB side? Did GDB expect something like this? I though just running GDB over such case could be interesting to see if it accepts such scenario or not (I should find some time to play with that for sure).

As far as I can tell GCC does not emit any
entry values / call sites in these cases, so we do not have something to
compare with, but the former seems like the more reasonable approach.

I think as well. What about GDB side? Did GDB expect something like this? I though just running GDB over such case could be interesting to see if it accepts such scenario or not (I should find some time to play with that for sure).

GDB currently imposes the following restrictions for call site locations:

Only single DW_OP_reg or DW_OP_fbreg is supported for DW_FORM_block* DW_AT_location is supported for DW_TAG_call_site child DIE

and the following for entry value operations:

DWARF-2 expression error: DW_OP_entry_value is supported only for single DW_OP_reg* or for DW_OP_breg*(0)+DW_OP_deref*

As far as I can tell GCC does not emit any
entry values / call sites in these cases, so we do not have something to
compare with, but the former seems like the more reasonable approach.

I think as well. What about GDB side? Did GDB expect something like this? I though just running GDB over such case could be interesting to see if it accepts such scenario or not (I should find some time to play with that for sure).

GDB currently imposes the following restrictions for call site locations:

Only single DW_OP_reg or DW_OP_fbreg is supported for DW_FORM_block* DW_AT_location is supported for DW_TAG_call_site child DIE

and the following for entry value operations:

DWARF-2 expression error: DW_OP_entry_value is supported only for single DW_OP_reg* or for DW_OP_breg*(0)+DW_OP_deref*

Thanks for this! I've expected that... I've confirmed this output with an older version of GDB 7.1* as well. We will need to discuss about adding such support to debuggers.

dstenb added a comment.Mar 4 2020, 4:47 AM
In D75270#1897102, @vsk wrote:

Fixing the assertion failure in this way sgtm. Re:

Sorry, coming back to this now after the similar discussion in D75326.

I just want to clarify that this patch does not fix any assertion failures. The entry value operation is emitted without crashing; it's just that I think that it's invalid DWARF. The assertion I mentioned in the description was for the DW_AT_location at the call site parameter entry (but see my correction about that at the end of this comment).

DW_OP_entry_value(DW_OP_regx sub_reg0), DW_OP_stack_value, DW_OP_piece 8, DW_OP_entry_value(DW_OP_regx sub_reg1), DW_OP_stack_value, DW_OP_piece 8, ...

It sounds like you expect debuggers to have some difficulty handling this expression. How come? I didn't understand this part.

I don't know how much about how the call site and entry value matching works and is implemented in the debuggers, but I thought there could be some difficulties to understand that the each sub-register's entry value at the callee's location:

DW_OP_entry_value(DW_OP_regx sub_reg0), DW_OP_stack_value, DW_OP_piece 8, DW_OP_entry_value(DW_OP_regx sub_reg1), DW_OP_stack_value, DW_OP_piece 8, ...

should be matched to the corresponding piece of the DW_AT_location for the call site's single parameter entry:

DW_OP_regx sub_reg0, DW_OP_piece 8, DW_OP_regx sub_reg1, DW_OP_stack_value, DW_OP_piece 8, ...

Then, if we e.g. have a DW_OP_constu as the DW_AT_call_value for that call site parameter entry, I assume that the debugger has to split up that value into different parts according to the DW_AT_location composition, and push those to the DWARF stacks for the entry values in the different pieces?

Again, as I don't know much about the debuggers' implementations, maybe nothing of that is an issue really?

My lack of familiarity with DWARF is showing now, but would DW_OP_entry_value(DW_OP_regx sub_reg0, DW_OP_piece 8, DW_OP_regx sub_reg1, DW_OP_piece 8) be valid (sorry if I've left out any necessary OP_stack_values)?

That is what we currently emit (with a stack value after the DW_OP_entry_value). I think that's invalid DWARF since the standard specifies that the DW_OP_entry_value operation's block is "containing a DWARF expression or a register location description", so I don't think it's valid to emit a composite location description like that one.

And sorry, I noticed something incorrect in my patch description:

In D75270, @dstenb wrote:

Currently when trying to emit a call site entry for a parameter composed
of multiple DWARF registers a (DwarfRegs.size() == 1) assert is
triggered in addMachineRegExpression(). Until the call site
representation is figured out, and until there is use for these entry
values in practice, this commit simply stops the invalid DWARF from
being emitted.

The call site entry's DW_AT_location is emitted fine for composite locations, so what I'm describing there does not happen for those cases. However, if you were to describe the call site value using a preserved register, which is composed of multiple DWARF register pieces, you'll currently hit that assertion (code here: [0]) since isParameterValue() is true.

[0] https://github.com/llvm/llvm-project/blob/master/llvm/lib/CodeGen/AsmPrinter/DwarfExpression.cpp#L279

Hi @dstenb,

What is the status with this?

Hi @dstenb,

What is the status with this?

Sorry for leaving this!

This related a bit to D75326, and there I sent a mail to the Dwarf-Discuss mailing thread (http://lists.dwarfstd.org/pipermail/dwarf-discuss-dwarfstd.org/2020-March/004610.html) about whether or not composite locations are allowed in DWARF Expressions.

@vsk, do you think it would be okay for you if we land this patch based on the similar reasoning as in you wrote in D75326? I mean this:

Reading through the discussion, I do see some amount of consensus about the first sentence of section 2.5 being misleading (or at least confusing) -- this is the bit I cited in argument for allowing composite locations wherever a value is expected. I think we'd need a strong reason to disregard that consensus.

vsk added a comment.Jun 30 2020, 12:02 PM

@dstenb thanks for kicking off the thread on dwarf-discuss, and sorry for the delay here. Please go ahead, it looks like there's strong consensus that a composite location description can't be emitted where a DWARF expression or simple register location is expected.

Thanks, and sorry for letting this patch lay dormant. I'll land this tomorrow when I have time for the build bots.

This revision was automatically updated to reflect the committed changes.