@@ -361,11 +361,7 @@ static int CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION
gdbpy_initialize_arch (void)
{
arch_object_type.tp_new = PyType_GenericNew;
- if (PyType_Ready (&arch_object_type) < 0)
- return -1;
-
- return gdb_pymodule_addobject (gdb_module, "Architecture",
- (PyObject *) &arch_object_type);
+ return gdbpy_type_ready (&arch_object_type);
}
GDBPY_INITIALIZE_FILE (gdbpy_initialize_arch);
@@ -493,19 +493,14 @@ static int CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION
gdbpy_initialize_blocks (void)
{
block_object_type.tp_new = PyType_GenericNew;
- if (PyType_Ready (&block_object_type) < 0)
+ if (gdbpy_type_ready (&block_object_type) < 0)
return -1;
block_syms_iterator_object_type.tp_new = PyType_GenericNew;
- if (PyType_Ready (&block_syms_iterator_object_type) < 0)
+ if (gdbpy_type_ready (&block_syms_iterator_object_type) < 0)
return -1;
- if (gdb_pymodule_addobject (gdb_module, "Block",
- (PyObject *) &block_object_type) < 0)
- return -1;
-
- return gdb_pymodule_addobject (gdb_module, "BlockIterator",
- (PyObject *) &block_syms_iterator_object_type);
+ return 0;
}
GDBPY_INITIALIZE_FILE (gdbpy_initialize_blocks);
@@ -1114,7 +1114,7 @@ gdbpy_breakpoint_init_breakpoint_type ()
if (breakpoint_object_type.tp_new == nullptr)
{
breakpoint_object_type.tp_new = PyType_GenericNew;
- if (PyType_Ready (&breakpoint_object_type) < 0)
+ if (gdbpy_type_ready (&breakpoint_object_type) < 0)
{
/* Reset tp_new back to nullptr so future calls to this function
will try calling PyType_Ready again. */
@@ -1359,10 +1359,6 @@ gdbpy_initialize_breakpoints (void)
if (!gdbpy_breakpoint_init_breakpoint_type ())
return -1;
- if (gdb_pymodule_addobject (gdb_module, "Breakpoint",
- (PyObject *) &breakpoint_object_type) < 0)
- return -1;
-
gdb::observers::breakpoint_created.attach (gdbpy_breakpoint_created,
"py-breakpoint");
gdb::observers::breakpoint_deleted.attach (gdbpy_breakpoint_deleted,
@@ -1394,14 +1390,7 @@ gdbpy_initialize_breakpoints (void)
static int CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION
gdbpy_initialize_breakpoint_locations ()
{
- if (PyType_Ready (&breakpoint_location_object_type) < 0)
- return -1;
-
- if (gdb_pymodule_addobject (gdb_module, "BreakpointLocation",
- (PyObject *) &breakpoint_location_object_type)
- < 0)
- return -1;
- return 0;
+ return gdbpy_type_ready (&breakpoint_location_object_type);
}
@@ -557,7 +557,7 @@ gdbpy_initialize_commands (void)
int i;
cmdpy_object_type.tp_new = PyType_GenericNew;
- if (PyType_Ready (&cmdpy_object_type) < 0)
+ if (gdbpy_type_ready (&cmdpy_object_type) < 0)
return -1;
/* Note: alias and user are special. */
@@ -587,10 +587,6 @@ gdbpy_initialize_commands (void)
return -1;
}
- if (gdb_pymodule_addobject (gdb_module, "Command",
- (PyObject *) &cmdpy_object_type) < 0)
- return -1;
-
invoke_cst = PyUnicode_FromString ("invoke");
if (invoke_cst == NULL)
return -1;
@@ -287,18 +287,10 @@ connpy_get_connection_details (PyObject *self, void *closure)
static int CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION
gdbpy_initialize_connection (void)
{
- if (PyType_Ready (&connection_object_type) < 0)
+ if (gdbpy_type_ready (&connection_object_type) < 0)
return -1;
- if (gdb_pymodule_addobject (gdb_module, "TargetConnection",
- (PyObject *) &connection_object_type) < 0)
- return -1;
-
- if (PyType_Ready (&remote_connection_object_type) < 0)
- return -1;
-
- if (gdb_pymodule_addobject (gdb_module, "RemoteTargetConnection",
- (PyObject *) &remote_connection_object_type) < 0)
+ if (gdbpy_type_ready (&remote_connection_object_type) < 0)
return -1;
return 0;
@@ -1665,45 +1665,23 @@ gdbpy_initialize_disasm ()
}
disasm_info_object_type.tp_new = PyType_GenericNew;
- if (PyType_Ready (&disasm_info_object_type) < 0)
- return -1;
-
- if (gdb_pymodule_addobject (gdb_disassembler_module, "DisassembleInfo",
- (PyObject *) &disasm_info_object_type) < 0)
+ if (gdbpy_type_ready (&disasm_info_object_type, gdb_disassembler_module) < 0)
return -1;
disasm_result_object_type.tp_new = PyType_GenericNew;
- if (PyType_Ready (&disasm_result_object_type) < 0)
- return -1;
-
- if (gdb_pymodule_addobject (gdb_disassembler_module, "DisassemblerResult",
- (PyObject *) &disasm_result_object_type) < 0)
+ if (gdbpy_type_ready (&disasm_result_object_type, gdb_disassembler_module) < 0)
return -1;
disasm_part_object_type.tp_new = PyType_GenericNew;
- if (PyType_Ready (&disasm_part_object_type) < 0)
- return -1;
-
- if (gdb_pymodule_addobject (gdb_disassembler_module, "DisassemblerPart",
- (PyObject *) &disasm_part_object_type) < 0)
+ if (gdbpy_type_ready (&disasm_part_object_type, gdb_disassembler_module) < 0)
return -1;
disasm_addr_part_object_type.tp_new = PyType_GenericNew;
- if (PyType_Ready (&disasm_addr_part_object_type) < 0)
- return -1;
-
- if (gdb_pymodule_addobject (gdb_disassembler_module,
- "DisassemblerAddressPart",
- (PyObject *) &disasm_addr_part_object_type) < 0)
+ if (gdbpy_type_ready (&disasm_addr_part_object_type, gdb_disassembler_module) < 0)
return -1;
disasm_text_part_object_type.tp_new = PyType_GenericNew;
- if (PyType_Ready (&disasm_text_part_object_type) < 0)
- return -1;
-
- if (gdb_pymodule_addobject (gdb_disassembler_module,
- "DisassemblerTextPart",
- (PyObject *) &disasm_text_part_object_type) < 0)
+ if (gdbpy_type_ready (&disasm_text_part_object_type, gdb_disassembler_module) < 0)
return -1;
return 0;
@@ -56,25 +56,9 @@ evpy_add_attribute (PyObject *event, const char *name, PyObject *attr)
static int CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION
gdbpy_initialize_event (void)
{
- return gdbpy_initialize_event_generic (&event_object_type,
- "Event");
+ return gdbpy_type_ready (&event_object_type);
}
-/* Initialize the given event type. If BASE is not NULL it will
- be set as the types base.
- Returns 0 if initialization was successful -1 otherwise. */
-
-int
-gdbpy_initialize_event_generic (PyTypeObject *type,
- const char *name)
-{
- if (PyType_Ready (type) < 0)
- return -1;
-
- return gdb_pymodule_addobject (gdb_module, name, (PyObject *) type);
-}
-
-
/* Notify the list of listens that the given EVENT has occurred.
returns 0 if emit is successful -1 otherwise. */
@@ -84,7 +84,5 @@ extern void evpy_dealloc (PyObject *self);
extern int evpy_add_attribute (PyObject *event,
const char *name, PyObject *attr)
CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION;
-int gdbpy_initialize_event_generic (PyTypeObject *type, const char *name)
- CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION;
#endif /* PYTHON_PY_EVENT_H */
@@ -104,11 +104,7 @@ evregpy_dealloc (PyObject *self)
static int CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION
gdbpy_initialize_eventregistry (void)
{
- if (PyType_Ready (&eventregistry_object_type) < 0)
- return -1;
-
- return gdb_pymodule_addobject (gdb_module, "EventRegistry",
- (PyObject *) &eventregistry_object_type);
+ return gdbpy_type_ready (&eventregistry_object_type);
}
/* Return the number of listeners currently connected to this
@@ -439,11 +439,7 @@ gdbpy_initialize_finishbreakpoints (void)
if (!gdbpy_breakpoint_init_breakpoint_type ())
return -1;
- if (PyType_Ready (&finish_breakpoint_object_type) < 0)
- return -1;
-
- if (gdb_pymodule_addobject (gdb_module, "FinishBreakpoint",
- (PyObject *) &finish_breakpoint_object_type) < 0)
+ if (gdbpy_type_ready (&finish_breakpoint_object_type) < 0)
return -1;
gdb::observers::normal_stop.attach (bpfinishpy_handle_stop,
@@ -761,7 +761,7 @@ static int CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION
gdbpy_initialize_frames (void)
{
frame_object_type.tp_new = PyType_GenericNew;
- if (PyType_Ready (&frame_object_type) < 0)
+ if (gdbpy_type_ready (&frame_object_type) < 0)
return -1;
/* Note: These would probably be best exposed as class attributes of
@@ -785,8 +785,7 @@ gdbpy_initialize_frames (void)
#include "unwind_stop_reasons.def"
#undef SET
- return gdb_pymodule_addobject (gdb_module, "Frame",
- (PyObject *) &frame_object_type);
+ return 0;
}
GDBPY_INITIALIZE_FILE (gdbpy_initialize_frames);
@@ -137,11 +137,7 @@ static int CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION
gdbpy_initialize_functions (void)
{
fnpy_object_type.tp_new = PyType_GenericNew;
- if (PyType_Ready (&fnpy_object_type) < 0)
- return -1;
-
- return gdb_pymodule_addobject (gdb_module, "Function",
- (PyObject *) &fnpy_object_type);
+ return gdbpy_type_ready (&fnpy_object_type);
}
GDBPY_INITIALIZE_FILE (gdbpy_initialize_functions);
@@ -1009,11 +1009,7 @@ gdbpy_selected_inferior (PyObject *self, PyObject *args)
static int CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION
gdbpy_initialize_inferior (void)
{
- if (PyType_Ready (&inferior_object_type) < 0)
- return -1;
-
- if (gdb_pymodule_addobject (gdb_module, "Inferior",
- (PyObject *) &inferior_object_type) < 0)
+ if (gdbpy_type_ready (&inferior_object_type) < 0)
return -1;
gdb::observers::new_thread.attach (add_thread_object, "py-inferior");
@@ -412,11 +412,7 @@ gdbpy_selected_thread (PyObject *self, PyObject *args)
static int CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION
gdbpy_initialize_thread (void)
{
- if (PyType_Ready (&thread_object_type) < 0)
- return -1;
-
- return gdb_pymodule_addobject (gdb_module, "InferiorThread",
- (PyObject *) &thread_object_type);
+ return gdbpy_type_ready (&thread_object_type);
}
GDBPY_INITIALIZE_FILE (gdbpy_initialize_thread);
@@ -66,7 +66,7 @@ py_insn_get_insn_type ()
py_insn_type.tp_doc = "GDB instruction object";
py_insn_type.tp_getset = py_insn_getset;
- if (PyType_Ready (&py_insn_type) < 0)
+ if (gdbpy_type_ready (&py_insn_type) < 0)
{
/* Reset the tp_new field so any subsequent calls to this
function will retry to make the type ready. */
@@ -236,11 +236,7 @@ gdbpy_create_lazy_string_object (CORE_ADDR address, long length,
static int CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION
gdbpy_initialize_lazy_string (void)
{
- if (PyType_Ready (&lazy_string_object_type) < 0)
- return -1;
-
- Py_INCREF (&lazy_string_object_type);
- return 0;
+ return gdbpy_type_ready (&lazy_string_object_type);
}
/* Determine whether the printer object pointed to by OBJ is a
@@ -287,27 +287,11 @@ ltpy_dealloc (PyObject *self)
static int CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION
gdbpy_initialize_linetable (void)
{
- if (PyType_Ready (&linetable_object_type) < 0)
+ if (gdbpy_type_ready (&linetable_object_type) < 0)
return -1;
- if (PyType_Ready (&linetable_entry_object_type) < 0)
+ if (gdbpy_type_ready (&linetable_entry_object_type) < 0)
return -1;
- if (PyType_Ready (<py_iterator_object_type) < 0)
- return -1;
-
- Py_INCREF (&linetable_object_type);
- Py_INCREF (&linetable_entry_object_type);
- Py_INCREF (<py_iterator_object_type);
-
- if (gdb_pymodule_addobject (gdb_module, "LineTable",
- (PyObject *) &linetable_object_type) < 0)
- return -1;
-
- if (gdb_pymodule_addobject (gdb_module, "LineTableEntry",
- (PyObject *) &linetable_entry_object_type) < 0)
- return -1;
-
- if (gdb_pymodule_addobject (gdb_module, "LineTableIterator",
- (PyObject *) <py_iterator_object_type) < 0)
+ if (gdbpy_type_ready (<py_iterator_object_type) < 0)
return -1;
return 0;
@@ -102,11 +102,7 @@ static int CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION
gdbpy_initialize_membuf (void)
{
membuf_object_type.tp_new = PyType_GenericNew;
- if (PyType_Ready (&membuf_object_type) < 0)
- return -1;
-
- return gdb_pymodule_addobject (gdb_module, "Membuf",
- (PyObject *) &membuf_object_type);
+ return gdbpy_type_ready (&membuf_object_type);
}
GDBPY_INITIALIZE_FILE (gdbpy_initialize_membuf);
@@ -447,12 +447,7 @@ static int CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION
gdbpy_initialize_micommands ()
{
micmdpy_object_type.tp_new = PyType_GenericNew;
- if (PyType_Ready (&micmdpy_object_type) < 0)
- return -1;
-
- if (gdb_pymodule_addobject (gdb_module, "MICommand",
- (PyObject *) &micmdpy_object_type)
- < 0)
+ if (gdbpy_type_ready (&micmdpy_object_type) < 0)
return -1;
invoke_cst = PyUnicode_FromString ("invoke");
@@ -709,11 +709,7 @@ objfile_to_objfile_object (struct objfile *objfile)
static int CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION
gdbpy_initialize_objfile (void)
{
- if (PyType_Ready (&objfile_object_type) < 0)
- return -1;
-
- return gdb_pymodule_addobject (gdb_module, "Objfile",
- (PyObject *) &objfile_object_type);
+ return gdbpy_type_ready (&objfile_object_type);
}
GDBPY_INITIALIZE_FILE (gdbpy_initialize_objfile);
@@ -909,7 +909,7 @@ gdbpy_initialize_parameters (void)
int i;
parmpy_object_type.tp_new = PyType_GenericNew;
- if (PyType_Ready (&parmpy_object_type) < 0)
+ if (gdbpy_type_ready (&parmpy_object_type) < 0)
return -1;
set_doc_cst = PyUnicode_FromString ("set_doc");
@@ -927,8 +927,7 @@ gdbpy_initialize_parameters (void)
return -1;
}
- return gdb_pymodule_addobject (gdb_module, "Parameter",
- (PyObject *) &parmpy_object_type);
+ return 0;
}
GDBPY_INITIALIZE_FILE (gdbpy_initialize_parameters);
@@ -836,10 +836,7 @@ PyTypeObject printer_object_type =
static int
gdbpy_initialize_prettyprint ()
{
- if (PyType_Ready (&printer_object_type) < 0)
- return -1;
- return gdb_pymodule_addobject (gdb_module, "ValuePrinter",
- (PyObject *) &printer_object_type);
+ return gdbpy_type_ready (&printer_object_type);
}
GDBPY_INITIALIZE_FILE (gdbpy_initialize_prettyprint);
@@ -747,11 +747,10 @@ gdbpy_initialize_pspace (void)
gdb::observers::free_program_space.attach (gdbpy_free_program_space_event,
"py-progspace");
- if (PyType_Ready (&pspace_object_type) < 0)
+ if (gdbpy_type_ready (&pspace_object_type) < 0)
return -1;
- return gdb_pymodule_addobject (gdb_module, "Progspace",
- (PyObject *) &pspace_object_type);
+ return 0;
}
GDBPY_INITIALIZE_FILE (gdbpy_initialize_pspace);
@@ -1006,7 +1006,7 @@ gdbpy_initialize_btrace (void)
btpy_list_mapping_methods.mp_subscript = btpy_list_slice;
- return PyType_Ready (&btpy_list_type);
+ return gdbpy_type_ready (&btpy_list_type);
}
GDBPY_INITIALIZE_FILE (gdbpy_initialize_btrace);
@@ -653,11 +653,11 @@ gdbpy_initialize_record (void)
recpy_aux_type.tp_richcompare = recpy_element_richcompare;
recpy_aux_type.tp_hash = recpy_element_hash;
- if (PyType_Ready (&recpy_record_type) < 0
- || PyType_Ready (&recpy_insn_type) < 0
- || PyType_Ready (&recpy_func_type) < 0
- || PyType_Ready (&recpy_gap_type) < 0
- || PyType_Ready (&recpy_aux_type) < 0)
+ if (gdbpy_type_ready (&recpy_record_type) < 0
+ || gdbpy_type_ready (&recpy_insn_type) < 0
+ || gdbpy_type_ready (&recpy_func_type) < 0
+ || gdbpy_type_ready (&recpy_gap_type) < 0
+ || gdbpy_type_ready (&recpy_aux_type) < 0)
return -1;
else
return 0;
@@ -430,35 +430,22 @@ static int CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION
gdbpy_initialize_registers ()
{
register_descriptor_object_type.tp_new = PyType_GenericNew;
- if (PyType_Ready (®ister_descriptor_object_type) < 0)
- return -1;
- if (gdb_pymodule_addobject
- (gdb_module, "RegisterDescriptor",
- (PyObject *) ®ister_descriptor_object_type) < 0)
+ if (gdbpy_type_ready (®ister_descriptor_object_type) < 0)
return -1;
reggroup_iterator_object_type.tp_new = PyType_GenericNew;
- if (PyType_Ready (®group_iterator_object_type) < 0)
- return -1;
- if (gdb_pymodule_addobject
- (gdb_module, "RegisterGroupsIterator",
- (PyObject *) ®group_iterator_object_type) < 0)
+ if (gdbpy_type_ready (®group_iterator_object_type) < 0)
return -1;
reggroup_object_type.tp_new = PyType_GenericNew;
- if (PyType_Ready (®group_object_type) < 0)
- return -1;
- if (gdb_pymodule_addobject
- (gdb_module, "RegisterGroup",
- (PyObject *) ®group_object_type) < 0)
+ if (gdbpy_type_ready (®group_object_type) < 0)
return -1;
register_descriptor_iterator_object_type.tp_new = PyType_GenericNew;
- if (PyType_Ready (®ister_descriptor_iterator_object_type) < 0)
+ if (gdbpy_type_ready (®ister_descriptor_iterator_object_type) < 0)
return -1;
- return (gdb_pymodule_addobject
- (gdb_module, "RegisterDescriptorIterator",
- (PyObject *) ®ister_descriptor_iterator_object_type));
+
+ return 0;
}
GDBPY_INITIALIZE_FILE (gdbpy_initialize_registers);
@@ -640,7 +640,7 @@ gdbpy_lookup_static_symbols (PyObject *self, PyObject *args, PyObject *kw)
static int CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION
gdbpy_initialize_symbols (void)
{
- if (PyType_Ready (&symbol_object_type) < 0)
+ if (gdbpy_type_ready (&symbol_object_type) < 0)
return -1;
if (PyModule_AddIntConstant (gdb_module, "SYMBOL_LOC_UNDEF", LOC_UNDEF) < 0
@@ -685,8 +685,7 @@ gdbpy_initialize_symbols (void)
#include "sym-domains.def"
#undef SYM_DOMAIN
- return gdb_pymodule_addobject (gdb_module, "Symbol",
- (PyObject *) &symbol_object_type);
+ return 0;
}
GDBPY_INITIALIZE_FILE (gdbpy_initialize_symbols);
@@ -512,19 +512,14 @@ static int CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION
gdbpy_initialize_symtabs (void)
{
symtab_object_type.tp_new = PyType_GenericNew;
- if (PyType_Ready (&symtab_object_type) < 0)
+ if (gdbpy_type_ready (&symtab_object_type) < 0)
return -1;
sal_object_type.tp_new = PyType_GenericNew;
- if (PyType_Ready (&sal_object_type) < 0)
+ if (gdbpy_type_ready (&sal_object_type) < 0)
return -1;
- if (gdb_pymodule_addobject (gdb_module, "Symtab",
- (PyObject *) &symtab_object_type) < 0)
- return -1;
-
- return gdb_pymodule_addobject (gdb_module, "Symtab_and_line",
- (PyObject *) &sal_object_type);
+ return 0;
}
GDBPY_INITIALIZE_FILE (gdbpy_initialize_symtabs);
@@ -625,7 +625,7 @@ gdbpy_initialize_tui ()
{
#ifdef TUI
gdbpy_tui_window_object_type.tp_new = PyType_GenericNew;
- if (PyType_Ready (&gdbpy_tui_window_object_type) < 0)
+ if (gdbpy_type_ready (&gdbpy_tui_window_object_type) < 0)
return -1;
#endif /* TUI */
@@ -1526,11 +1526,11 @@ gdbpy_lookup_type (PyObject *self, PyObject *args, PyObject *kw)
static int CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION
gdbpy_initialize_types (void)
{
- if (PyType_Ready (&type_object_type) < 0)
+ if (gdbpy_type_ready (&type_object_type) < 0)
return -1;
- if (PyType_Ready (&field_object_type) < 0)
+ if (gdbpy_type_ready (&field_object_type) < 0)
return -1;
- if (PyType_Ready (&type_iterator_object_type) < 0)
+ if (gdbpy_type_ready (&type_iterator_object_type) < 0)
return -1;
for (const auto &item : pyty_codes)
@@ -1539,16 +1539,7 @@ gdbpy_initialize_types (void)
return -1;
}
- if (gdb_pymodule_addobject (gdb_module, "Type",
- (PyObject *) &type_object_type) < 0)
- return -1;
-
- if (gdb_pymodule_addobject (gdb_module, "TypeIterator",
- (PyObject *) &type_iterator_object_type) < 0)
- return -1;
-
- return gdb_pymodule_addobject (gdb_module, "Field",
- (PyObject *) &field_object_type);
+ return 0;
}
GDBPY_INITIALIZE_FILE (gdbpy_initialize_types);
@@ -1002,17 +1002,13 @@ gdbpy_initialize_unwind (void)
{
gdb::observers::new_architecture.attach (pyuw_on_new_gdbarch, "py-unwind");
- if (PyType_Ready (&pending_frame_object_type) < 0)
+ if (gdbpy_type_ready (&pending_frame_object_type) < 0)
return -1;
- int rc = gdb_pymodule_addobject (gdb_module, "PendingFrame",
- (PyObject *) &pending_frame_object_type);
- if (rc != 0)
- return rc;
- if (PyType_Ready (&unwind_info_object_type) < 0)
+ if (gdbpy_type_ready (&unwind_info_object_type) < 0)
return -1;
- return gdb_pymodule_addobject (gdb_module, "UnwindInfo",
- (PyObject *) &unwind_info_object_type);
+
+ return 0;
}
void _initialize_py_unwind ();
@@ -2215,11 +2215,7 @@ gdbpy_is_value_object (PyObject *obj)
static int CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION
gdbpy_initialize_values (void)
{
- if (PyType_Ready (&value_object_type) < 0)
- return -1;
-
- return gdb_pymodule_addobject (gdb_module, "Value",
- (PyObject *) &value_object_type);
+ return gdbpy_type_ready (&value_object_type);
}
GDBPY_INITIALIZE_FILE (gdbpy_initialize_values);
@@ -1119,4 +1119,34 @@ extern std::optional<int> gdbpy_print_insn (struct gdbarch *gdbarch,
CORE_ADDR address,
disassemble_info *info);
+/* A wrapper for PyType_Ready that also automatically registers the
+ type in the appropriate module. Returns 0 on success, -1 on error.
+ If MOD is supplied, then the type is added to that module. If MOD
+ is not supplied, the type name (tp_name field) must be of the form
+ "gdb.Mumble", and the type will be added to the gdb module. */
+
+static inline int
+gdbpy_type_ready (PyTypeObject *type, PyObject *mod = nullptr)
+{
+ if (PyType_Ready (type) < 0)
+ return -1;
+ if (mod == nullptr)
+ {
+ gdb_assert (startswith (type->tp_name, "gdb."));
+ mod = gdb_module;
+ }
+ const char *dot = strrchr (type->tp_name, '.');
+ gdb_assert (dot != nullptr);
+ return gdb_pymodule_addobject (mod, dot + 1, (PyObject *) type);
+}
+
+/* Poison PyType_Ready. Only gdbpy_type_ready should be used, to
+ avoid forgetting to register the type. See PR python/32163. */
+#undef PyType_Ready
+#ifdef __GNUC__
+# pragma GCC poison PyType_Ready
+#else
+# define PyType_Ready POISONED_PyType_Ready
+#endif
+
#endif /* PYTHON_PYTHON_INTERNAL_H */
@@ -2316,7 +2316,7 @@ do_start_initialization ()
return false;
#define GDB_PY_DEFINE_EVENT_TYPE(name, py_name, doc, base) \
- if (gdbpy_initialize_event_generic (&name##_event_object_type, py_name) < 0) \
+ if (gdbpy_type_ready (&name##_event_object_type) < 0) \
return false;
#include "py-event-types.def"
#undef GDB_PY_DEFINE_EVENT_TYPE
@@ -561,3 +561,12 @@ if { [use_gdb_stub] == 0 } {
}
}
}
+
+# Regression test for PR python/32163: several types were not
+# previously registered with the module, so could not be inspected
+# directly.
+foreach type {Instruction LazyString Membuf Record RecordFunctionSegment \
+ RecordGap RecordInstruction TuiWindow} {
+ gdb_test "python print(type(gdb.$type))" "<class 'type'>" \
+ "gdb.$type is registered"
+}