Add `help set` to LLDB Pwndbg (#3068)

* Add `help set` to LLDB

* Change documentation to reflect it
pull/3074/head
Matt. 6 months ago committed by GitHub
parent 8a93b2b258
commit 8c8f886666
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -76,7 +76,7 @@ bn-autosync whether to automatically run bn-sync every st
```
Because of the various contexts in which a parameter can be show, the first letter of the `set_show_doc` string should be lowercase (unless the first word is a name or an abbreviation) and there should be no punctuation at the end. This way, Pwndbg and GDB can more easily modify the string to fit it into these contexts.
## help_docstring
While `help_docstring` is not mandatory, it is highly recommended to use it. Put a detailed explanation of what the parameter does here, and explain any caveats. This string does not have a size limit and is shown with the following command in GDB:
While `help_docstring` is not mandatory, it is highly recommended to use it. Put a detailed explanation of what the parameter does here, and explain any caveats. This string does not have a size limit and is shown with the following command in GDB and LLDB:
```text
pwndbg> help set gdb-workaround-stop-event
Set asynchronous stop events to improve 'commands' functionality.
@ -92,8 +92,6 @@ Default: 'disabled'
Valid values: 'disabled', 'disabled-deadlock', 'enabled'
```
Note that the last two lines are automatically generated by Pwndbg.
!!! note
There is currently no way to display this string nor the `set_show_doc` string in LLDB.
When writing this explanation, it is important to take into account how it will be displayed [in the documentation](https://pwndbg.re/pwndbg/dev/configuration/) after being parsed as markdown. See what `gdb-workaround-stop-event` looks like here: https://pwndbg.re/pwndbg/dev/configuration/config/#gdb-workaround-stop-event . If there wasn't an empty line between `Values explained:` and ``+ `disabled`..`` the list wouldn't have rendered properly.
## param_class

@ -71,7 +71,9 @@ parser.add_argument(
)
def display_config(filter_pattern: str, scope: Scope, has_file_command: bool = True) -> None:
def display_config(
filter_pattern: str, scope: Scope, has_file_command: bool = True, show_hints: bool = True
) -> None:
values = get_config_parameters(scope, filter_pattern)
if not values:
@ -97,18 +99,19 @@ def display_config(filter_pattern: str, scope: Scope, has_file_command: bool = T
print_row(v.name, value, default, v.set_show_doc, longest_optname, longest_doc)
print(
hint(
f"You can set a {scope.name} variable with `set <{scope.name}-var> <value>`, and read more about it with `help set <{scope.name}-var>`."
)
)
if has_file_command:
if show_hints:
print(
hint(
f"You can generate a configuration file using `{scope.name}file` "
"- then put it in your .gdbinit after initializing pwndbg."
f"You can set a {scope.name} variable with `set <{scope.name}-var> <value>`, and read more about it with `help set <{scope.name}-var>`."
)
)
if has_file_command:
print(
hint(
f"You can generate a configuration file using `{scope.name}file` "
"- then put it in your .gdbinit after initializing pwndbg."
)
)
@pwndbg.commands.Command(parser, category=CommandCategory.PWNDBG)

@ -1,6 +1,7 @@
from __future__ import annotations
from typing import Any
from typing import Optional
import pwndbg
import pwndbg.color.message as message
@ -8,16 +9,22 @@ import pwndbg.commands
import pwndbg.lib.config as cfg
def pget(name: str) -> Optional[pwndbg.lib.config.Parameter]:
"""
Retrieves a parameter with a given name.
"""
return pwndbg.config.params.get(name.replace("-", "_"))
def pset(name: str, value: str) -> bool:
"""
Parses and sets a Pwndbg configuration value.
"""
name = name.replace("-", "_")
if name not in pwndbg.config.params:
param = pget(name)
if param is None:
print(message.error(f"Unknown setting '{name}'"))
return False
param = pwndbg.config.params[name]
try:
new_value = parse_value(param, value)
except InvalidParse as e:

@ -62,6 +62,7 @@ from pwndbg.color import message
from pwndbg.dbg import EventType
from pwndbg.dbg.lldb import LLDB
from pwndbg.dbg.lldb import OneShotAwaitable
from pwndbg.dbg.lldb.pset import pget
from pwndbg.dbg.lldb.pset import pset
from pwndbg.dbg.lldb.repl.io import IODriver
from pwndbg.dbg.lldb.repl.io import get_io_driver
@ -517,6 +518,52 @@ def exec_repl_command(
return True
if (
(bits[0] == "h" or (bits[0].startswith("hel") and "help".startswith(bits[0])))
and len(bits) >= 2
and bits[1] == "set"
):
# This is 'help set'
#
# We override this command to provide help for the 'set' command
# override.
warn = False
if len(bits) > 3:
print("Usage: help set [name]")
warn = True
elif len(bits) == 2:
# In LLDB style, list all valid settings.
print("Set a Pwndbg configuration parameter.")
print()
print("Syntax: set <name> <value>")
for scope in pwndbg.lib.config.Scope:
print()
print(f"Configuration parameters - {scope._name_}:")
pwndbg.commands.config.display_config(
"", pwndbg.lib.config.Scope.config, show_hints=False
)
else:
# Show information about a single parameter.
param = pget(bits[2])
if param is None:
warn = True
else:
print(f"Set {param.set_show_doc}.")
print()
print(f"Syntax: set {param.name} <value>")
print()
if param.help_docstring:
print(param.help_docstring)
if warn:
print(
message.warn(
"The 'set' command is used exclusively for Pwndbg settings. If you meant to see help for LLDB settings, use the fully spelled-out 'settings' command, instead."
)
)
return True
if bits[0] == "ipi":
# Spawn IPython shell, easy for debugging
run_ipython_shell()

Loading…
Cancel
Save