Repository: pwndbg/pwndbg

Issue:
Remove GDB<9.2 leftovers in config.py
We did a cleanup for GDB < 9.2 in the past in https://github.com/pwndbg/pwndbg/issues/1854 but it seems we missed some things in gdblib/config.py:
```
$ rg gte_
pwndbg/gdblib/config.py
52:    def __init_super_gdb_gte_9(self, param: pwndbg.lib.config.Parameter) -> None:
71:        self.__init_super_gdb_gte_9(param)
73:    init_super = __init_super_gdb_gte_9 if IS_GDB_GTE_9 else __init_super_gdb_lt_9
85:    def __get_set_string_gdb_gte_9(self) -> str:
117:        return self.__get_set_string_gdb_gte_9()
119:    get_set_string = __get_set_string_gdb_gte_9 if IS_GDB_GTE_9 else __get_set_string_gdb_le_9
121:    def __get_show_string_gdb_gte_9(self, svalue: str) -> str:
135:        return self.__get_show_string_gdb_gte_9(svalue)
137:    get_show_string = __get_show_string_gdb_gte_9 if IS_GDB_GTE_9 else __get_show_string_gdb_le_9
```

So yeah, this needs a cleanup/refactor since we don't support GDB below 9.2.


Discussion:
Taking this

Resolving patch:
diff --git a/pwndbg/gdblib/config.py b/pwndbg/gdblib/config.py
--- a/pwndbg/gdblib/config.py
+++ b/pwndbg/gdblib/config.py
@@ -26,13 +26,6 @@
 
 config = pwndbg.lib.config.Config()
 
-# GDB < 9 does not support PARAM_ZUINTEGER*, so we implement it by ourselves for consistency
-IS_GDB_GTE_9 = True
-if not hasattr(gdb, "PARAM_ZUINTEGER"):
-    gdb.PARAM_ZUINTEGER = "PARAM_ZUINTEGER"
-    gdb.PARAM_ZUINTEGER_UNLIMITED = "PARAM_ZUINTEGER_UNLIMITED"
-    IS_GDB_GTE_9 = False
-
 
 # See this for details about the API of `gdb.Parameter`:
 # https://sourceware.org/gdb/onlinedocs/gdb/Parameters-In-Python.html
@@ -49,7 +42,7 @@ def __init__(self, param: pwndbg.lib.config.Parameter) -> None:
         self.param = param
         self.value = param.value
 
-    def __init_super_gdb_gte_9(self, param: pwndbg.lib.config.Parameter) -> None:
+    def init_super(self, param: pwndbg.lib.config.Parameter) -> None:
         """Initializes the super class for GDB >= 9"""
         if param.param_class == gdb.PARAM_ENUM:
             super().__init__(
@@ -61,17 +54,6 @@ def __init_super_gdb_gte_9(self, param: pwndbg.lib.config.Parameter) -> None:
             return
         super().__init__(param.name, gdb.COMMAND_SUPPORT, param.param_class)
 
-    def __init_super_gdb_lt_9(self, param: pwndbg.lib.config.Parameter) -> None:
-        """Initializes the super class for GDB < 9"""
-        # GDB < 9 does not support PARAM_ZUINTEGER*, so we implement it by ourselves for consistency
-        if param.param_class in (gdb.PARAM_ZUINTEGER, gdb.PARAM_ZUINTEGER_UNLIMITED):
-            super().__init__(param.name, gdb.COMMAND_SUPPORT, pwndbg.lib.config.PARAM_CLASSES[int])
-            return
-        # the logic after this line is the same as GDB >= 9
-        self.__init_super_gdb_gte_9(param)
-
-    init_super = __init_super_gdb_gte_9 if IS_GDB_GTE_9 else __init_super_gdb_lt_9
-
     @property
     def native_value(self):
         return Parameter._value_to_gdb_native(self.param.value, param_class=self.param.param_class)
@@ -82,8 +64,8 @@ def native_default(self):
             self.param.default, param_class=self.param.param_class
         )
 
-    def __get_set_string_gdb_gte_9(self) -> str:
-        """Handles the GDB `set <param>` command for GDB >= 9"""
+    def get_set_string(self) -> str:
+        """Handles the GDB `set <param>`"""
         # GDB will set `self.value` to the user's input
         if self.value is None and self.param.param_class in (gdb.PARAM_UINTEGER, gdb.PARAM_INTEGER):
             # Note: This is really weird, according to GDB docs, 0 should mean "unlimited" for gdb.PARAM_UINTEGER and gdb.PARAM_INTEGER, but somehow GDB sets the value to `None` actually :/
@@ -104,22 +86,8 @@ def __get_set_string_gdb_gte_9(self) -> str:
 
         return f"Set {self.param.set_show_doc} to {self.native_value!r}."
 
-    def __get_set_string_gdb_le_9(self) -> str:
-        """Handles the GDB `set <param>` command for GDB < 9"""
-        if (self.param.param_class == gdb.PARAM_ZUINTEGER and self.value < 0) or (  # type: ignore[operator]
-            self.param.param_class == gdb.PARAM_ZUINTEGER_UNLIMITED and self.value < -1  # type: ignore[operator]
-        ):
-            # Restore the old value
-            self.value = self.param.value
-            # GDB < 9 is too buggy, it won't handle `gdb.GdbError`..., so we return a string here
-            return "integer %d out of range" % self.value  # type: ignore[str-format]
-        # the logic after this line is the same as GDB >= 9
-        return self.__get_set_string_gdb_gte_9()
-
-    get_set_string = __get_set_string_gdb_gte_9 if IS_GDB_GTE_9 else __get_set_string_gdb_le_9
-
-    def __get_show_string_gdb_gte_9(self, svalue: str) -> str:
-        """Handles the GDB `show <param>` command for GDB >= 9"""
+    def get_show_string(self, svalue: str) -> str:
+        """Handles the GDB `show <param>`"""
         more_information_hint = f" See `help set {self.param.name}` for more information."
         return "{} is {!r}.{}".format(
             self.param.set_show_doc.capitalize(),
@@ -127,15 +95,6 @@ def __get_show_string_gdb_gte_9(self, svalue: str) -> str:
             more_information_hint if self.__doc__ else "",
         )
 
-    def __get_show_string_gdb_le_9(self, svalue: str) -> str:
-        """Handles the GDB `show <param>` command for GDB < 9"""
-        if self.param.param_class == gdb.PARAM_ZUINTEGER_UNLIMITED and self.value == -1:
-            svalue = "unlimited"
-        # the logic after this line is the same as GDB >= 9
-        return self.__get_show_string_gdb_gte_9(svalue)
-
-    get_show_string = __get_show_string_gdb_gte_9 if IS_GDB_GTE_9 else __get_show_string_gdb_le_9
-
     @staticmethod
     def _value_to_gdb_native(value: Any, param_class: int | None = None) -> Any:
         """Translates Python value into native GDB syntax string."""


Test patch: