Clarify Location Expressions

From wiki.dwarfstd.org
Jump to navigation Jump to search

There are a few places where we use expressions for things other than returning the location of something. But we don't do it very much yet. So it's hard to find good examples.

I'm now thinking we should remove all references to "location expressions" in dwarf 4, and simply use the term "expression".

It might be nice to have two explicit forms for expressions, one which returns an address and one which returns a value. I'm not sure how the singleton registers fit into that. ugh.


---



Location expressions are used to describe the location of a value in the target program image. Sometimes it's the value of a local variable (DW_AT_location), sometimes it is the dynamic extent of an array (DW_AT_size) or some other significant value.

There are three basic kinds of location expressions:

BASE Expression

Most expressions fall into this category, and almost all the operators contribute to these kinds of expressions. The result of a BASE location expression is a value. In some cases an attribute will expect the value to be an address, and the consumer is expected to use that address to fetch something further. In some cases the expression directly returns a final value other than an address.

If the result is the address of a variable, then the memory size of the variable is found be examining the type recorded in the dwarf information.

If the result is a non-address value, then the constant will be address-sized and the consumer will again need to determine which parts of the value are valid based on the expected size of the value.

<<Composition Operators>> may not be used inside a BASE expression.

REGISTER Location Expression

When a value is stored in a register, it has no memory address. REGISTER location expressions are composed of either a single <<DW_OP_reg(n)>> operator or a <<DW_OP_regx>> operator with an argument indicating the register number.

COMPOSED Location Expression

A COMPOSED location expression is composed of one or more MEMORY or REGISTER location expressions glued together using <<Composition Operators>>. This kind of expression is used to record a value that is split into multiple parts. Some of the parts might be in different locations, or some of the parts might be unavailable.