{"record":{"id":"9b0d375ec580a5c2","repo":"NationalSecurityAgency/ghidra","slug":"usage-ghidra-trace-putmem-address-length-state-p","errorCode":null,"errorMessage":"Usage: ghidra trace putmem ADDRESS LENGTH STATE [PAGES]","messagePattern":"Usage: ghidra trace putmem ADDRESS LENGTH STATE \\[PAGES\\]","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"Ghidra/Debug/Debugger-agent-lldb/src/main/py/src/ghidralldb/commands.py","lineNumber":825,"sourceCode":"    By default, all addresses in the trace are marked 'unknown'. Writing bytes\n    to the trace, e.g., via putmem, implicitly marks the affected bytes as\n    'known'. The interpretation of START, LENGTH, and PAGES is the same as in\n    'ghidra trace putmem'.\n    \"\"\"\n\n    args = shlex.split(command)\n    if len(args) == 3:\n        address = args[0]\n        length = args[1]\n        state = args[2]\n        pages = True\n    elif len(args) == 4:\n        address = args[0]\n        length = args[1]\n        state = args[2]\n        pages = (util.get_eval(args[2]).unsigned != 0)\n    else:\n        raise RuntimeError(\n            \"Usage: ghidra trace putmem ADDRESS LENGTH STATE [PAGES]\")\n\n    STATE.require_tx()\n    putmem_state(address, length, state, pages)\n\n\n@convert_errors\ndef ghidra_trace_delmem(debugger: lldb.SBDebugger, command: str,\n                        result: lldb.SBCommandReturnObject,\n                        internal_dict: Dict[str, Any]) -> None:\n    \"\"\"Delete the given range of memory from the Ghidra trace.\n\n    Usage: ghidra trace delmem ADDRESS LENGTH\n\n    Why would you do this? There are probably good reasons, but please consider\n    that deleting information is typically not helping the user.\n\n    Note there is no PAGES argument. This is to prevent accidental deletion of","sourceCodeStart":807,"sourceCodeEnd":843,"githubUrl":"https://github.com/NationalSecurityAgency/ghidra/blob/d5f144c24d6bc53c9cbf4448c6d11143e7696206/Ghidra/Debug/Debugger-agent-lldb/src/main/py/src/ghidralldb/commands.py#L807-L843","documentation":"Usage error raised by ghidra_trace_putmem_state when the token count is not 3 or 4. The command takes ADDRESS, LENGTH, STATE ('known'|'unknown'|'error') plus an optional positional PAGES flag. NOTE: line 823 has the same args[2] indexing bug as putval when 4 args are given (it reads args[2], the STATE token, as the PAGES flag instead of args[3]).","triggerScenarios":"Wrong token count; passing an unsupported --pages flag; miscounting STATE. Additionally, the 4-arg path mis-evaluates PAGES from the STATE slot, so an explicit PAGES argument is effectively ignored and STATE is parsed as an integer.","commonSituations":"User forgets STATE; user adds a flag-style PAGES; user passes STATE in wrong position.","solutions":["Provide exactly 3 or 4 tokens: ADDRESS LENGTH STATE [PAGES].","Use one of known/unknown/error for STATE.","Patch line 823 to read util.get_eval(args[3]) so the 4-arg PAGES slot is parsed correctly (code bug)."],"exampleFix":"// before\nghidra trace putmem-state 0x10000 0x100 --pages\n// after\nghidra trace putmem-state 0x10000 0x100 known 1","handlingStrategy":"validation","validationCode":"import shlex\n\ndef validate_putmem_state(command: str) -> None:\n    toks = shlex.split(command)\n    if len(toks) not in (3, 4):\n        raise ValueError('putmem-state needs ADDRESS LENGTH STATE [PAGES]')\n    if toks[2] not in ('known', 'unknown', 'error'):\n        raise ValueError(f\"STATE must be known/unknown/error, got {toks[2]}\")","typeGuard":null,"tryCatchPattern":"try:\n    ghidra_trace_putmem_state(debugger, command, result, internal_dict)\nexcept RuntimeError as e:\n    if str(e).startswith('Usage:'):\n        result.SetError(str(e))\n    else:\n        raise","preventionTips":["Use the 3-arg form to avoid the args[2]/args[3] PAGES bug on line 823.","Restrict STATE to known/unknown/error.","Patch line 823 to read args[3] if you need explicit PAGES."],"tags":["ghidra-trace","argument-validation","cli-usage","known-bug"],"backgroundTag":null,"analyzedSha":"d5f144c24d6bc53c9cbf4448c6d11143e7696206","analyzedAt":"2026-08-14T01:00:57.564Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}