[Dwarf-discuss] PROPOSAL: Constant expressions in locations lists

Roland McGrath roland@redhat.com
Wed May 30 02:26:49 GMT 2007


This was moved to the private mailing list and it doesn't look like there
has been any traffic about it for a while.  So I don't know what its status is.
I think the formulation should be adjusted a little from what was proposed.

The block is often overkill, but I think adding a plethora of
constant_value[248] and so forth would be a waste of opcodes and needless
new repetition in decoding.  Instead, I suggest using a special suffix
operation DW_OP_implicit_value.  It can follow DW_OP_const*, DW_OP_lit*, etc.

Doing it this way also makes it a natural way to describe more cases.
(This is why I used DW_OP_implicit_value rather than DW_OP_constant_value.)
Imagine:

	for (int i = 0, j = 0; i < n; ++i, j += 4) {
		...
	}

j is optimized away and has no location, but its value is computable, e.g.:

    "i" location expr: DW_OP_reg0
    "j" location expr: DW_OP_breg0(0) DW_OP_lit4 DW_OP_mul DW_OP_implicit_value

(In fact, I think I might prefer DW_OP_computed_value to be more clear.)

Note that this makes DW_CFA_val_expression redundant with using
DW_CFA_expression and DW_OP_implicit_value.  If we had contemplated these
cases earlier, we might have used this instead of adding DW_CFA_val_expression.


Furthermore, imagine a compiler generating the very same code for:

	for (int i[2] = {0,0}; i[0] < n; ++i[0], i[1] += 4) {
		...
	}

Now i[0] has a usable location but i[1] does not.  So in the 070512.1
grammar's terms, this says that the DW_OP_implicit_value suffix in fact
must be a "simple_location_expression".  This permits i's location to be:

    DW_OP_reg0 DW_OP_piece(4) \
    DW_OP_breg0(0) DW_OP_lit4 DW_OP_mul DW_OP_implicit_value DW_OP_piece(4)


Incidentally, it should be noted that DW_AT_const_value is now redundant
with a trivial location expression using DW_OP_implicit_value.  Using it
should be encouraged for the cases it covers, both because of the existing
practice and because of the simpler and smaller encoding.


Thanks,
Roland




More information about the Dwarf-discuss mailing list