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:854-855) when the first token of the keys string starts with '--' but is not one of the recognized switches (--elements, --attributes, --both). The command accepts an optional leading switch to scope the retain operation; any other dash-prefixed token is rejected as an invalid argument.
Source
Thrown at Ghidra/Debug/Debugger-agent-dbgeng/src/main/py/src/ghidradbg/commands.py:855
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 exactly one of --elements, --attributes, --both as the optional first token, or omit the switch entirely.
- If a real key starts with '--', you must prefix the call with an explicit valid switch (e.g. '--elements --mykey').
- Check spelling: it is --attributes (plural), --elements (plural), --both.
Example fix
// before
ghidra_trace_retain_values('Processes[0]', '--element a b') # typo
// after
ghidra_trace_retain_values('Processes[0]', '--elements a b')
# or omit the switch:
ghidra_trace_retain_values('Processes[0]', 'a b')
# if a key literally starts with '--', force the switch:
ghidra_trace_retain_values('Processes[0]', '--both --mykey otherkey') Defensive patterns
Strategy: validation
Validate before calling
VALID_SWITCHES = {'--elements', '--attributes', '--both'}
def normalize_retain_keys(keys):
tokens = keys.split()
if tokens and tokens[0].startswith('--'):
if tokens[0] not in VALID_SWITCHES:
raise ValueError(f'invalid switch {tokens[0]!r}; use one of {VALID_SWITCHES}')
return keys
ghidra_trace_retain_values(path, normalize_retain_keys(keys)) Type guard
def retain_keys_well_formed(keys) -> bool:
tokens = keys.split()
if not tokens:
return True
if tokens[0].startswith('--'):
return tokens[0] in {'--elements', '--attributes', '--both'}
return True Try / catch
try:
ghidra_trace_retain_values(path, keys)
except RuntimeError as e:
if 'Invalid argument' in str(e):
# drop the bogus switch and retry, or prompt user
keys = ' '.join(t for t in keys.split() if not t.startswith('--'))
ghidra_trace_retain_values(path, keys)
else:
raise Prevention
- Spell switches exactly: --elements, --attributes, --both.
- If a key starts with '--', prefix the call with an explicit valid switch.
- Validate the first token in your wrapper before forwarding.
When it happens
Trigger: Calling ghidra_trace_retain_values(path, '--element key1') (typo, missing 's'); passing '--all' or any unsupported flag; passing a key name that legitimately starts with '--' without first emitting the required switch (the docstring notes the switch is then required to disambiguate).
Common situations: Typo in the switch name; key name colliding with the switch prefix; copy/paste from a different command's flag vocabulary.
Related errors
- Trace already started
- No transaction
- Transaction already started
- 'ghidra_trace_connect': missing required argument 'address'
- address must be in the form 'host:port'
AI-assisted analysis of NationalSecurityAgency/ghidra@d5f144c24d (2026-08-14).
Data as JSON: /api/errors/5ed02c70bbed4d85.
Report an issue: GitHub.