NationalSecurityAgency/ghidra · error · Exception
Could not build data for register value {rv.value}
Error message
Could not build data for register value {rv.value} What it means
Raised inside the write_reg method when lldb.SBData.Append() returns False while assembling register value bytes. The method converts each byte of the register value via EvaluateExpression('(char){b}'), collects the results into an SBData buffer, and this error fires when a byte cannot be appended to that buffer.
Source
Thrown at Ghidra/Debug/Debugger-agent-lldb/src/main/py/src/ghidralldb/methods.py:761
@REGISTRY.method()
def write_reg(frame: StackFrame, name: str, value: bytes) -> None:
"""Write a register."""
proc = find_proc_by_frame(frame)
util.get_debugger().SetSelectedTarget(proc.target)
f = find_frame_by_obj(frame)
exec_convert_errors(f'frame select {f.idx}')
rv = frame.trace.extra.require_rm().map_value_back(proc, name, value)
reg = f.registers[0].GetChildMemberWithName(name)
error = lldb.SBError()
data = lldb.SBData()
tgt = util.get_target()
for b in rv.value:
bv = tgt.EvaluateExpression(f"(char){b}")
if bv.error.fail:
raise Exception(bv.error.description)
if not data.Append(bv.GetData()):
raise Exception(f"Could not build data for register value {rv.value}")
if not reg.SetData(data, error):
raise Exception(error.description)
with commands.open_tracked_tx(f'Write Register {name}'):
exec_convert_errors('ghidra trace putreg')
View on GitHub (pinned to d5f144c24d)
Solutions
- Check rv.value byte range before the loop: ensure each byte is 0-255.
- Verify the LLDB target is in a valid state for expression evaluation before write_reg.
- Log bv.GetData() and bv.error for the failing byte to diagnose the LLDB-side failure.
- Consider replacing the byte-by-byte Append approach with a single SBData.SetData or CreateDataFromInt call.
Example fix
# before: byte-by-byte Append
for b in rv.value:
bv = tgt.EvaluateExpression(f"(char){b}")
if bv.error.fail:
raise Exception(bv.error.description)
if not data.Append(bv.GetData()):
raise Exception(f"Could not build data for register value {rv.value}")
# after: single-shot SBData construction
from struct import pack
raw = bytes(rv.value)
data = lldb.SBData.CreateDataFromInt(
int.from_bytes(raw, 'big' if rm.byte_order == 'big' else 'little'),
size=len(raw),
) if hasattr(lldb.SBData, 'CreateDataFromInt') else lldb.SBData()
if not data and not raw:
for b in rv.value:
bv = tgt.EvaluateExpression(f"(char){b}")
data.Append(bv.GetData()) Defensive patterns
Strategy: try-catch
Validate before calling
for b in rv.value:
if not (0 <= b <= 255):
raise ValueError(f"Byte {b} out of range for (char) cast")
# also verify target is valid for expression evaluation
if not util.get_target().IsValid():
raise RuntimeError("LLDB target is not valid for expression evaluation") Try / catch
try:
# ... build data via Append ...
except Exception as e:
if 'Could not build data' in str(e):
log.error(f"SBData.Append failed for register {name}, value={rv.value}")
raise RuntimeError(f"Cannot write register {name}: LLDB data build failed") from e
raise Prevention
- Validate each byte in rv.value is 0-255 before the expression-evaluation loop.
- Ensure the LLDB target is valid and in a stopped state before write_reg.
- Consider replacing the byte-by-byte Append approach with a bulk SBData construction.
When it happens
Trigger: write_reg is called with a frame, register name, and byte value. The mapped-back value rv.value is iterated byte-by-byte; for each byte, tgt.EvaluateExpression('(char){b}') is evaluated and its SBData is appended via data.Append(bv.GetData()). If Append returns False for any byte, the exception is raised.
Common situations: The byte value in rv.value is outside the valid range for the expression (e.g. negative or >255 if the expression cast is invalid). The LLDB target cannot evaluate the cast expression (e.g. invalid target state). A register value contains unexpected byte values from a faulty register mapper.
Related errors
- Usage: ghidra trace disassemble ADDRESS
- Usage: ghidra trace put-processes
- Usage: ghidra trace put-available
- Usage: ghidra trace put-breakpoints
- Usage: ghidra trace put-watchpoints
AI-assisted analysis of NationalSecurityAgency/ghidra@d5f144c24d (2026-08-14).
Data as JSON: /api/errors/c6205207b5890478.
Report an issue: GitHub.