[Dwarf-Discuss] Semantics of DW_OP_(b)reg

Adrian Prantl aprantl at apple.com
Mon Mar 20 10:04:10 PDT 2017


> On Mar 20, 2017, at 9:59 AM, Jakub Jelinek <jakub at redhat.com> wrote:
> 
> On Mon, Mar 20, 2017 at 09:23:36AM -0700, Adrian Prantl wrote:
>> 
>>> On Mar 17, 2017, at 2:49 PM, David Anderson <davea42 at linuxmail.org> wrote:
>>> 
>>> On 03/17/2017 01:18 PM, Adrian Prantl wrote:
>>>> Are these two expressions equivalent?
>>>> 1. DW_OP_breg1 0 DW_OP_breg2 0 DW_OP_plus DW_OP_stack_value
>>>> 2. DW_OP_reg1    DW_OP_reg2    DW_OP_plus DW_OP_stack_value
>>> 
>>> In DW4 (DW5 has same text)
>>> These operations name a register location. To fetch the contents of a
>>> register, it is necessary to
>>> use one of the register based addressing operations, such as DW_OP_bregx
>>> (see Section
>>> 2.5.1.2).
>>> 
>>> To me that means that 2. above cannot work.
>> 
>> Thanks for the clarification!
>> 
>> To summarize in my own words: in DWARF 4+, a DW_OP_reg(x) may only appear in a register location description, which implies that it must either be the only operation in an expression, or embedded inside an expression that takes a register location description as an argument, such as DW_OP_entry_value.
>> 
>> In particular, this means that these two location descriptions are equivalent:
>> 1. DW_OP_breg1 0 DW_OP_stack_value ; implicit location description
>> 2. DW_OP_reg1                      ; register location description
> 
> They are not equivalent.  The former is, the value of this and this can be
> computed by adding 0 to the value of register 1, the latter the value lives
> in the register 1.  To the debug info consumer, 1. is something you can't
> really modify if you e.g. want to change the value of some variable, while
> 2. can be modified.

Thanks! That is of course an important distinction for the debugger. It also explains why register location descriptions exist even though they appear to be redundant with the more general implicit descriptions at first.

-- adrian

>> 
>> This is illegal:
>> 1. DW_OP_reg1 DW_OP_deref
> 
> Yeah, illegal.
> 
>> And these are also equivalent:
>> 1. DW_OP_breg1 0 DW_OP_deref DW_OP_stack_value ; implicit loc. desc.
>> 2. DW_OP_breg1 0                               ; memory loc. desc.
> 
> Again, same difference as above, the former can't be modified, the latter
> can.
> 
> 	Jakub



More information about the Dwarf-Discuss mailing list