Remove `pset` as a command and replace it with the `set` LLDB Pwndbg CLI command override (#2525)

* Remove `pset` as a command and replace it with the `set` Pwndbg CLI pseudo-command

* Add warning for mistaken uses of `set` as an alias for `settings`

* Update pwndbg/dbg/lldb/pset.py

Co-authored-by: Disconnect3d <dominik.b.czarnota@gmail.com>

* Update pset.py

---------

Co-authored-by: Disconnect3d <dominik.b.czarnota@gmail.com>
pull/2541/head
Matt. 1 year ago committed by GitHub
parent 1bafe22ae1
commit 4e30fdeb75
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -1491,7 +1491,6 @@ class LLDB(pwndbg.dbg_mod.Debugger):
pwndbg.commands.comments.init()
import pwndbg.dbg.lldb.hooks
import pwndbg.dbg.lldb.pset
@override
def add_command(

@ -1,6 +1,5 @@
from __future__ import annotations
import argparse
from typing import Any
import pwndbg
@ -8,39 +7,29 @@ import pwndbg.color.message as message
import pwndbg.commands
import pwndbg.lib.config as cfg
parser = argparse.ArgumentParser(description="Changes a Pwndbg setting.")
parser.add_argument(
"name",
type=str,
default=None,
help="Name of the setting to be changed",
)
parser.add_argument(
"value",
type=str,
default=None,
help="Value to change the setting into",
)
@pwndbg.commands.ArgparsedCommand(parser)
def pset(name, value):
def pset(name: str, value: str) -> bool:
"""
Parses and sets a Pwndbg configuration value.
"""
name = name.replace("-", "_")
if name not in pwndbg.config.params:
print(message.error(f"Unknown setting '{name}'"))
return
return False
param = pwndbg.config.params[name]
try:
new_value = parse_value(param, value)
except InvalidParse:
print(message.error("Invalid value '{value}' for setting '{name}': {e.message}"))
return
except InvalidParse as e:
print(message.error(f"Invalid value '{value}' for setting '{name}': {e}"))
return False
param.value = new_value
for trigger in pwndbg.config.triggers[param.name]:
trigger()
return True
class InvalidParse(Exception):
pass

@ -53,6 +53,7 @@ import pwndbg.dbg.lldb
from pwndbg.color import message
from pwndbg.dbg import EventType
from pwndbg.dbg.lldb import LLDB
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
from pwndbg.dbg.lldb.repl.proc import EventHandler
@ -341,6 +342,32 @@ def run(startup: List[str] | None = None, debug: bool = False) -> None:
gdb_remote(driver, relay, bits[1:], dbg)
continue
if bits[0] == "set":
# We handle `set` as a command override. We do this so that users
# may change Pwndbg-specific settings in the same way that they
# would in GDB Pwndbg.
#
# The alternatives to this are either (1) use a proper command,
# but that requires the process to already be running, and needs us
# to use a name other than "set", or (2) add our settings to the
# standard debugger settings mechanism, like we do in GDB, but LLDB
# doesn't support that.
warn = False
if len(bits) != 3:
print("Usage: set <name> <value>")
warn = True
else:
warn = not pset(bits[1], bits[2])
if warn:
print(
message.warn(
"The 'set' command is used exclusively for Pwndbg settings. If you meant to change LLDB settings, use the fully spelled-out 'settings' command, instead."
)
)
continue
# The command hasn't matched any of our filtered commands, just let LLDB
# handle it normally. Either in the context of the process, if we have
# one, or just in a general context.

Loading…
Cancel
Save