Index: docs/LangRef.rst =================================================================== --- docs/LangRef.rst +++ docs/LangRef.rst @@ -4594,11 +4594,41 @@ DWARF specifies three kinds of simple location descriptions: Register, memory, and implicit location descriptions. Register and memory location descriptions -describe the *location* of a source variable (in the sense that a debugger might -modify its value), whereas implicit locations describe merely the *value* of a -source variable. DIExpressions also follow this model: A DIExpression that -doesn't have a trailing ``DW_OP_stack_value`` will describe an *address* when -combined with a concrete location. +describe the *concrete location* of a source variable (in the sense that a +debugger might modify its value), whereas *implicit locations* describe merely +the actual *value* of a source variable which might not exist in registers or +in memory. Note that a location description is defined for certain ranges of a +program, i.e the location of a variable may change over the course of the +program. + +A DIExpression attached to a ``llvm.dbg.addr`` or ``llvm.dbg.declare`` +intrinsic describes the concrete location of a source variable. A debugger must +be able to modify the variable via this location. Consequently, this +DIExpression must not contain ``DW_OP_stack_value``. + +The value operand of a ``llvm.dbg.value`` intrinsic may either be a concrete +location or an implicit one. The following rules apply to a DIExpression +attached to a ``llvm.dbg.value`` intrinsic: + +- If the value operand of the intrinsic is an implicit location, the + DIExpression is interpreted as if it contained ``DW_OP_stack_value``, + regardless of what the DIExpression contains. The intrinsic describes an + implicit location. + +- If the value operand of the intrinsic is a concrete location and the + DIExpression does not contain ``DW_OP_stack_value``, the intrinsic describes + a concrete location. + +- If the value operand of the intrinsic is a concrete location and the + DIExpression contains ``DW_OP_stack_value``, the DIExpression is interpreted + as if it started with a ``DW_OP_deref``, regardless of what else the + DIExpression contains. The intrinsic describes an implicit location. + +.. note:: + + In the future, ``llvm.dbg.value`` may only be allowed to have an implicit + value operand. This should simplify DIExpression handling by eliminating two + of the special cases described above. .. code-block:: text Index: docs/SourceLevelDebugging.rst =================================================================== --- docs/SourceLevelDebugging.rst +++ docs/SourceLevelDebugging.rst @@ -242,7 +242,8 @@ value. The first argument is the new value (wrapped as metadata). The second argument is a `local variable `_ containing a description of the variable. The third argument is a `complex expression -`_. +`_, with semantics which depend on whether the value +operand is an implicit or a concrete location. Object lifetimes and scoping ============================