rust-lang/rust · error · Exception

<bless error: Cannot find variable {var_name}>

Error message

<bless error: Cannot find variable {var_name}>

What it means

Raised by from_lldb.bless_variable when frame.FindVariable(var_name) returns an SBValue that is not valid, meaning LLDB cannot find a local/static with that name in the given frame. The message is wrapped in <bless error: ...> so the bless driver surfaces it clearly during reference generation.

Source

Thrown at src/etc/lldb_batchmode/from_lldb.py:326

        synthetic,
        summary,
        format,
        children,
    )


def bless_variable(
    target_data: TargetData, var_name: str, breakpoint_idx: int, frame: lldb.SBFrame
):
    """Updates the given `TargetData` with data generated from the given variable at the given
    breakpoint. This function **does not** write to the input file. Please see
    `TargetData.save_blessing` for more info on when and how to save the data.
    """

    valobj = frame.FindVariable(var_name)
    if not valobj.IsValid():
        # FIXME (todo) error handling
        raise Exception(f"<bless error: Cannot find variable {var_name}>")

    # HACK it's obviously not ideal to output empty breakpoints, but it will be somewhat rare for it
    # to happen (you would need a breakpoint with repr -> breakpoint without repr -> breakpoint
    # with repr). In the more common case (e.g. 1 breakpoint, sequential breakpoints all with repr
    # commands), this saves a lot more space than converting all TargetData.breakpoints to
    # `dict[int,...]`
    if len(target_data.breakpoints) <= breakpoint_idx:
        target_data.breakpoints.extend(
            {} for i in range(1 + breakpoint_idx - len(target_data.breakpoints))
        )

    var_data = variable_from_lldb(valobj)
    target_data.breakpoints[breakpoint_idx][var_name] = var_data

    # We also need to bless the types of the valobj's children, as they may not appear in the type
    # or fields.
    target = valobj.GetTarget()

View on GitHub (pinned to 7088e4b63a)

Solutions

  1. Match the var_name in the test directive to an actual local at that breakpoint (inspect with `frame variable` in LLDB).
  2. Recompile with -C opt-level=0 -C debuginfo=2 so the variable survives.
  3. If the variable was removed on purpose, delete the corresponding bless/check directives.

Example fix

# before: blessing a variable that no longer exists
bless_variable(data, 'old_name', idx, frame)
# after
bless_variable(data, 'new_name', idx, frame)
Defensive patterns

Strategy: type-guard

Validate before calling

valobj = frame.FindVariable(var_name)
if not valobj.IsValid():
    raise Exception(f"<bless error: Cannot find variable {var_name}>")

Type guard

def frame_has_variable(frame: lldb.SBFrame, name: str) -> bool:
    return frame.FindVariable(name).IsValid()

Try / catch

try:
    bless_variable(target_data, var_name, idx, frame)
except Exception as e:
    if "Cannot find variable" in str(e):
        print(f"variable {var_name!r} not live at breakpoint {idx}; check name/opt level")
        raise
    raise

Prevention

When it happens

Trigger: Calling bless_variable with a var_name that does not exist in frame, or exists but was optimized out so FindVariable yields an invalid SBValue. The `if not valobj.IsValid()` guard at line 324 fires.

Common situations: Test specifies a `lldb-check`/`lldb-var` line for a variable that no longer exists after a refactor; optimization removed the variable; the wrong breakpoint/frame was captured.

Related errors


AI-assisted analysis of rust-lang/rust@7088e4b63a (2026-08-10). Data as JSON: /api/errors/18810fa19f5a98de. Report an issue: GitHub.