[Dwarf-Discuss] DW_OP_regX vs. DW_OP_bregX 0

Robinson, Paul T NonStop paul.t.robinson@hp.com
Thu Feb 12 19:42:44 GMT 2009


Jakub Jelinek wrote:
>GCC uses DW_OP_regX heavily in lots of places, e.g. in .dwarf_frame when
>dynamic stack realignment is needed:
>DW_CFA_expression: r7 (edi) (DW_OP_reg5; DW_OP_const1s: -8; DW_OP_and; 
>DW_OP_const1s: -4; DW_OP_plus)
>or e.g. in .dwarf_loc for
>DW_OP_reg4; DW_OP_deref etc.
>
>But I've been recently pointed at Dwarf3's 2.6.1 which seems to forbid this.
>What's the rationale for it?  When DW_OP_reg5 is used alone, it has slightly
>different meaning from DW_OP_breg5 0 (the former means the value can be
>changed by tweaking the register, the latter is more like an rvalue), but
>when it is not used alone, is there a reason why DW_OP_regX couldn't be
>treated as a more compact form of DW_OP_bregX 0?

DW_CFA_expression takes a location expression.  That is, an expression
that specifies a storage location, somewhere in the machine.

DW_OP_reg5 says the location is register 5.
DW_OP_breg5 0 says it is the memory address contained in register 5.
Clearly these are different locations (register vs. memory).

GCC is producing nonstandard expressions.

>I'm afraid changing all DW_OP_regX in GCC to DW_OP_bregX 0 except for
>DW_OP_regX alone in a location list will bloat the debug and unwind info a
>lot.

If the 0 offset happens really a lot, it could be worth doing something
about it.  Blessing GCC's current behavior doesn't feel right, though,
as it overloads DW_OP_regN to mean one thing when used by itself and 
another thing when embedded in a larger expression.  This puts an 
unnecessary burden on the interpreter.

I might rather suggest a new set of operators, say DW_OP_cregN, which
are exactly equivalent to DW_OP_bregN 0.  (creg = content of register.)

--paulr




More information about the Dwarf-discuss mailing list