Skip to content

No way to describe computed variable values (analogue of DWARF expression locations / DW_OP_stack_value) #291

Description

@djolertrk

Pointers can describe where a variable's bytes live (regions in stack, storage, memory, ...), and the expression grammar can compute positions ($sum, $read, $keccak256, ...). But there is no form that says: "this variable currently has no allocation at all — its value equals this expression".

Optimizing compilers need this constantly. After rematerialization or expression folding, a source variable may have no region anywhere, while its value is still perfectly recoverable from other live state, e.g.:

  • a constant folded into every use site (value = literal 42),
  • let x := add(a, 1) eliminated, with a still live (value = a + 1),
  • a value recomputable from a storage slot that is still intact.

DWARF handles this with expression-based location descriptions, with a stack-machine expression (see e.g. https://www.hitzhangjie.pro/debugger101-en.io/8-dwarf/4-die/2-desc-locations.html) terminated by DW_OP_stack_value, meaning "the computed result is the value, there is no address". Without an equivalent, the only honest thing a producer can emit for such variables is "unavailable", which loses debugging quality exactly where optimizations kick in.

The expression grammar seems to already contain most of the machinery; what is missing is a schema form marking the result as the value itself rather than a position. A minimal sketch:

{ "value": <expression> }

allowed wherever a variable's pointer goes in a program context (perhaps not inside region collections, since it denotes no data range).

Context: we hit this in the Solidity compiler's ethdebug work (solc #16780 PR) — we currently model these variables with a "computed" phase that admits the value is recomputable in principle but cannot carry the recipe.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions