[Dwarf-discuss] DW_OP_piece limits and assumptions

jeff nelson jeff.nelson
Wed Apr 27 19:06:49 GMT 2005


Thanks to everyone who contributed to the discussion of the FBREG
operator. I now have another set of questions regarding how folks are
interpreting and using DW_OP_piece.


1. Are there any limits to the size of the result returned by
DW_OP_piece? There doesn't appear to be an explicit restriction, so I'm
wondering if there ought to be one or not. There seem to be the
following choices:

a) Limit the expression size to the size of an address, so that the
Dwarf expression stack can be used to hold the result.

b) Let the expression be an arbitrary size, and either keep the result
in a separate storage area, or permit the expression stack to hold an
arbitrary-sized value. I think the latter is needed in case the
intermediate result of DW_OP_piece is used by any subsequent Dwarf
operator in the expression.


2. Are there any limits to the size of the operand? This is similar to
the first question. If option (a) is selected above, then the size of
the operand would have to be the size (in bytes) of an address. If (b)
then the size can be unlimited.


3. There is an implied combining operation that occurs when a Dwarf
expression contains two or more DW_OP_piece operators. I'd like to see
this combining made explicit in the description of DW_OP_piece.

The definition of DW_OP_piece on page 20 of the Dwarf V3 spec (draft 9)
reads:

    DW_OP_piece takes a single operand, which is an unsigned LEB128
    number. The number describes the size in bytes of the piece of
    the object referenced by the DWARF expression whose result is at
    the top of the stack.

Here is the only example of DW_OP_piece, on page 24:

    DW_OP_reg3 DW_OP_piece 4 DW_OP_reg10 DW_OP_piece 2

    A variable whose first four bytes reside in register 3 and whose
    next two bytes reside in register 10.

If you follow the strict interpretation of DW_OP_piece, the expression
ought to result in TWO values, not one. That is, when you reach the
second DW_OP_piece, what definition or rule do you use to combine it's
value with the results of the first DW_OP_piece?

To resolve this issue, I propose the following addition to the
description of DW_OP_piece:

    DW_OP_piece is a context-sensitive operator. For the first occurance
    of DW_OP_piece in a DWARF expression, the operator result is pushed
    on the DWARF expression stack. For all remaining occurances, the
    operator result is appended to the value at the top of the stack. In
    this way, the results of several consecutive DW_OP_piece operations
    are combined into a single value.

Note that:
a) "appended" is undefined.

b) I make the simplifying assumption that the the operator result is
saved on the stack (i.e., leaving questions 1 and 2 above unresolved for
now).

Thanks for your feedback.

-Jeff





More information about the Dwarf-discuss mailing list