[Dwarf-Discuss] question about DW_OP_*_value

Cary Coutant ccoutant at gmail.com
Sun Jun 21 21:12:54 PDT 2009


> About DW_OP_stack_value, the text says:
>
>  This operation may only be followed by DW_OP_piece or DW_OP_bit_piece.
>
> However, later there is an example showing DW_OP_stack_value without a
> following piece operator.
>
> We had some disagreement about the proper interpretation of this
> sentence: should it mean that DW_OP_stack_value *must* be followed by
> a piece operator, or should it mean that DW_OP_stack_value should
> follow the DW_OP_reg* rules and either be followed by a piece operator
> or occur at the end of an expression?

The latter. IF it's followed by anything at all, those are the only
two operators that can follow it. (In other words, DW_OP_stack_value
terminates an expression, and those are the only two operators that
can apply to a terminated expression.)


> Also, I am curious about a couple cases involving
> DW_OP_implicit_value.  What is the meaning of these two cases:
>
>  DW_OP_implicit_value[length=10, ...] DW_OP_piece[length=5]
>
>  DW_OP_implicit_value[length=5, ...] DW_OP_piece[length=10]
>
> I suspect this is addressed somewhere in the text but I am simply not
> finding it.

The first example would seem rather useless, but I'd guess it would
follow normal truncation rules -- you have a 10-byte value, but you're
only going to use 5 bytes of it to assemble an aggregate value of some
sort. In that case, why not just provide the 5 bytes you're going to
use?

The second example could be useful to zero- or sign-extend the given
value to the piece that you're assembling into the aggregate, but that
would require some additional specification.

The way to interpret these is to treat the result of
DW_OP_implicit_value as the (pseudo-)location of the provided value,
whose length is X bytes. Compare that to a normal expression that
delivers a location in memory (with unspecified length). The
DW_OP_piece/bit_piece operator will take Y bytes/bits starting at that
location. Under this interpretation, your second example would grab an
additional 5 bytes, whose contents are currently unspecified, but we
could define them as zero. That would be useful for zero-extension in
a little-endian environment, but it would extend to the right in a
big-endian environment. Perhaps it would be best just to document that
case as undefined, and recommend that DWARF producers avoid generating
a case like your second example.

-cary



More information about the Dwarf-Discuss mailing list