Remove Python API checker defines

The GCC plugin that implements the Python API checker does not appear
to really be maintained.  And, as far as I know, it never really
worked for C++ code anyway.  Considering those factors, and that no
one has tried to run it in years, I think it's time to remove the
macros from the gdb source.

Approved-By: Simon Marchi <simon.marchi@efficios.com>
This commit is contained in:
Tom Tromey
2025-10-21 10:00:20 -06:00
parent f20c97f00d
commit 8eeb52e3c7
38 changed files with 117 additions and 198 deletions

View File

@@ -42,8 +42,7 @@ static const registry<gdbarch>::key<PyObject, gdb::noop_deleter<PyObject>>
} \ } \
} while (0) } while (0)
extern PyTypeObject arch_object_type extern PyTypeObject arch_object_type;
CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("arch_object");
/* Associates an arch_object with GDBARCH as gdbarch_data via the gdbarch /* Associates an arch_object with GDBARCH as gdbarch_data via the gdbarch
post init registration mechanism (gdbarch_data_register_post_init). */ post init registration mechanism (gdbarch_data_register_post_init). */
@@ -368,8 +367,8 @@ gdbpy_all_architecture_names (PyObject *self, PyObject *args)
/* Initializes the Architecture class in the gdb module. */ /* Initializes the Architecture class in the gdb module. */
static int CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION static int
gdbpy_initialize_arch (void) gdbpy_initialize_arch ()
{ {
arch_object_type.tp_new = PyType_GenericNew; arch_object_type.tp_new = PyType_GenericNew;
return gdbpy_type_ready (&arch_object_type); return gdbpy_type_ready (&arch_object_type);

View File

@@ -56,8 +56,8 @@ info_auto_load_python_scripts (const char *pattern, int from_tty)
&extension_language_python); &extension_language_python);
} }
static int CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION static int
gdbpy_initialize_auto_load (void) gdbpy_initialize_auto_load ()
{ {
add_setshow_boolean_cmd ("python-scripts", class_support, add_setshow_boolean_cmd ("python-scripts", class_support,
&auto_load_python_scripts, _("\ &auto_load_python_scripts, _("\

View File

@@ -72,8 +72,7 @@ struct block_syms_iterator_object {
} \ } \
} while (0) } while (0)
extern PyTypeObject block_syms_iterator_object_type extern PyTypeObject block_syms_iterator_object_type;
CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("block_syms_iterator_object");
static const registry<objfile>::key<htab, htab_deleter> static const registry<objfile>::key<htab, htab_deleter>
blpy_objfile_data_key; blpy_objfile_data_key;
@@ -523,8 +522,8 @@ blpy_richcompare (PyObject *self, PyObject *other, int op)
return PyBool_FromLong (equal == expected); return PyBool_FromLong (equal == expected);
} }
static int CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION static int
gdbpy_initialize_blocks (void) gdbpy_initialize_blocks ()
{ {
block_object_type.tp_new = PyType_GenericNew; block_object_type.tp_new = PyType_GenericNew;
if (gdbpy_type_ready (&block_object_type) < 0) if (gdbpy_type_ready (&block_object_type) < 0)

View File

@@ -35,8 +35,7 @@
#include "linespec.h" #include "linespec.h"
#include "gdbsupport/common-utils.h" #include "gdbsupport/common-utils.h"
extern PyTypeObject breakpoint_location_object_type extern PyTypeObject breakpoint_location_object_type;
CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("breakpoint_location_object");
struct gdbpy_breakpoint_location_object struct gdbpy_breakpoint_location_object
{ {
@@ -1353,8 +1352,8 @@ gdbpy_breakpoint_modified (struct breakpoint *b)
/* Initialize the Python breakpoint code. */ /* Initialize the Python breakpoint code. */
static int CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION static int
gdbpy_initialize_breakpoints (void) gdbpy_initialize_breakpoints ()
{ {
int i; int i;
@@ -1389,7 +1388,7 @@ gdbpy_initialize_breakpoints (void)
/* Initialize the Python BreakpointLocation code. */ /* Initialize the Python BreakpointLocation code. */
static int CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION static int
gdbpy_initialize_breakpoint_locations () gdbpy_initialize_breakpoint_locations ()
{ {
return gdbpy_type_ready (&breakpoint_location_object_type); return gdbpy_type_ready (&breakpoint_location_object_type);

View File

@@ -65,8 +65,7 @@ struct cmdpy_object
struct cmd_list_element *sub_list; struct cmd_list_element *sub_list;
}; };
extern PyTypeObject cmdpy_object_type extern PyTypeObject cmdpy_object_type;
CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("cmdpy_object");
/* Constants used by this module. */ /* Constants used by this module. */
static PyObject *invoke_cst; static PyObject *invoke_cst;
@@ -595,8 +594,8 @@ cmdpy_init (PyObject *self, PyObject *args, PyObject *kw)
/* Initialize the 'commands' code. */ /* Initialize the 'commands' code. */
static int CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION static int
gdbpy_initialize_commands (void) gdbpy_initialize_commands ()
{ {
int i; int i;

View File

@@ -44,11 +44,9 @@ struct connection_object
struct process_stratum_target *target; struct process_stratum_target *target;
}; };
extern PyTypeObject connection_object_type extern PyTypeObject connection_object_type;
CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("connection_object");
extern PyTypeObject remote_connection_object_type extern PyTypeObject remote_connection_object_type;
CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("remote_connection_object");
/* Require that CONNECTION be valid. */ /* Require that CONNECTION be valid. */
#define CONNPY_REQUIRE_VALID(connection) \ #define CONNPY_REQUIRE_VALID(connection) \
@@ -283,8 +281,8 @@ connpy_get_connection_details (PyObject *self, void *closure)
/* Python specific initialization for this file. */ /* Python specific initialization for this file. */
static int CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION static int
gdbpy_initialize_connection (void) gdbpy_initialize_connection ()
{ {
if (gdbpy_type_ready (&connection_object_type) < 0) if (gdbpy_type_ready (&connection_object_type) < 0)
return -1; return -1;

View File

@@ -47,8 +47,7 @@ struct corefile_object
PyObject *mapped_files; PyObject *mapped_files;
}; };
extern PyTypeObject corefile_object_type extern PyTypeObject corefile_object_type;
CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("corefile_object");
/* A gdb.CorefileMapped object. */ /* A gdb.CorefileMapped object. */
@@ -73,8 +72,7 @@ struct corefile_mapped_file_object
bool is_main_exec_p; bool is_main_exec_p;
}; };
extern PyTypeObject corefile_mapped_file_object_type extern PyTypeObject corefile_mapped_file_object_type;
CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("corefile_mapped_file_object");
/* A gdb.CorefileMappedFileRegion object. */ /* A gdb.CorefileMappedFileRegion object. */
@@ -91,8 +89,7 @@ struct corefile_mapped_file_region_object
ULONGEST file_offset; ULONGEST file_offset;
}; };
extern PyTypeObject corefile_mapped_file_region_object_type extern PyTypeObject corefile_mapped_file_region_object_type;
CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("corefile_mapped_file_region_object");
/* Clear the inferior pointer in a Corefile object OBJ when an inferior is /* Clear the inferior pointer in a Corefile object OBJ when an inferior is
deleted. */ deleted. */

View File

@@ -52,8 +52,7 @@ struct disasm_info_object
struct disasm_info_object *next; struct disasm_info_object *next;
}; };
extern PyTypeObject disasm_info_object_type extern PyTypeObject disasm_info_object_type;
CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("disasm_info_object");
/* Implement gdb.disassembler.DisassembleAddressPart type. An object of /* Implement gdb.disassembler.DisassembleAddressPart type. An object of
this type represents a small part of a disassembled instruction; a part this type represents a small part of a disassembled instruction; a part
@@ -74,8 +73,7 @@ struct disasm_addr_part_object
struct gdbarch *gdbarch; struct gdbarch *gdbarch;
}; };
extern PyTypeObject disasm_addr_part_object_type extern PyTypeObject disasm_addr_part_object_type;
CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("disasm_addr_part_object");
/* Implement gdb.disassembler.DisassembleTextPart type. An object of /* Implement gdb.disassembler.DisassembleTextPart type. An object of
this type represents a small part of a disassembled instruction; a part this type represents a small part of a disassembled instruction; a part
@@ -92,11 +90,9 @@ struct disasm_text_part_object
enum disassembler_style style; enum disassembler_style style;
}; };
extern PyTypeObject disasm_text_part_object_type extern PyTypeObject disasm_text_part_object_type;
CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("disasm_text_part_object");
extern PyTypeObject disasm_part_object_type extern PyTypeObject disasm_part_object_type;
CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("PyObject");
/* Implement gdb.disassembler.DisassemblerResult type, an object that holds /* Implement gdb.disassembler.DisassemblerResult type, an object that holds
the result of calling the disassembler. This is mostly the length of the result of calling the disassembler. This is mostly the length of
@@ -115,8 +111,7 @@ struct disasm_result_object
std::vector<gdbpy_ref<>> *parts; std::vector<gdbpy_ref<>> *parts;
}; };
extern PyTypeObject disasm_result_object_type extern PyTypeObject disasm_result_object_type;
CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("disasm_result_object");
/* When this is false we fast path out of gdbpy_print_insn, which should /* When this is false we fast path out of gdbpy_print_insn, which should
keep the performance impact of the Python disassembler down. This is keep the performance impact of the Python disassembler down. This is
@@ -1627,7 +1622,7 @@ static struct PyModuleDef python_disassembler_module_def =
/* Called to initialize the Python structures in this file. */ /* Called to initialize the Python structures in this file. */
static int CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION static int
gdbpy_initialize_disasm () gdbpy_initialize_disasm ()
{ {
/* Create the _gdb.disassembler module, and add it to the _gdb module. */ /* Create the _gdb.disassembler module, and add it to the _gdb module. */

View File

@@ -53,8 +53,8 @@ evpy_add_attribute (PyObject *event, const char *name, PyObject *attr)
/* Initialize the Python event code. */ /* Initialize the Python event code. */
static int CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION static int
gdbpy_initialize_event (void) gdbpy_initialize_event ()
{ {
return gdbpy_type_ready (&event_object_type); return gdbpy_type_ready (&event_object_type);
} }

View File

@@ -27,8 +27,7 @@
/* Declare all event types. */ /* Declare all event types. */
#define GDB_PY_DEFINE_EVENT_TYPE(name, py_name, doc, base) \ #define GDB_PY_DEFINE_EVENT_TYPE(name, py_name, doc, base) \
extern PyTypeObject name##_event_object_type \ extern PyTypeObject name##_event_object_type;
CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("event_object");
#include "py-event-types.def" #include "py-event-types.def"
#undef GDB_PY_DEFINE_EVENT_TYPE #undef GDB_PY_DEFINE_EVENT_TYPE
@@ -82,7 +81,6 @@ extern int emit_clear_objfiles_event (program_space *pspace);
extern void evpy_dealloc (PyObject *self); extern void evpy_dealloc (PyObject *self);
extern int evpy_add_attribute (PyObject *event, extern int evpy_add_attribute (PyObject *event,
const char *name, PyObject *attr) const char *name, PyObject *attr);
CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION;
#endif /* GDB_PYTHON_PY_EVENT_H */ #endif /* GDB_PYTHON_PY_EVENT_H */

View File

@@ -22,8 +22,7 @@
events_object gdb_py_events; events_object gdb_py_events;
extern PyTypeObject eventregistry_object_type extern PyTypeObject eventregistry_object_type;
CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("eventregistry_object");
/* Implementation of EventRegistry.connect () -> NULL. /* Implementation of EventRegistry.connect () -> NULL.
Add FUNCTION to the list of listeners. */ Add FUNCTION to the list of listeners. */
@@ -101,8 +100,8 @@ evregpy_dealloc (PyObject *self)
/* Initialize the Python event registry code. */ /* Initialize the Python event registry code. */
static int CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION static int
gdbpy_initialize_eventregistry (void) gdbpy_initialize_eventregistry ()
{ {
return gdbpy_type_ready (&eventregistry_object_type); return gdbpy_type_ready (&eventregistry_object_type);
} }

View File

@@ -35,7 +35,7 @@ static struct PyModuleDef EventModuleDef =
/* Helper function to add a single event registry to the events /* Helper function to add a single event registry to the events
module. */ module. */
static int CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION static int
add_new_registry (eventregistry_object **registryp, const char *name) add_new_registry (eventregistry_object **registryp, const char *name)
{ {
*registryp = create_eventregistry_object (); *registryp = create_eventregistry_object ();

View File

@@ -61,8 +61,7 @@ struct finish_breakpoint_object
struct frame_id initiating_frame; struct frame_id initiating_frame;
}; };
extern PyTypeObject finish_breakpoint_object_type extern PyTypeObject finish_breakpoint_object_type;
CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("finish_breakpoint_object");
/* Python function to get the 'return_value' attribute of /* Python function to get the 'return_value' attribute of
FinishBreakpoint. */ FinishBreakpoint. */
@@ -433,8 +432,8 @@ bpfinishpy_handle_exit (struct inferior *inf)
/* Initialize the Python finish breakpoint code. */ /* Initialize the Python finish breakpoint code. */
static int CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION static int
gdbpy_initialize_finishbreakpoints (void) gdbpy_initialize_finishbreakpoints ()
{ {
if (!gdbpy_breakpoint_init_breakpoint_type ()) if (!gdbpy_breakpoint_init_breakpoint_type ())
return -1; return -1;

View File

@@ -757,8 +757,8 @@ frapy_richcompare (PyObject *self, PyObject *other, int op)
/* Sets up the Frame API in the gdb module. */ /* Sets up the Frame API in the gdb module. */
static int CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION static int
gdbpy_initialize_frames (void) gdbpy_initialize_frames ()
{ {
frame_object_type.tp_new = PyType_GenericNew; frame_object_type.tp_new = PyType_GenericNew;
if (gdbpy_type_ready (&frame_object_type) < 0) if (gdbpy_type_ready (&frame_object_type) < 0)

View File

@@ -27,8 +27,7 @@
#include "expression.h" #include "expression.h"
#include "language.h" #include "language.h"
extern PyTypeObject fnpy_object_type extern PyTypeObject fnpy_object_type;
CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("PyObject");
@@ -135,8 +134,8 @@ fnpy_init (PyObject *self, PyObject *args, PyObject *kwds)
/* Initialize internal function support. */ /* Initialize internal function support. */
static int CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION static int
gdbpy_initialize_functions (void) gdbpy_initialize_functions ()
{ {
fnpy_object_type.tp_new = PyType_GenericNew; fnpy_object_type.tp_new = PyType_GenericNew;
return gdbpy_type_ready (&fnpy_object_type); return gdbpy_type_ready (&fnpy_object_type);

View File

@@ -82,8 +82,8 @@ gdbpy_readline_wrapper (FILE *sys_stdin, FILE *sys_stdout,
/* Initialize Python readline support. */ /* Initialize Python readline support. */
static int CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION static int
gdbpy_initialize_gdb_readline (void) gdbpy_initialize_gdb_readline ()
{ {
/* Python's readline module conflicts with GDB's use of readline /* Python's readline module conflicts with GDB's use of readline
since readline is not reentrant. Ideally, a reentrant wrapper to since readline is not reentrant. Ideally, a reentrant wrapper to

View File

@@ -51,8 +51,7 @@ struct inferior_object
PyObject *dict; PyObject *dict;
}; };
extern PyTypeObject inferior_object_type extern PyTypeObject inferior_object_type;
CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("inferior_object");
/* Deleter to clean up when an inferior is removed. */ /* Deleter to clean up when an inferior is removed. */
struct infpy_deleter struct infpy_deleter
@@ -1022,8 +1021,8 @@ gdbpy_selected_inferior (PyObject *self, PyObject *args)
inferior_to_inferior_object (current_inferior ()).release ()); inferior_to_inferior_object (current_inferior ()).release ());
} }
static int CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION static int
gdbpy_initialize_inferior (void) gdbpy_initialize_inferior ()
{ {
if (gdbpy_type_ready (&inferior_object_type) < 0) if (gdbpy_type_ready (&inferior_object_type) < 0)
return -1; return -1;

View File

@@ -21,8 +21,7 @@
#include "inferior.h" #include "inferior.h"
#include "python-internal.h" #include "python-internal.h"
extern PyTypeObject thread_object_type extern PyTypeObject thread_object_type;
CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("thread_object");
/* Require that INFERIOR be a valid inferior ID. */ /* Require that INFERIOR be a valid inferior ID. */
#define THPY_REQUIRE_VALID(Thread) \ #define THPY_REQUIRE_VALID(Thread) \
@@ -404,8 +403,8 @@ gdbpy_selected_thread (PyObject *self, PyObject *args)
Py_RETURN_NONE; Py_RETURN_NONE;
} }
static int CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION static int
gdbpy_initialize_thread (void) gdbpy_initialize_thread ()
{ {
return gdbpy_type_ready (&thread_object_type); return gdbpy_type_ready (&thread_object_type);
} }

View File

@@ -80,8 +80,8 @@ py_insn_get_insn_type ()
/* Sets up the gdb.Instruction type. */ /* Sets up the gdb.Instruction type. */
static int CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION static int
gdbpy_initialize_instruction (void) gdbpy_initialize_instruction ()
{ {
if (py_insn_get_insn_type () == nullptr) if (py_insn_get_insn_type () == nullptr)
return -1; return -1;

View File

@@ -52,8 +52,7 @@ struct lazy_string_object {
PyObject *type; PyObject *type;
}; };
extern PyTypeObject lazy_string_object_type extern PyTypeObject lazy_string_object_type;
CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("lazy_string_object");
static PyObject * static PyObject *
stpy_get_address (PyObject *self, void *closure) stpy_get_address (PyObject *self, void *closure)
@@ -242,8 +241,8 @@ gdbpy_create_lazy_string_object (CORE_ADDR address, long length,
return (PyObject *) str_obj; return (PyObject *) str_obj;
} }
static int CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION static int
gdbpy_initialize_lazy_string (void) gdbpy_initialize_lazy_string ()
{ {
return gdbpy_type_ready (&lazy_string_object_type); return gdbpy_type_ready (&lazy_string_object_type);
} }

View File

@@ -27,8 +27,7 @@ struct linetable_entry_object {
CORE_ADDR pc; CORE_ADDR pc;
}; };
extern PyTypeObject linetable_entry_object_type extern PyTypeObject linetable_entry_object_type;
CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("linetable_entry_object");
struct linetable_object { struct linetable_object {
PyObject_HEAD PyObject_HEAD
@@ -38,8 +37,7 @@ struct linetable_object {
PyObject *symtab; PyObject *symtab;
}; };
extern PyTypeObject linetable_object_type extern PyTypeObject linetable_object_type;
CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("linetable_object");
struct ltpy_iterator_object { struct ltpy_iterator_object {
PyObject_HEAD PyObject_HEAD
@@ -51,8 +49,7 @@ struct ltpy_iterator_object {
PyObject *source; PyObject *source;
}; };
extern PyTypeObject ltpy_iterator_object_type extern PyTypeObject ltpy_iterator_object_type;
CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("ltpy_iterator_object");
/* Internal helper function to extract gdb.Symtab from a gdb.LineTable /* Internal helper function to extract gdb.Symtab from a gdb.LineTable
object. */ object. */
@@ -284,8 +281,8 @@ ltpy_dealloc (PyObject *self)
/* Initialize LineTable, LineTableEntry and LineTableIterator /* Initialize LineTable, LineTableEntry and LineTableIterator
objects. */ objects. */
static int CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION static int
gdbpy_initialize_linetable (void) gdbpy_initialize_linetable ()
{ {
if (gdbpy_type_ready (&linetable_object_type) < 0) if (gdbpy_type_ready (&linetable_object_type) < 0)
return -1; return -1;

View File

@@ -32,8 +32,7 @@ struct membuf_object {
CORE_ADDR length; CORE_ADDR length;
}; };
extern PyTypeObject membuf_object_type extern PyTypeObject membuf_object_type;
CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("membuf_object");
/* Wrap BUFFER, ADDRESS, and LENGTH into a gdb.Membuf object. ADDRESS is /* Wrap BUFFER, ADDRESS, and LENGTH into a gdb.Membuf object. ADDRESS is
the address within the inferior that the contents of BUFFER were read, the address within the inferior that the contents of BUFFER were read,
@@ -98,8 +97,8 @@ get_buffer (PyObject *self, Py_buffer *buf, int flags)
/* General Python initialization callback. */ /* General Python initialization callback. */
static int CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION static int
gdbpy_initialize_membuf (void) gdbpy_initialize_membuf ()
{ {
membuf_object_type.tp_new = PyType_GenericNew; membuf_object_type.tp_new = PyType_GenericNew;
return gdbpy_type_ready (&membuf_object_type); return gdbpy_type_ready (&membuf_object_type);

View File

@@ -165,8 +165,7 @@ private:
using mi_command_py_up = std::unique_ptr<mi_command_py>; using mi_command_py_up = std::unique_ptr<mi_command_py>;
extern PyTypeObject micmdpy_object_type extern PyTypeObject micmdpy_object_type;
CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("micmdpy_object");
/* Holds a Python object containing the string 'invoke'. */ /* Holds a Python object containing the string 'invoke'. */
@@ -443,7 +442,7 @@ micmdpy_dealloc (PyObject *obj)
/* Python initialization for the MI commands components. */ /* Python initialization for the MI commands components. */
static int CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION static int
gdbpy_initialize_micommands () gdbpy_initialize_micommands ()
{ {
micmdpy_object_type.tp_new = PyType_GenericNew; micmdpy_object_type.tp_new = PyType_GenericNew;

View File

@@ -53,8 +53,7 @@ struct objfile_object
PyObject *xmethods; PyObject *xmethods;
}; };
extern PyTypeObject objfile_object_type extern PyTypeObject objfile_object_type;
CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("objfile_object");
/* Clear the OBJFILE pointer in an Objfile object and remove the /* Clear the OBJFILE pointer in an Objfile object and remove the
reference. */ reference. */
@@ -704,8 +703,8 @@ objfile_to_objfile_object (struct objfile *objfile)
return gdbpy_ref<>::new_reference (result); return gdbpy_ref<>::new_reference (result);
} }
static int CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION static int
gdbpy_initialize_objfile (void) gdbpy_initialize_objfile ()
{ {
return gdbpy_type_ready (&objfile_object_type); return gdbpy_type_ready (&objfile_object_type);
} }

View File

@@ -170,8 +170,7 @@ make_setting (parmpy_object *s)
gdb_assert_not_reached ("unhandled var type"); gdb_assert_not_reached ("unhandled var type");
} }
extern PyTypeObject parmpy_object_type extern PyTypeObject parmpy_object_type;
CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("parmpy_object");
/* Some handy string constants. */ /* Some handy string constants. */
static PyObject *set_doc_cst; static PyObject *set_doc_cst;
@@ -953,8 +952,8 @@ parmpy_dealloc (PyObject *obj)
} }
/* Initialize the 'parameters' module. */ /* Initialize the 'parameters' module. */
static int CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION static int
gdbpy_initialize_parameters (void) gdbpy_initialize_parameters ()
{ {
int i; int i;

View File

@@ -59,8 +59,7 @@ struct pspace_object
PyObject *missing_file_handlers; PyObject *missing_file_handlers;
}; };
extern PyTypeObject pspace_object_type extern PyTypeObject pspace_object_type;
CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("pspace_object");
/* Clear the PSPACE pointer in a Pspace object and remove the reference. */ /* Clear the PSPACE pointer in a Pspace object and remove the reference. */
struct pspace_deleter struct pspace_deleter
@@ -737,8 +736,8 @@ gdbpy_free_program_space_event (program_space *pspace)
gdbpy_program_space_event (pspace, false); gdbpy_program_space_event (pspace, false);
} }
static int CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION static int
gdbpy_initialize_pspace (void) gdbpy_initialize_pspace ()
{ {
gdb::observers::executable_changed.attach (gdbpy_executable_changed, gdb::observers::executable_changed.attach (gdbpy_executable_changed,
"py-progspace"); "py-progspace");

View File

@@ -987,8 +987,8 @@ static PyMappingMethods btpy_list_mapping_methods =
/* Sets up the btrace record API. */ /* Sets up the btrace record API. */
static int CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION static int
gdbpy_initialize_btrace (void) gdbpy_initialize_btrace ()
{ {
btpy_list_type.tp_new = PyType_GenericNew; btpy_list_type.tp_new = PyType_GenericNew;
btpy_list_type.tp_flags = Py_TPFLAGS_DEFAULT; btpy_list_type.tp_flags = Py_TPFLAGS_DEFAULT;

View File

@@ -607,8 +607,8 @@ static gdb_PyGetSetDef recpy_aux_getset[] = {
/* Sets up the record API in the gdb module. */ /* Sets up the record API in the gdb module. */
static int CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION static int
gdbpy_initialize_record (void) gdbpy_initialize_record ()
{ {
recpy_record_type.tp_new = PyType_GenericNew; recpy_record_type.tp_new = PyType_GenericNew;
recpy_record_type.tp_flags = Py_TPFLAGS_DEFAULT; recpy_record_type.tp_flags = Py_TPFLAGS_DEFAULT;

View File

@@ -46,8 +46,7 @@ struct register_descriptor_iterator_object {
struct gdbarch *gdbarch; struct gdbarch *gdbarch;
}; };
extern PyTypeObject register_descriptor_iterator_object_type extern PyTypeObject register_descriptor_iterator_object_type;
CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("register_descriptor_iterator_object");
/* A register descriptor. */ /* A register descriptor. */
struct register_descriptor_object { struct register_descriptor_object {
@@ -60,8 +59,7 @@ struct register_descriptor_object {
struct gdbarch *gdbarch; struct gdbarch *gdbarch;
}; };
extern PyTypeObject register_descriptor_object_type extern PyTypeObject register_descriptor_object_type;
CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("register_descriptor_object");
/* Structure for iterator over register groups. */ /* Structure for iterator over register groups. */
struct reggroup_iterator_object { struct reggroup_iterator_object {
@@ -74,8 +72,7 @@ struct reggroup_iterator_object {
struct gdbarch *gdbarch; struct gdbarch *gdbarch;
}; };
extern PyTypeObject reggroup_iterator_object_type extern PyTypeObject reggroup_iterator_object_type;
CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("reggroup_iterator_object");
/* A register group object. */ /* A register group object. */
struct reggroup_object { struct reggroup_object {
@@ -85,8 +82,7 @@ struct reggroup_object {
const struct reggroup *reggroup; const struct reggroup *reggroup;
}; };
extern PyTypeObject reggroup_object_type extern PyTypeObject reggroup_object_type;
CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("reggroup_object");
/* Return a gdb.RegisterGroup object wrapping REGGROUP. The register /* Return a gdb.RegisterGroup object wrapping REGGROUP. The register
group objects are cached, and the same Python object will always be group objects are cached, and the same Python object will always be
@@ -425,7 +421,7 @@ gdbpy_parse_register_id (struct gdbarch *gdbarch, PyObject *pyo_reg_id,
/* Initializes the new Python classes from this file in the gdb module. */ /* Initializes the new Python classes from this file in the gdb module. */
static int CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION static int
gdbpy_initialize_registers () gdbpy_initialize_registers ()
{ {
register_descriptor_object_type.tp_new = PyType_GenericNew; register_descriptor_object_type.tp_new = PyType_GenericNew;

View File

@@ -645,8 +645,8 @@ gdbpy_lookup_static_symbols (PyObject *self, PyObject *args, PyObject *kw)
return return_list.release (); return return_list.release ();
} }
static int CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION static int
gdbpy_initialize_symbols (void) gdbpy_initialize_symbols ()
{ {
if (gdbpy_type_ready (&symbol_object_type) < 0) if (gdbpy_type_ready (&symbol_object_type) < 0)
return -1; return -1;

View File

@@ -30,8 +30,7 @@ struct symtab_object {
struct symtab *symtab; struct symtab *symtab;
}; };
extern PyTypeObject symtab_object_type extern PyTypeObject symtab_object_type;
CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("symtab_object");
static const gdbpy_registry<gdbpy_memoizing_registry_storage<symtab_object, static const gdbpy_registry<gdbpy_memoizing_registry_storage<symtab_object,
symtab, &symtab_object::symtab>> stpy_registry; symtab, &symtab_object::symtab>> stpy_registry;
@@ -74,8 +73,7 @@ struct salpy_invalidator
} }
}; };
extern PyTypeObject sal_object_type extern PyTypeObject sal_object_type;
CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("sal_object");
static const gdbpy_registry<gdbpy_tracking_registry_storage<sal_object, static const gdbpy_registry<gdbpy_tracking_registry_storage<sal_object,
symtab_and_line, &sal_object::sal, salpy_invalidator>> salpy_registry; symtab_and_line, &sal_object::sal, salpy_invalidator>> salpy_registry;
@@ -423,8 +421,8 @@ symtab_object_to_symtab (PyObject *obj)
return ((symtab_object *) obj)->symtab; return ((symtab_object *) obj)->symtab;
} }
static int CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION static int
gdbpy_initialize_symtabs (void) gdbpy_initialize_symtabs ()
{ {
symtab_object_type.tp_new = PyType_GenericNew; symtab_object_type.tp_new = PyType_GenericNew;
if (gdbpy_type_ready (&symtab_object_type) < 0) if (gdbpy_type_ready (&symtab_object_type) < 0)

View File

@@ -55,8 +55,7 @@ struct gdbpy_tui_window
bool is_valid () const; bool is_valid () const;
}; };
extern PyTypeObject gdbpy_tui_window_object_type extern PyTypeObject gdbpy_tui_window_object_type;
CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("gdbpy_tui_window");
/* A TUI window written in Python. */ /* A TUI window written in Python. */
@@ -646,7 +645,7 @@ gdbpy_tui_enabled (bool state)
/* Initialize this module. */ /* Initialize this module. */
static int CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION static int
gdbpy_initialize_tui () gdbpy_initialize_tui ()
{ {
#ifdef TUI #ifdef TUI

View File

@@ -34,8 +34,7 @@ struct type_object
struct type *type; struct type *type;
}; };
extern PyTypeObject type_object_type extern PyTypeObject type_object_type;
CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("type_object");
/* A Field object. */ /* A Field object. */
struct field_object struct field_object
@@ -46,8 +45,7 @@ struct field_object
PyObject *dict; PyObject *dict;
}; };
extern PyTypeObject field_object_type extern PyTypeObject field_object_type;
CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("field_object");
/* A type iterator object. */ /* A type iterator object. */
struct typy_iterator_object { struct typy_iterator_object {
@@ -60,8 +58,7 @@ struct typy_iterator_object {
type_object *source; type_object *source;
}; };
extern PyTypeObject type_iterator_object_type extern PyTypeObject type_iterator_object_type;
CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("typy_iterator_object");
/* This is used to initialize various gdb.TYPE_ constants. */ /* This is used to initialize various gdb.TYPE_ constants. */
struct pyty_code struct pyty_code
@@ -1511,8 +1508,8 @@ gdbpy_lookup_type (PyObject *self, PyObject *args, PyObject *kw)
return type_to_type_object (type); return type_to_type_object (type);
} }
static int CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION static int
gdbpy_initialize_types (void) gdbpy_initialize_types ()
{ {
if (gdbpy_type_ready (&type_object_type) < 0) if (gdbpy_type_ready (&type_object_type) < 0)
return -1; return -1;

View File

@@ -133,11 +133,9 @@ struct cached_frame_info
cached_reg_t reg[0]; cached_reg_t reg[0];
}; };
extern PyTypeObject pending_frame_object_type extern PyTypeObject pending_frame_object_type;
CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("pending_frame_object");
extern PyTypeObject unwind_info_object_type extern PyTypeObject unwind_info_object_type;
CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("unwind_info_object");
/* An enum returned by pyuw_object_attribute_to_pointer, a function which /* An enum returned by pyuw_object_attribute_to_pointer, a function which
is used to extract an attribute from a Python object. */ is used to extract an attribute from a Python object. */
@@ -1017,8 +1015,8 @@ pyuw_on_new_gdbarch (gdbarch *newarch)
/* Initialize unwind machinery. */ /* Initialize unwind machinery. */
static int CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION static int
gdbpy_initialize_unwind (void) gdbpy_initialize_unwind ()
{ {
gdb::observers::new_architecture.attach (pyuw_on_new_gdbarch, "py-unwind"); gdb::observers::new_architecture.attach (pyuw_on_new_gdbarch, "py-unwind");

View File

@@ -2244,8 +2244,8 @@ gdbpy_is_value_object (PyObject *obj)
return PyObject_TypeCheck (obj, &value_object_type); return PyObject_TypeCheck (obj, &value_object_type);
} }
static int CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION static int
gdbpy_initialize_values (void) gdbpy_initialize_values ()
{ {
return gdbpy_type_ready (&value_object_type); return gdbpy_type_ready (&value_object_type);
} }

View File

@@ -598,8 +598,8 @@ python_xmethod_worker::python_xmethod_worker (PyObject *py_worker,
Py_INCREF (this_type); Py_INCREF (this_type);
} }
static int CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION static int
gdbpy_initialize_xmethods (void) gdbpy_initialize_xmethods ()
{ {
py_match_method_name = PyUnicode_FromString (match_method_name); py_match_method_name = PyUnicode_FromString (match_method_name);
if (py_match_method_name == NULL) if (py_match_method_name == NULL)

View File

@@ -24,34 +24,6 @@
#include "extension-priv.h" #include "extension-priv.h"
#include "registry.h" #include "registry.h"
/* These WITH_* macros are defined by the CPython API checker that
comes with the Python plugin for GCC. See:
https://gcc-python-plugin.readthedocs.org/en/latest/cpychecker.html
The checker defines a WITH_ macro for each attribute it
exposes. Note that we intentionally do not use
'cpychecker_returns_borrowed_ref' -- that idiom is forbidden in
gdb. */
#ifdef WITH_CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF_ATTRIBUTE
#define CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF(ARG) \
__attribute__ ((cpychecker_type_object_for_typedef (ARG)))
#else
#define CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF(ARG)
#endif
#ifdef WITH_CPYCHECKER_SETS_EXCEPTION_ATTRIBUTE
#define CPYCHECKER_SETS_EXCEPTION __attribute__ ((cpychecker_sets_exception))
#else
#define CPYCHECKER_SETS_EXCEPTION
#endif
#ifdef WITH_CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION_ATTRIBUTE
#define CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION \
__attribute__ ((cpychecker_negative_result_sets_exception))
#else
#define CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION
#endif
/* /usr/include/features.h on linux systems will define _POSIX_C_SOURCE /* /usr/include/features.h on linux systems will define _POSIX_C_SOURCE
if it sees _GNU_SOURCE (which config.h will define). if it sees _GNU_SOURCE (which config.h will define).
pyconfig.h defines _POSIX_C_SOURCE to a different value than pyconfig.h defines _POSIX_C_SOURCE to a different value than
@@ -349,20 +321,13 @@ extern int gdb_python_initialized;
extern PyObject *gdb_module; extern PyObject *gdb_module;
extern PyObject *gdb_python_module; extern PyObject *gdb_python_module;
extern PyTypeObject value_object_type extern PyTypeObject value_object_type;
CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("value_object"); extern PyTypeObject block_object_type;
extern PyTypeObject block_object_type extern PyTypeObject symbol_object_type;
CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF("block_object"); extern PyTypeObject event_object_type;
extern PyTypeObject symbol_object_type extern PyTypeObject breakpoint_object_type;
CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("symbol_object"); extern PyTypeObject frame_object_type;
extern PyTypeObject event_object_type extern PyTypeObject thread_object_type;
CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("event_object");
extern PyTypeObject breakpoint_object_type
CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("breakpoint_object");
extern PyTypeObject frame_object_type
CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("frame_object");
extern PyTypeObject thread_object_type
CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("thread_object");
/* Ensure that breakpoint_object_type is initialized and return true. If /* Ensure that breakpoint_object_type is initialized and return true. If
breakpoint_object_type can't be initialized then set a suitable Python breakpoint_object_type can't be initialized then set a suitable Python
@@ -1004,8 +969,7 @@ extern PyObject *gdbpy_gdb_error;
extern PyObject *gdbpy_gdb_memory_error; extern PyObject *gdbpy_gdb_memory_error;
extern PyObject *gdbpy_gdberror_exc; extern PyObject *gdbpy_gdberror_exc;
extern void gdbpy_convert_exception (const struct gdb_exception &) extern void gdbpy_convert_exception (const struct gdb_exception &);
CPYCHECKER_SETS_EXCEPTION;
/* Use this in a 'catch' block to convert the exception E to a Python /* Use this in a 'catch' block to convert the exception E to a Python
exception and return value VAL to signal that an exception occurred. exception and return value VAL to signal that an exception occurred.
@@ -1019,8 +983,7 @@ gdbpy_handle_gdb_exception (T val, const gdb_exception &e)
return val; return val;
} }
int get_addr_from_python (PyObject *obj, CORE_ADDR *addr) int get_addr_from_python (PyObject *obj, CORE_ADDR *addr);
CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION;
gdbpy_ref<> gdb_py_object_from_longest (LONGEST l); gdbpy_ref<> gdb_py_object_from_longest (LONGEST l);
gdbpy_ref<> gdb_py_object_from_ulongest (ULONGEST l); gdbpy_ref<> gdb_py_object_from_ulongest (ULONGEST l);
@@ -1029,8 +992,7 @@ int gdb_py_int_as_long (PyObject *, long *);
PyObject *gdb_py_generic_dict (PyObject *self, void *closure); PyObject *gdb_py_generic_dict (PyObject *self, void *closure);
int gdb_pymodule_addobject (PyObject *module, const char *name, int gdb_pymodule_addobject (PyObject *module, const char *name,
PyObject *object) PyObject *object);
CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION;
/* Return a Python string (str) object that represents SELF. SELF can be /* Return a Python string (str) object that represents SELF. SELF can be

View File

@@ -3204,7 +3204,6 @@ Print a warning." },
/* Define all the event objects. */ /* Define all the event objects. */
#define GDB_PY_DEFINE_EVENT_TYPE(name, py_name, doc, base) \ #define GDB_PY_DEFINE_EVENT_TYPE(name, py_name, doc, base) \
PyTypeObject name##_event_object_type \ PyTypeObject name##_event_object_type \
CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("event_object") \
= { \ = { \
PyVarObject_HEAD_INIT (NULL, 0) \ PyVarObject_HEAD_INIT (NULL, 0) \
"gdb." py_name, /* tp_name */ \ "gdb." py_name, /* tp_name */ \