{"record":{"id":"62b5ed70c297982d","repo":"NationalSecurityAgency/ghidra","slug":"could-not-evaluate-expression-e","errorCode":null,"errorMessage":"Could not evaluate {expression}: {e}","messagePattern":"Could not evaluate (.+?): (.+?)","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"Ghidra/Debug/Debugger-agent-lldb/src/main/py/src/ghidralldb/commands.py","lineNumber":773,"sourceCode":"    may result in undefined behavior.\n    \"\"\"\n\n    args = shlex.split(command)\n    if len(args) == 1:\n        expression = args[0]\n        pages = True\n    elif len(args) == 2:\n        expression = args[0]\n        pages = (util.get_eval(args[2]).unsigned != 0)\n    else:\n        raise RuntimeError(\"Usage: ghidra trace putval EXPRESSION [PAGES]\")\n\n    STATE.require_tx()\n    try:\n        value = util.get_eval(expression)\n        address = value.addr\n    except BaseException as e:\n        raise RuntimeError(f\"Could not evaluate {expression}: {e}\")\n    if not address.IsValid():\n        raise RuntimeError(f\"Expression {expression} does not have an address\")\n    start = int(address)\n    end = start + start + value.size\n    return put_bytes(start, end, result, pages)\n\n\ndef putmem_state(address: str, length: str, state: str,\n                 pages: bool = True) -> None:\n    trace = STATE.require_trace()\n    trace.validate_state(state)\n    start, end = eval_range(address, length)\n    if start is None or end is None:\n        return\n    if pages:\n        start, end = quantize_pages(start, end)\n    proc = util.get_process()\n    base, addr = trace.extra.require_mm().map(proc, start)","sourceCodeStart":755,"sourceCodeEnd":791,"githubUrl":"https://github.com/NationalSecurityAgency/ghidra/blob/d5f144c24d6bc53c9cbf4448c6d11143e7696206/Ghidra/Debug/Debugger-agent-lldb/src/main/py/src/ghidralldb/commands.py#L755-L791","documentation":"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.).","triggerScenarios":"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.","commonSituations":"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.","solutions":["Confirm the expression evaluates standalone: 'expr <EXPRESSION>' in LLDB before invoking putval.","Stop the target so evaluation is permitted.","Load the appropriate symbols ('target symbols ...') and retry.","Use LLDB register syntax ('$rax'/'$pc') appropriate for the platform."],"exampleFix":"// before\nghidra trace putval undefined_thing\n// after\nghidra trace putval my_struct","handlingStrategy":"validation","validationCode":"from ghidralldb import util\n\ndef expression_ok(expr: str) -> bool:\n    try:\n        util.get_eval(expr)\n        return True\n    except BaseException:\n        return False","typeGuard":null,"tryCatchPattern":"try:\n    value = util.get_eval(expression)\nexcept BaseException as e:\n    raise RuntimeError(f'Could not evaluate {expression}: {e}')","preventionTips":["Test the expression with 'expr <EXPRESSION>' in LLDB first.","Stop the target before evaluation.","Confirm symbols are loaded for referenced identifiers."],"tags":["ghidra-trace","expression-eval","lldb","argument-validation"],"backgroundTag":null,"analyzedSha":"d5f144c24d6bc53c9cbf4448c6d11143e7696206","analyzedAt":"2026-08-14T01:00:57.564Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}