NationalSecurityAgency/ghidra · error · RuntimeError
Invalid argument: {key_list[0]}
Error message
Invalid argument: {key_list[0]} What it means
Raised by ghidra_trace_retain_values (commands.py:753-754) when the first token of the keys argument starts with '--' but is not one of the recognized switches (--elements, --attributes, --both). The command splits keys on spaces and inspects only key_list[0] for a switch; an unknown switch is rejected before retain_values is called.
Source
Thrown at Ghidra/Debug/Debugger-agent-x64dbg/src/main/py/src/ghidraxdbg/commands.py:754
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 key_list[0] == '--attributes':
kinds = 'attributes'
key_list = key_list[1:]
elif key_list[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(f"{object.id}\t{object.path}")
def ghidra_trace_get_values(pattern: str) -> None:
"""List all values matching a given path pattern."""
View on GitHub (pinned to d5f144c24d)
Solutions
- Use one of the valid switches: --elements, --attributes, --both, or omit the switch entirely (defaults to elements).
- If a key legitimately starts with '--', you must still pass a valid switch first (the docstring notes the switch is required in that case).
- Check for typos in the switch name against the command docstring.
Example fix
// before ghidra_trace_retain_values(path, '--all [0] [1]') // after ghidra_trace_retain_values(path, '--both [0] [1]')
Defensive patterns
Strategy: validation
Validate before calling
VALID_SWITCHES = {'--elements', '--attributes', '--both'}
def retain(path, keys):
first = keys.split(' ', 1)[0]
if first.startswith('--') and first not in VALID_SWITCHES:
raise ValueError(f'Unknown switch {first}; valid: {sorted(VALID_SWITCHES)}')
ghidra_trace_retain_values(path, keys) Type guard
def switch_is_valid(keys: str) -> bool:
first = keys.split(' ', 1)[0]
return not first.startswith('--') or first in {'--elements', '--attributes', '--both'} Try / catch
try:
ghidra_trace_retain_values(path, keys)
except RuntimeError as e:
if 'Invalid argument' in str(e):
# drop the bad switch and retry with default (elements)
ghidra_trace_retain_values(path, keys.split(' ', 1)[1] if ' ' in keys else '')
else:
raise Prevention
- Restrict switch input to the three documented values.
- If a key legitimately starts with '--', pass a valid switch first.
- Validate the first token before dispatching the command.
When it happens
Trigger: Calling the retain-values command with an unrecognized leading switch, e.g. keys='--all [0] [1]' or '--elems'. The first token begins with '--' and matches no case.
Common situations: Typing a switch name from memory (--all, --values) that does not exist; an older/newer agent version with different switch names; a script that interpolates an unintended '--' prefix into the keys.
Related errors
- 'ghidra_trace_connect': missing required argument 'address'
- Usage: ghidra trace retain-values [OPTIONS] PATH [KEYS...]
- Transaction already started
- address must be in the form 'host:port'
- port must be numeric
AI-assisted analysis of NationalSecurityAgency/ghidra@d5f144c24d (2026-08-14).
Data as JSON: /api/errors/b75fcf265d85667b.
Report an issue: GitHub.