rust-lang/rust · error · Exception

Cannot bless invalid SBValue object

Error message

Cannot bless invalid SBValue object

What it means

Raised by from_lldb.variable_from_lldb during a bless run when the top-level lldb.SBValue for a variable fails IsValid(). This is the entry point for blessing a variable, so an invalid value means there is nothing to record; the guard prevents writing garbage to the golden file.

Source

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

        raise Exception("Cannot bless invalid child")

    sbtype: lldb.SBType = child.GetType()

    if not sbtype.IsPointerType() and sbtype.GetBasicType() != lldb.eBasicTypeInvalid:
        value = decode_primitive(child)
    else:
        value = None

    children = [
        child_from_lldb(child.GetChildAtIndex(i)) for i in range(child.GetNumChildren())
    ]

    return Child(child.GetName(), child.GetType().GetName(), value, children)


def variable_from_lldb(var: lldb.SBValue) -> Variable:
    if BLESS and not var.IsValid():
        raise Exception("Cannot bless invalid SBValue object")

    sbtype = var.GetType()
    type_name = sbtype.GetName()

    pretty_type_name = var.GetDisplayTypeName()

    if pretty_type_name == type_name:
        pretty_type_name = None

    # We never want to store pointer values since they are expected to change from run to run.
    # For now, we also only want to record values for primitives. In the future, we may support
    # testing the `get_value` output from syntheticproviders, but the current visualizers do not
    # implement this so it isn't urgent.
    if not sbtype.IsPointerType() and sbtype.GetBasicType() != lldb.eBasicTypeInvalid:
        value = decode_primitive(var)
    else:
        value = None

View on GitHub (pinned to 7088e4b63a)

Solutions

  1. Confirm the variable is live at the breakpoint (recompile with -C opt-level=0 -C debuginfo=2).
  2. Verify the breakpoint index and variable name match what the test expects.
  3. Inspect the frame in LLDB interactively (frame variable) before blessing.

Example fix

# before
variable_from_lldb(frame.FindVariable(name))
# after
valobj = frame.FindVariable(name)
if valobj.IsValid():
    variable_from_lldb(valobj)
Defensive patterns

Strategy: type-guard

Validate before calling

valobj = frame.FindVariable(var_name)
if BLESS and not valobj.IsValid():
    raise Exception(f"Cannot bless invalid SBValue for variable {var_name}")
variable_from_lldb(valobj)

Type guard

def is_valid_value(v: lldb.SBValue) -> bool:
    return v.IsValid()

Prevention

When it happens

Trigger: Calling variable_from_lldb with BLESS=True on an SBValue whose underlying variable was optimized away or whose frame has no such value. Typically reached via bless_variable after frame.FindVariable returned a valid-looking but empty object.

Common situations: The variable was optimized out at the breakpoint; the wrong breakpoint index was used; the variable name in the test does not match a real local in the frame.

Related errors


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