[Dwarf-discuss] register name operators

David B. Anderson davea
Wed Nov 15 17:54:47 GMT 2006

Marcel Mettes writes:
|David B. Anderson wrote:
|>Marcel Mettes writes:

|I think I understand why DW_OP_piece is not an operator. Given that a 
|expression must be used for both reading and writing, one cannot
|implement DW_OP_piece as a mask+shift operation. That would not
|work when writing. (not something I thought of the first time I studied 
|this :-)
|However, in the example in the DWARF3 document, 2.6.5, there is also an 
|DW_OP_fbreg operator
|in the last example:
|	DW_OP_reg0 DW_OP_piece 4 DW_OP_piece  4 DW_OP_fbreg  -12 DW_OP_piece  4
|DW_OP_fbreg is a regular operator. Is that also valid given the register 
|name operator restriction?

Yes. In effect
        DW_OP_fbreg  -12 
are 3 distinct dwarf expressions.
Each dwarf expresion supplying a part of the result 'independently'.
So the restriction on DW_OP_reg<n> applies independently in
each of the 3 distinct dwarf expressions.

|I must confess that I do not really understand why the DW_OP_regx and 
|have been restricted in the DWARF 3, except for perhaps making it work 
|with incomplete
|(older?) expression interpreters?

No. It's because nothing else makes sense.
	DW_OP_reg0 says the variable is  *in* the register.
All other dwarf-expressions compute an address and the variable
is at that computed address.

There is no way to combine DW_OP_reg3 (for example) with any other
operator (DW_OP_piece and DW_OP_bit_piece being the exceptions).
It makes no sense to do so. DW_OP_reg<n> do NOT say to dereference the register,
they just say 'register number <n>'.   Since (for most architectures)
a register has no address the  normal dwarf expression result
of 'address of the variable' makes no sense.  DW_OP_reg<n>
provides a way to deal with the special case.

Don't know if I'm explaining this very well.

|In the 8th example, two DW_OP_reg's appear in one expression
|    DW_OP_reg3 DW_OP_piece 4 DW_OP_reg10 DW_OP_piece 2

|So I wonder how to interprete this limitation as described for 
|DW_OP_regx/DW_OP_reg3 in 2.6.1 .

These are *independent* as DW_OP_piece (DW_OP_bit_piece) delineate
the end of a simple expression (well sort of) and 
with each simple expresson these are unique.

The problem is that there's no language in the document (that I recognize) that
really distinquishes the two categories of simple expressions:
   simple simple expression
   simple expression of a set of simple expressions terminated
	by DW_OP_piece.

Difficult to state.
	    operators..... (left as exercise)

	      simple-expression0 DW_OP_piece <n>
	      simple-expression0 DW_OP_bit_piece <n>

	      simple-expression-n  piece

	where the restriction applies to simple-expression0

Hmm. Then the <empty> needs to be accounted for. 
And then the DW_OP_reg<n> restriction applies to simple-expression0
(not to simple-expression-n).

Hope this makes sense.
David Anderson

More information about the Dwarf-discuss mailing list