Issue 100909.1: DW_OP_entry_value

Author: Jakub Jelinek
Champion: Jakub Jelinek
Date submitted: 2010-09-09
Date revised:
Date closed:
Type: Enhancement
Status: Accepted
DWARF version: 5
Section 2.5.1.6, pg 24

Tracking of values passed as arguments to functions in debug information
========================================================================

Overview
--------

Many architectures pass arguments in registers and quite often
the register in which an argument has been passed is quickly reused
for something else. In that case all the debugger can say is that
a value has been optimized out.  If the argument is never modified
in the function, often the value can be discovered through extra
effort.  This could be by setting preemptive breakpoints to collect
argument values at function entry, or by unwinding in the debugger
to the caller and seeing what value has been passed to the function.
A companion proposal addresses unwinding to a caller to determine
argument values for such cases.

Proposed changes to DWARF
-------------------------

New DWARF expression operation

DW_OP_entry_value   0xa1    2   ULEB128 size followed by
                    DWARF expression block
                    of that size

2.5.1.6

Change "one special operation" into "two special operations".

Add

2. DW_OP_entry_value

The DW_OP_entry_value operation pushes a value that had a known location
upon entering the current subprogram.  It uses two operands: an unsigned
LEB128 length, followed by a block containing a DWARF expression or
a simple register location description.  The length gives the length
in bytes of the block.  If the block contains a register location
description, DW_OP_entry_value pushes the value that register had upon
entering the current subprogram.  If the block contains a DWARF expression,
the DWARF expression is evaluated as if it has been evaluated upon entering
the current subprogram.  The DWARF expression should not assume any values
being present on the DWARF stack initially and should result in exactly one
value being added to the DWARF stack in the end.  That value is then the value
being pushed by the DW_OP_entry_value operation.  DW_OP_push_object_address
is not meaningful inside of this DWARF expression.

*The DW_OP_entry_value operation can be used by consumers if they are able
to find the call site in the caller function, unwind to it and the corresponding
DW_TAG_call_site_parameter entry has DW_AT_call_site_value or
DW_AT_call_site_data_value attributes that can be evaluated to find out the
value a function parameter had on the first instruction in the function.
Or non-interactive consumers which know what variables will need to be
inspected ahead of running the debugged program could put breakpoint
on the first instruction in functions where there is no other way to find
some variable's value, but evaluating DW_OP_entry_value operation.  The
consumer can collect there the value of registers or memory referenced in
DW_OP_entry_value operations, then continue to breakpoints where the values
of variables or parameters need to be inspected and use there the remembered
register or memory values during DW_OP_entry_value evaluation.*

2.6.1.3

Add

DW_OP_entry_value 1 DW_OP_reg5 DW_OP_stack_value
DW_OP_entry_value 2 DW_OP_breg5 0 DW_OP_stack_value

  Both of these location descriptions mean the value register 5 had upon
  entering of the current subprogram.

DW_OP_breg2 0 DW_OP_entry_value 1 DW_OP_reg5 DW_OP_add DW_OP_stack_value

  The value register 5 had upon entering of the current subprogram
  plus the value register 2 currently has.

DW_OP_entry_value 3 DW_OP_breg4 16 DW_OP_deref DW_OP_stack_value
DW_OP_entry_value 6 DW_OP_entry_value 1 DW_OP_reg4 DW_OP_plus_uconst 16 DW_OP_deref DW_OP_stack_value

  These two location expressions do the same thing, push the value
  memory location with size of an address pointed to by value of
  register 4 upon entering current subprogram plus 16 had upon
  entering of the current subprogram.

7.7.1

Add

DW_OP_entry_value   0xa1    2   ULEB128 size followed by
                    DWARF expression block
                    of that size to figure 24.

---

Revised 2/12/2013.  Previous version:
http://dwarfstd.org/issues/100909.1-1.html
4/22/2014 -- Accepted.