]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
gdb/python: remove unused argument from builtin_disassemble
authorAndrew Burgess <aburgess@redhat.com>
Sat, 15 Mar 2025 12:03:50 +0000 (12:03 +0000)
committerAndrew Burgess <aburgess@redhat.com>
Sat, 15 Mar 2025 17:12:12 +0000 (17:12 +0000)
This commit:

  commit 15e15b2d9cd3b1db68f99cd3b047352142ddfd1c
  Date:   Fri Sep 17 18:12:34 2021 +0100

      gdb/python: implement the print_insn extension language hook

added the gdb.disassembler.builtin_disassemble Python API function.
By mistake, the implementation accepted two arguments, the second
being a "memory_source".

However, this second argument was never used, it was left over from an
earlier proposed version of the API.

Luckily, the only place the unused argument was documented was in the
NEWS file and in the output of `help(gdb.builtin_disassemble)`, and
neither of these locations really describe what the argument was, or
how it would be used.  The manual only describes the first (actually
used) argument, so I think we are safe enough to delete the unused
argument.

This allows some additional cleanup, with the store for the argument
also being deleted.

As the NEWS file did originally document the second argument, I have
added a NEWS entry to explain the argument has now been removed.

This could potentially break users code if they somehow decided to
pass a second argument, however, fixing things is as simple as
removing the second (unused) argument.

Approved-By: Simon Marchi <simon.marchi@efficios.com>
gdb/NEWS
gdb/python/py-disasm.c

index fae24d0cf617af822f1f18411b343d99bd5a5cea..e845ebfb5aaf37c8fe78a499cad6c23c2a6d37c5 100644 (file)
--- a/gdb/NEWS
+++ b/gdb/NEWS
@@ -51,6 +51,12 @@ show riscv numeric-register-names
   ** New constant gdb.PARAM_COLOR represents color type of a
      gdb.Parameter.value.  Parameter's value is gdb.Color instance.
 
+  ** The memory_source argument (the second argument) has been removed
+     from gdb.disassembler.builtin_disassemble.  This argument was
+     never used by GDB, and was added my mistake.  The only place this
+     argument was ever documented was in the NEWS file, the official
+     documentation never mentioned this argument.
+
 * Guile API
 
   ** New type <gdb:color> for dealing with colors.
index 66ed4563c461c03d300910f8b845de01206455b5..22d2ac7740d82b820ef37deb12c6e823b20e95bd 100644 (file)
@@ -133,7 +133,7 @@ static bool python_print_insn_enabled = false;
 struct gdbpy_disassembler : public gdb_disassemble_info
 {
   /* Constructor.  */
-  gdbpy_disassembler (disasm_info_object *obj, PyObject *memory_source);
+  gdbpy_disassembler (disasm_info_object *obj);
 
   /* Get the DisassembleInfo object pointer.  */
   disasm_info_object *
@@ -222,11 +222,6 @@ private:
      address of the memory error is stored in here.  */
   std::optional<CORE_ADDR> m_memory_error_address;
 
-  /* When the user calls the builtin_disassemble function, if they pass a
-     memory source object then a pointer to the object is placed in here,
-     otherwise, this field is nullptr.  */
-  PyObject *m_memory_source;
-
   /* Move the exception EX into this disassembler object.  */
   void store_exception (gdbpy_err_fetch &&ex)
   {
@@ -539,18 +534,17 @@ disasmpy_init_disassembler_result (disasm_result_object *obj, int length,
 static PyObject *
 disasmpy_builtin_disassemble (PyObject *self, PyObject *args, PyObject *kw)
 {
-  PyObject *info_obj, *memory_source_obj = nullptr;
-  static const char *keywords[] = { "info", "memory_source", nullptr };
-  if (!gdb_PyArg_ParseTupleAndKeywords (args, kw, "O!|O", keywords,
-                                       &disasm_info_object_type, &info_obj,
-                                       &memory_source_obj))
+  PyObject *info_obj;
+  static const char *keywords[] = { "info", nullptr };
+  if (!gdb_PyArg_ParseTupleAndKeywords (args, kw, "O!", keywords,
+                                       &disasm_info_object_type, &info_obj))
     return nullptr;
 
   disasm_info_object *disasm_info = (disasm_info_object *) info_obj;
   DISASMPY_DISASM_INFO_REQUIRE_VALID (disasm_info);
 
   /* Where the result will be written.  */
-  gdbpy_disassembler disassembler (disasm_info, memory_source_obj);
+  gdbpy_disassembler disassembler (disasm_info);
 
   /* Now actually perform the disassembly.  LENGTH is set to the length of
      the disassembled instruction, or -1 if there was a memory-error
@@ -1139,16 +1133,14 @@ gdbpy_disassembler::print_address_func (bfd_vma addr,
 
 /* constructor.  */
 
-gdbpy_disassembler::gdbpy_disassembler (disasm_info_object *obj,
-                                       PyObject *memory_source)
+gdbpy_disassembler::gdbpy_disassembler (disasm_info_object *obj)
   : gdb_disassemble_info (obj->gdbarch,
                          read_memory_func,
                          memory_error_func,
                          print_address_func,
                          fprintf_func,
                          fprintf_styled_func),
-    m_disasm_info_object (obj),
-    m_memory_source (memory_source)
+    m_disasm_info_object (obj)
 { /* Nothing.  */ }
 
 /* A wrapper around a reference to a Python DisassembleInfo object, which
@@ -1610,10 +1602,9 @@ PyMethodDef python_disassembler_methods[] =
 {
   { "builtin_disassemble", (PyCFunction) disasmpy_builtin_disassemble,
     METH_VARARGS | METH_KEYWORDS,
-    "builtin_disassemble (INFO, MEMORY_SOURCE = None) -> None\n\
+    "builtin_disassemble (INFO) -> None\n\
 Disassemble using GDB's builtin disassembler.  INFO is an instance of\n\
-gdb.disassembler.DisassembleInfo.  The MEMORY_SOURCE, if not None, should\n\
-be an object with the read_memory method." },
+gdb.disassembler.DisassembleInfo." },
   { "_set_enabled", (PyCFunction) disasmpy_set_enabled,
     METH_VARARGS | METH_KEYWORDS,
     "_set_enabled (STATE) -> None\n\