gdb/python: remove unused argument from builtin_disassemble

This commit:

  commit 15e15b2d9c
  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>
This commit is contained in:
Andrew Burgess
2025-03-15 12:03:50 +00:00
parent 8bfe8a6bfd
commit d21f28a067
2 changed files with 16 additions and 19 deletions

View File

@@ -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.

View 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\