NationalSecurityAgency/ghidra · error · RuntimeError

Could not evaluate {expression}: {e}

Error message

Could not evaluate {expression}: {e}

What it means

Thrown by ghidra_trace_putval when util.get_eval(expression) raises while trying to evaluate the EXPRESSION in the current target. The original exception text is appended so the user sees LLDB's actual diagnostic (parse error, unknown symbol, etc.).

Source

Thrown at Ghidra/Debug/Debugger-agent-lldb/src/main/py/src/ghidralldb/commands.py:773

    may result in undefined behavior.
    """

    args = shlex.split(command)
    if len(args) == 1:
        expression = args[0]
        pages = True
    elif len(args) == 2:
        expression = args[0]
        pages = (util.get_eval(args[2]).unsigned != 0)
    else:
        raise RuntimeError("Usage: ghidra trace putval EXPRESSION [PAGES]")

    STATE.require_tx()
    try:
        value = util.get_eval(expression)
        address = value.addr
    except BaseException as e:
        raise RuntimeError(f"Could not evaluate {expression}: {e}")
    if not address.IsValid():
        raise RuntimeError(f"Expression {expression} does not have an address")
    start = int(address)
    end = start + start + value.size
    return put_bytes(start, end, result, pages)


def putmem_state(address: str, length: str, state: str,
                 pages: bool = True) -> None:
    trace = STATE.require_trace()
    trace.validate_state(state)
    start, end = eval_range(address, length)
    if start is None or end is None:
        return
    if pages:
        start, end = quantize_pages(start, end)
    proc = util.get_process()
    base, addr = trace.extra.require_mm().map(proc, start)

View on GitHub (pinned to d5f144c24d)

Solutions

  1. Confirm the expression evaluates standalone: 'expr <EXPRESSION>' in LLDB before invoking putval.
  2. Stop the target so evaluation is permitted.
  3. Load the appropriate symbols ('target symbols ...') and retry.
  4. Use LLDB register syntax ('$rax'/'$pc') appropriate for the platform.

Example fix

// before
ghidra trace putval undefined_thing
// after
ghidra trace putval my_struct
Defensive patterns

Strategy: validation

Validate before calling

from ghidralldb import util

def expression_ok(expr: str) -> bool:
    try:
        util.get_eval(expr)
        return True
    except BaseException:
        return False

Try / catch

try:
    value = util.get_eval(expression)
except BaseException as e:
    raise RuntimeError(f'Could not evaluate {expression}: {e}')

Prevention

When it happens

Trigger: Passing an expression LLDB cannot evaluate: undefined variable, syntax error, type with no value, or evaluating while the process is running. Also if the target has no loaded symbols for the referenced identifier.

Common situations: Typo in a variable name; referencing a symbol before the right module/symbol file is loaded; running the command while the inferior is executing; using GDB-style syntax ('$pc') where LLDB expects different register syntax.

Related errors


AI-assisted analysis of NationalSecurityAgency/ghidra@d5f144c24d (2026-08-14). Data as JSON: /api/errors/62b5ed70c297982d. Report an issue: GitHub.