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

Adrian Prantl aprantl at apple.com
Mon Mar 20 09:23:36 PDT 2017


> 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

This is illegal:
1. DW_OP_reg1 DW_OP_deref

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.

Let me know if I got anything wrong.
-- adrian


> 
> In 1. the value of   DW_OP_breg1 0
> (for example) is  pushed on the stack.
> 
> Can someone point out
> where the standard (4 or 5 or?) states the push happens?
> Ah yes: DW5:
> 
> 2.5.1.2 Register Values
> 
> The following operations push a value onto the stack
> that is either the contents of a register or the result
> of adding the contents of a register to a given
> signed offset. DW_OP_regval_type pushes the
> contents of the register together with the given
> base type, while the other operations push the
> result of adding the contents of a register
> to a given signed offset together with the generic type.
> 
> Notice that DW_OP_reg<n> is NOT in the list where something
> gets pushed on the stack.
> 
> Comments/correction?
> DavidA.
> _______________________________________________
> Dwarf-Discuss mailing list
> Dwarf-Discuss at lists.dwarfstd.org
> http://lists.dwarfstd.org/listinfo.cgi/dwarf-discuss-dwarfstd.org



More information about the Dwarf-Discuss mailing list