Issue 230808.1: DW_OP_entry_value description and examples

Author: Paul Robinson
Champion: Paul Robinson
Date submitted: 2023-08-08
Date revised: 2023-11-10
Date closed: 2023-11-13
Type: Error
Status: Accepted
DWARF Version: 6

Overview

DW_OP_entry_value provides a way to compute a value as if the value had been computed on entry to the current subprogram. Its operand is either a DWARF expression, which assumes nothing is already on the DWARF stack and leaves one value on the DWARF stack; or, it is a register location description, and the content of the register (as it was on entry to the subprogram) is implicitly read and pushed on the DWARF stack. The register location description is simply a more compact representation of the common case of reading a register; for example, the producer can emit DW_OP_reg1 instead of DW_OP_breg1 0 with the same result.

However, the description and examples aren't completely consistent, and in some cases are very confusing. This proposal corrects the language and examples.

Proposed Changes

Section 2.5.1.7 Special Operations, p.37

The first sentence of the description of DW_OP_entry_value reads:

The DW_OP_entry_value operation pushes the value that the described location held upon entering the current subprogram.

A DWARF expression does not describe a location, so this should read:

The DW_OP_entry_value operation pushes the value that a DWARF expression would have computed, or that a register location held upon entering the current subprogram.

Appendix D.1.3, pp.291-292

This section contains examples of DWARF location descriptions. In a committee meeting discussing this issue, we recognized that in the DW_OP_entry_value examples, part of the expression is the operand to DW_OP_entry_value and part of it is not. This made it a bit hard to follow the examples, and previous iterations of this issue misunderstood the intent entirely. This issue now proposes to put the "operand part" in parentheses for clarity. I've also updated some of the textual descriptions for additional clarity, and consistency with other examples in this section.

There are six examples using DW_OP_entry_value.

DW_OP_entry_value 2 { DW_OP_breg1 0 }

[replace existing text]

The value that register 1 contained upon entering the current subprogram is pushed on the stack.

[with new text]

The variable's address is the value that register 1 contained upon entering the current subprogram.

DW_OP_entry_value 1 { DW_OP_reg1 }

[replace existing text]

Same as the previous example (push the value register 1 contained upon entering the current subprogram) but use the more compact register location description.

[with new text]

Same as the previous example, but uses the more compact register location description.

DW_OP_entry_value 2 { DW_OP_breg1 0 }
DW_OP_stack_value

[replace existing text]

The value that register 1 contained upon entering the current suprogram is pushed on the stack. This value is the "contents" of an otherwise anonymous location.

[with new text]

The variable's value is the value that register 1 contained upon entering the current subprogram. This value is the "contents" of an otherwise anonymous location.

DW_OP_entry_value 1 { DW_OP_reg1 }
DW_OP_stack_value

[replace existing text]

Same as the previous example (push the value register 1 contained upon entering the current subprogram) but use the more compact register location description.

[with new text]

Same as the previous example, but uses the more compact register location description.

DW_OP_entry_value 3 { DW_OP_breg4 16 DW_OP_deref }
DW_OP_stack_value

[existing text unchanged]

Add 16 to the value register 4 had upon entering the current subprogram to form an address and then push the value of the memory location at that address. This value is the "contents" of an otherwise anonymous location.

DW_OP_entry_value 1 { DW_OP_reg5 }
DW_OP_plus_uconst 16

[existing text unchanged]

The address of the memory location is calculated by adding 16 to the value contained in register 5 upon entering the current subprogram.

Also, remove the italicized note about how this last example does not end with DW_OP_stack_value. That's clear from context.


2023-10-30: Agreed that proposed change to 2.5.1.7 is correct, but examples in Appendix D are actually valid, if confusing. Will revise issue with improved explanations of the examples and revisit.

2023-11-07: Revised.

2023-11-13: Accepted with editorial changes suggested in email. There was a suggestion to omit the expression length operand in the examples — this is left to the editor's discretion. Also agreed to reformat other examples in D.1.3 to show each DWARF operator on separate lines, at the editor's discretion.