diff --git a/pwndbg/dbg/lldb/__init__.py b/pwndbg/dbg/lldb/__init__.py index 53a700ad1..d5b2f6a44 100644 --- a/pwndbg/dbg/lldb/__init__.py +++ b/pwndbg/dbg/lldb/__init__.py @@ -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( diff --git a/pwndbg/dbg/lldb/pset.py b/pwndbg/dbg/lldb/pset.py index d3c6fbd54..1bd67a0b2 100644 --- a/pwndbg/dbg/lldb/pset.py +++ b/pwndbg/dbg/lldb/pset.py @@ -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 diff --git a/pwndbg/dbg/lldb/repl/__init__.py b/pwndbg/dbg/lldb/repl/__init__.py index 322231d64..de6b5366d 100644 --- a/pwndbg/dbg/lldb/repl/__init__.py +++ b/pwndbg/dbg/lldb/repl/__init__.py @@ -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 ") + 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.