NationalSecurityAgency/ghidra · error · RuntimeError
Invalid argument: {arg}
Error message
Invalid argument: {arg} What it means
Thrown by the retain_values command handler in the drgn agent when the first element of key_list starts with '--' but is not one of the recognized flags (--elements, --attributes, --both). NOTE: the code has a latent inconsistency — it checks key_list[0] in the first and last branch but keys[0] in the middle two branches, suggesting keys and key_list may diverge in some code paths, potentially masking valid flags.
Source
Thrown at Ghidra/Debug/Debugger-agent-drgn/src/main/py/src/ghidradrgn/commands.py:839
switch, then the switch is required. Only the first argument is taken as the
switch. All others are taken as keys.
"""
key_list = keys.split(" ")
trace, tx = STATE.require_tx()
kinds = 'elements'
if key_list[0] == '--elements':
kinds = 'elements'
key_list = key_list[1:]
elif keys[0] == '--attributes':
kinds = 'attributes'
key_list = key_list[1:]
elif keys[0] == '--both':
kinds = 'both'
key_list = key_list[1:]
elif key_list[0].startswith('--'):
raise RuntimeError("Invalid argument: " + key_list[0])
trace.proxy_object_path(path).retain_values(key_list, kinds=kinds)
def ghidra_trace_get_obj(path: str) -> None:
"""
Get an object descriptor by its canonical path.
This isn't the most informative, but it will at least confirm whether an
object exists and provide its id.
"""
trace = STATE.require_trace()
object = trace.get_object(path)
print("{}\t{}".format(object.id, object.path))
def ghidra_trace_get_values(pattern: str) -> None:
"""View on GitHub (pinned to d5f144c24d)
Solutions
- Use only recognized flags: --elements, --attributes, or --both.
- Omit the flag entirely to default to 'elements'.
- If the error persists with a correct flag, inspect the keys vs key_list variables in the source — there is a bug where --attributes and --both check keys[0] instead of key_list[0].
Example fix
// before
ghidra_trace_retain_values('Processes[]', '--all', 'key1', 'key2')
// after
ghidra_trace_retain_values('Processes[]', '--both', 'key1', 'key2') Defensive patterns
Strategy: validation
Validate before calling
VALID_FLAGS = {'--elements', '--attributes', '--both'}
def validate_retain_args(key_list):
if key_list and key_list[0].startswith('--'):
if key_list[0] not in VALID_FLAGS:
raise ValueError(
f"Unrecognized flag '{key_list[0]}'. Valid: {VALID_FLAGS}")
return key_list[1:], key_list[0]
return key_list, '--elements' Try / catch
try:
ghidra_trace_retain_values(path, *args)
except RuntimeError as e:
if 'Invalid argument' in str(e):
print(f"Use --elements, --attributes, or --both. Got: {e}")
raise Prevention
- Only use --elements, --attributes, or --both as flags.
- Omit the flag entirely to default to 'elements'.
- Be aware of the keys vs key_list code inconsistency if --attributes or --both fails unexpectedly.
When it happens
Trigger: Calling the retain_values command with an unrecognized flag like '--all', '--keys', or '--merge'. Also, if keys and key_list are different objects (due to the code bug), a valid '--attributes' or '--both' flag checked against keys[0] might fall through to the error branch if key_list[0] has already been modified.
Common situations: Misspelling a flag (e.g. '--atributes'); using a flag from a different version of the API; the keys/key_list variable inconsistency causing unexpected routing to the error branch.
Related errors
- port must be numeric
- address must be 'port' or 'host:port'
- Cannot convert '{}' to length
- {node} is not {err_msg}
- Address {address} is not in process {proc}
AI-assisted analysis of NationalSecurityAgency/ghidra@d5f144c24d (2026-08-14).
Data as JSON: /api/errors/28807593c8d68a16.
Report an issue: GitHub.