Check errors.
* python/py-auto-load.c (gdbpy_initialize_auto_load): Return 'int'.
* python/py-block.c (gdbpy_initialize_blocks): Return 'int'.
Check errors.
* python/py-breakpoint.c (gdbpy_initialize_breakpoints): Return 'int'.
Check errors.
* python/py-cmd.c (gdbpy_initialize_commands): Return 'int'.
Check errors.
* python/py-event.c (gdbpy_initialize_event): Return 'int'.
Check errors.
* python/py-event.h (GDBPY_NEW_EVENT_TYPE): Change generated
init function to return 'int'.
* python/py-evtregistry.c (gdbpy_initialize_eventregistry):
Return 'int'. Check errors.
* python/py-evts.c (gdbpy_initialize_py_events): Return 'int'.
Check errors.
* python/py-finishbreakpoint.c (gdbpy_initialize_finishbreakpoints):
Return 'int'. Check errors.
* python/py-frame.c (gdbpy_initialize_frames): Return 'int'.
Check errors.
* python/py-function.c (gdbpy_initialize_functions): Return 'int'.
Check errors.
* python/py-gdb-readline.c (gdbpy_initialize_gdb_readline):
Check errors.
* python/py-inferior.c (gdbpy_initialize_inferior): Return 'int'.
Check errors.
* python/py-infthread.c (gdbpy_initialize_thread): Return 'int'.
Check errors.
* python/py-lazy-string.c (gdbpy_initialize_lazy_string): Return 'int'.
Check errors.
* python/py-objfile.c (gdbpy_initialize_objfile): Return 'int'.
Check errors.
* python/py-param.c (gdbpy_initialize_parameters): Return 'int'.
Check errors.
* python/py-progspace.c (gdbpy_initialize_pspace): Return 'int'.
Check errors.
* python/py-symbol.c (gdbpy_initialize_symbols): Return 'int'.
Check errors.
* python/py-symtab.c (gdbpy_initialize_symtabs): Return 'int'.
Check errors.
* python/py-type.c (gdbpy_initialize_types): Return 'int'.
Check errors.
* python/py-value.c (gdbpy_initialize_values): Return 'int'.
Check errors.
* python/python-internal.h (gdbpy_initialize_auto_load,
gdbpy_initialize_values, gdbpy_initialize_frames,
gdbpy_initialize_symtabs, gdbpy_initialize_commands,
gdbpy_initialize_symbols, gdbpy_initialize_symtabs,
gdbpy_initialize_blocks, gdbpy_initialize_types,
gdbpy_initialize_functions, gdbpy_initialize_pspace,
gdbpy_initialize_objfile, gdbpy_initialize_breakpoints,
gdbpy_initialize_finishbreakpoints,
gdbpy_initialize_lazy_string, gdbpy_initialize_parameters,
gdbpy_initialize_thread, gdbpy_initialize_inferior,
gdbpy_initialize_eventregistry, gdbpy_initialize_event,
gdbpy_initialize_py_events, gdbpy_initialize_stop_event,
gdbpy_initialize_signal_event,
gdbpy_initialize_breakpoint_event,
gdbpy_initialize_continue_event,
gdbpy_initialize_exited_event, gdbpy_initialize_thread_event,
gdbpy_initialize_new_objfile_event, gdbpy_initialize_arch):
Update. Use CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION.
* python/python.c (gdb_python_initialized): New global.
(gdbpy_initialize_events): Return 'int'. Check errors.
(_initialize_python): Check errors. Set
gdb_python_initialized.
+2013-05-20 Tom Tromey <tromey@redhat.com>
+
+ * python/py-arch.c (gdbpy_initialize_arch): Return 'int'.
+ Check errors.
+ * python/py-auto-load.c (gdbpy_initialize_auto_load): Return 'int'.
+ * python/py-block.c (gdbpy_initialize_blocks): Return 'int'.
+ Check errors.
+ * python/py-breakpoint.c (gdbpy_initialize_breakpoints): Return 'int'.
+ Check errors.
+ * python/py-cmd.c (gdbpy_initialize_commands): Return 'int'.
+ Check errors.
+ * python/py-event.c (gdbpy_initialize_event): Return 'int'.
+ Check errors.
+ * python/py-event.h (GDBPY_NEW_EVENT_TYPE): Change generated
+ init function to return 'int'.
+ * python/py-evtregistry.c (gdbpy_initialize_eventregistry):
+ Return 'int'. Check errors.
+ * python/py-evts.c (gdbpy_initialize_py_events): Return 'int'.
+ Check errors.
+ * python/py-finishbreakpoint.c (gdbpy_initialize_finishbreakpoints):
+ Return 'int'. Check errors.
+ * python/py-frame.c (gdbpy_initialize_frames): Return 'int'.
+ Check errors.
+ * python/py-function.c (gdbpy_initialize_functions): Return 'int'.
+ Check errors.
+ * python/py-gdb-readline.c (gdbpy_initialize_gdb_readline):
+ Check errors.
+ * python/py-inferior.c (gdbpy_initialize_inferior): Return 'int'.
+ Check errors.
+ * python/py-infthread.c (gdbpy_initialize_thread): Return 'int'.
+ Check errors.
+ * python/py-lazy-string.c (gdbpy_initialize_lazy_string): Return 'int'.
+ Check errors.
+ * python/py-objfile.c (gdbpy_initialize_objfile): Return 'int'.
+ Check errors.
+ * python/py-param.c (gdbpy_initialize_parameters): Return 'int'.
+ Check errors.
+ * python/py-progspace.c (gdbpy_initialize_pspace): Return 'int'.
+ Check errors.
+ * python/py-symbol.c (gdbpy_initialize_symbols): Return 'int'.
+ Check errors.
+ * python/py-symtab.c (gdbpy_initialize_symtabs): Return 'int'.
+ Check errors.
+ * python/py-type.c (gdbpy_initialize_types): Return 'int'.
+ Check errors.
+ * python/py-value.c (gdbpy_initialize_values): Return 'int'.
+ Check errors.
+ * python/python-internal.h (gdbpy_initialize_auto_load,
+ gdbpy_initialize_values, gdbpy_initialize_frames,
+ gdbpy_initialize_symtabs, gdbpy_initialize_commands,
+ gdbpy_initialize_symbols, gdbpy_initialize_symtabs,
+ gdbpy_initialize_blocks, gdbpy_initialize_types,
+ gdbpy_initialize_functions, gdbpy_initialize_pspace,
+ gdbpy_initialize_objfile, gdbpy_initialize_breakpoints,
+ gdbpy_initialize_finishbreakpoints,
+ gdbpy_initialize_lazy_string, gdbpy_initialize_parameters,
+ gdbpy_initialize_thread, gdbpy_initialize_inferior,
+ gdbpy_initialize_eventregistry, gdbpy_initialize_event,
+ gdbpy_initialize_py_events, gdbpy_initialize_stop_event,
+ gdbpy_initialize_signal_event,
+ gdbpy_initialize_breakpoint_event,
+ gdbpy_initialize_continue_event,
+ gdbpy_initialize_exited_event, gdbpy_initialize_thread_event,
+ gdbpy_initialize_new_objfile_event, gdbpy_initialize_arch):
+ Update. Use CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION.
+ * python/python.c (gdb_python_initialized): New global.
+ (gdbpy_initialize_events): Return 'int'. Check errors.
+ (_initialize_python): Check errors. Set
+ gdb_python_initialized.
+
2013-05-20 Tom Tromey <tromey@redhat.com>
* python/py-finishbreakpoint.c (bpfinishpy_out_of_scope):
/* Initializes the Architecture class in the gdb module. */
-void
+int
gdbpy_initialize_arch (void)
{
arch_object_data = gdbarch_data_register_post_init (arch_object_data_init);
arch_object_type.tp_new = PyType_GenericNew;
if (PyType_Ready (&arch_object_type) < 0)
- return;
+ return -1;
Py_INCREF (&arch_object_type);
- PyModule_AddObject (gdb_module, "Architecture",
- (PyObject *) &arch_object_type);
+ return PyModule_AddObject (gdb_module, "Architecture",
+ (PyObject *) &arch_object_type);
}
static PyMethodDef arch_object_methods [] = {
auto_load_info_scripts (pattern, from_tty, &script_language_python);
}
\f
-void
+int
gdbpy_initialize_auto_load (void)
{
struct cmd_list_element *cmd;
cmd = add_info ("auto-load-scripts", info_auto_load_python_scripts, _("\
Print the list of automatically loaded Python scripts, deprecated."));
deprecate_cmd (cmd, "info auto-load python-scripts");
+
+ return 0;
}
#else /* ! HAVE_PYTHON */
}
}
-void
+int
gdbpy_initialize_blocks (void)
{
block_object_type.tp_new = PyType_GenericNew;
if (PyType_Ready (&block_object_type) < 0)
- return;
+ return -1;
block_syms_iterator_object_type.tp_new = PyType_GenericNew;
if (PyType_Ready (&block_syms_iterator_object_type) < 0)
- return;
+ return -1;
/* Register an objfile "free" callback so we can properly
invalidate blocks when an object file is about to be
= register_objfile_data_with_cleanup (NULL, del_objfile_blocks);
Py_INCREF (&block_object_type);
- PyModule_AddObject (gdb_module, "Block", (PyObject *) &block_object_type);
+ if (PyModule_AddObject (gdb_module, "Block",
+ (PyObject *) &block_object_type) < 0)
+ return -1;
Py_INCREF (&block_syms_iterator_object_type);
- PyModule_AddObject (gdb_module, "BlockIterator",
- (PyObject *) &block_syms_iterator_object_type);
+ return PyModule_AddObject (gdb_module, "BlockIterator",
+ (PyObject *) &block_syms_iterator_object_type);
}
\f
\f
/* Initialize the Python breakpoint code. */
-void
+int
gdbpy_initialize_breakpoints (void)
{
int i;
breakpoint_object_type.tp_new = PyType_GenericNew;
if (PyType_Ready (&breakpoint_object_type) < 0)
- return;
+ return -1;
Py_INCREF (&breakpoint_object_type);
- PyModule_AddObject (gdb_module, "Breakpoint",
- (PyObject *) &breakpoint_object_type);
+ if (PyModule_AddObject (gdb_module, "Breakpoint",
+ (PyObject *) &breakpoint_object_type) < 0)
+ return -1;
observer_attach_breakpoint_created (gdbpy_breakpoint_created);
observer_attach_breakpoint_deleted (gdbpy_breakpoint_deleted);
/* Cast needed for Python 2.4. */
(char *) pybp_codes[i].name,
pybp_codes[i].code) < 0)
- return;
+ return -1;
}
/* Add watchpoint types constants. */
/* Cast needed for Python 2.4. */
(char *) pybp_watch_types[i].name,
pybp_watch_types[i].code) < 0)
- return;
+ return -1;
}
+ return 0;
}
\f
/* Initialize the 'commands' code. */
-void
+int
gdbpy_initialize_commands (void)
{
int i;
cmdpy_object_type.tp_new = PyType_GenericNew;
if (PyType_Ready (&cmdpy_object_type) < 0)
- return;
+ return -1;
/* Note: alias and user are special; pseudo appears to be unused,
and there is no reason to expose tui or xdb, I think. */
|| PyModule_AddIntConstant (gdb_module, "COMMAND_MAINTENANCE",
class_maintenance) < 0
|| PyModule_AddIntConstant (gdb_module, "COMMAND_USER", class_user) < 0)
- return;
+ return -1;
for (i = 0; i < N_COMPLETERS; ++i)
{
if (PyModule_AddIntConstant (gdb_module, completers[i].name, i) < 0)
- return;
+ return -1;
}
Py_INCREF (&cmdpy_object_type);
- PyModule_AddObject (gdb_module, "Command",
- (PyObject *) &cmdpy_object_type);
+ if (PyModule_AddObject (gdb_module, "Command",
+ (PyObject *) &cmdpy_object_type) < 0)
+ return -1;
invoke_cst = PyString_FromString ("invoke");
+ if (invoke_cst == NULL)
+ return -1;
complete_cst = PyString_FromString ("complete");
+ if (complete_cst == NULL)
+ return -1;
+
+ return 0;
}
\f
/* Initialize the Python event code. */
-void
+int
gdbpy_initialize_event (void)
{
- gdbpy_initialize_event_generic (&event_object_type,
- "Event");
+ return gdbpy_initialize_event_generic (&event_object_type,
+ "Event");
}
/* Initialize the given event type. If BASE is not NULL it will
0 /* tp_alloc */ \
}; \
\
-void \
+int \
gdbpy_initialize_##name##_event (void) \
{ \
- gdbpy_initialize_event_generic (&name##_event_object_type, \
- py_name); \
+ return gdbpy_initialize_event_generic (&name##_event_object_type, \
+ py_name); \
}
typedef struct
/* Initialize the Python event registry code. */
-void
+int
gdbpy_initialize_eventregistry (void)
{
if (PyType_Ready (&eventregistry_object_type) < 0)
- return;
+ return -1;
Py_INCREF (&eventregistry_object_type);
- PyModule_AddObject (gdb_module, "EventRegistry",
- (PyObject *) &eventregistry_object_type);
+ return PyModule_AddObject (gdb_module, "EventRegistry",
+ (PyObject *) &eventregistry_object_type);
}
/* Retern the number of listeners currently connected to this
return -1;
}
-void
+int
gdbpy_initialize_py_events (void)
{
#ifdef IS_PY3K
#endif
if (!gdb_py_events.module)
- goto fail;
+ return -1;
if (add_new_registry (&gdb_py_events.stop, "stop") < 0)
- goto fail;
+ return -1;
if (add_new_registry (&gdb_py_events.cont, "cont") < 0)
- goto fail;
+ return -1;
if (add_new_registry (&gdb_py_events.exited, "exited") < 0)
- goto fail;
+ return -1;
if (add_new_registry (&gdb_py_events.new_objfile, "new_objfile") < 0)
- goto fail;
+ return -1;
#ifndef IS_PY3K
Py_INCREF (gdb_py_events.module);
if (PyModule_AddObject (gdb_module,
"events",
(PyObject *) gdb_py_events.module) < 0)
- goto fail;
-
- return;
+ return -1;
- fail:
- gdbpy_print_stack ();
+ return 0;
}
/* Initialize the Python finish breakpoint code. */
-void
+int
gdbpy_initialize_finishbreakpoints (void)
{
if (PyType_Ready (&finish_breakpoint_object_type) < 0)
- return;
+ return -1;
Py_INCREF (&finish_breakpoint_object_type);
- PyModule_AddObject (gdb_module, "FinishBreakpoint",
- (PyObject *) &finish_breakpoint_object_type);
+ if (PyModule_AddObject (gdb_module, "FinishBreakpoint",
+ (PyObject *) &finish_breakpoint_object_type) < 0)
+ return -1;
observer_attach_normal_stop (bpfinishpy_handle_stop);
observer_attach_inferior_exit (bpfinishpy_handle_exit);
+
+ return 0;
}
static PyGetSetDef finish_breakpoint_object_getset[] = {
/* Sets up the Frame API in the gdb module. */
-void
+int
gdbpy_initialize_frames (void)
{
frame_object_type.tp_new = PyType_GenericNew;
if (PyType_Ready (&frame_object_type) < 0)
- return;
+ return -1;
/* Note: These would probably be best exposed as class attributes of
Frame, but I don't know how to do it except by messing with the
type's dictionary. That seems too messy. */
- PyModule_AddIntConstant (gdb_module, "NORMAL_FRAME", NORMAL_FRAME);
- PyModule_AddIntConstant (gdb_module, "DUMMY_FRAME", DUMMY_FRAME);
- PyModule_AddIntConstant (gdb_module, "INLINE_FRAME", INLINE_FRAME);
- PyModule_AddIntConstant (gdb_module, "TAILCALL_FRAME", TAILCALL_FRAME);
- PyModule_AddIntConstant (gdb_module, "SIGTRAMP_FRAME", SIGTRAMP_FRAME);
- PyModule_AddIntConstant (gdb_module, "ARCH_FRAME", ARCH_FRAME);
- PyModule_AddIntConstant (gdb_module, "SENTINEL_FRAME", SENTINEL_FRAME);
+ if (PyModule_AddIntConstant (gdb_module, "NORMAL_FRAME", NORMAL_FRAME) < 0
+ || PyModule_AddIntConstant (gdb_module, "DUMMY_FRAME", DUMMY_FRAME) < 0
+ || PyModule_AddIntConstant (gdb_module, "INLINE_FRAME", INLINE_FRAME) < 0
+ || PyModule_AddIntConstant (gdb_module, "TAILCALL_FRAME",
+ TAILCALL_FRAME) < 0
+ || PyModule_AddIntConstant (gdb_module, "SIGTRAMP_FRAME",
+ SIGTRAMP_FRAME) < 0
+ || PyModule_AddIntConstant (gdb_module, "ARCH_FRAME", ARCH_FRAME) < 0
+ || PyModule_AddIntConstant (gdb_module, "SENTINEL_FRAME",
+ SENTINEL_FRAME) < 0)
+ return -1;
#define SET(name, description) \
- PyModule_AddIntConstant (gdb_module, "FRAME_"#name, name);
+ if (PyModule_AddIntConstant (gdb_module, "FRAME_"#name, name) < 0) \
+ return -1;
#define FIRST_ERROR(name) \
- PyModule_AddIntConstant (gdb_module, "FRAME_"#name, name);
+ if (PyModule_AddIntConstant (gdb_module, "FRAME_"#name, name) < 0) \
+ return -1;
#include "unwind_stop_reasons.def"
#undef SET
+#undef FIRST_ERROR
Py_INCREF (&frame_object_type);
- PyModule_AddObject (gdb_module, "Frame", (PyObject *) &frame_object_type);
+ return PyModule_AddObject (gdb_module, "Frame",
+ (PyObject *) &frame_object_type);
}
\f
/* Initialize internal function support. */
-void
+int
gdbpy_initialize_functions (void)
{
fnpy_object_type.tp_new = PyType_GenericNew;
if (PyType_Ready (&fnpy_object_type) < 0)
- return;
+ return -1;
Py_INCREF (&fnpy_object_type);
- PyModule_AddObject (gdb_module, "Function", (PyObject *) &fnpy_object_type);
+ return PyModule_AddObject (gdb_module, "Function",
+ (PyObject *) &fnpy_object_type);
}
\f
and prevent conflicts. For now, this file implements a
sys.meta_path finder that simply fails to import the readline
module. */
- PyRun_SimpleString ("\
+ if (PyRun_SimpleString ("\
import sys\n\
\n\
class GdbRemoveReadlineFinder:\n\
raise ImportError('readline module disabled under GDB')\n\
\n\
sys.meta_path.append(GdbRemoveReadlineFinder())\n\
-");
-
- PyOS_ReadlineFunctionPointer = gdbpy_readline_wrapper;
+") == 0)
+ PyOS_ReadlineFunctionPointer = gdbpy_readline_wrapper;
}
return inf_obj;
}
-void
+int
gdbpy_initialize_inferior (void)
{
if (PyType_Ready (&inferior_object_type) < 0)
- return;
+ return -1;
Py_INCREF (&inferior_object_type);
- PyModule_AddObject (gdb_module, "Inferior",
- (PyObject *) &inferior_object_type);
+ if (PyModule_AddObject (gdb_module, "Inferior",
+ (PyObject *) &inferior_object_type) < 0)
+ return -1;
infpy_inf_data_key =
register_inferior_data_with_cleanup (NULL, py_free_inferior);
membuf_object_type.tp_new = PyType_GenericNew;
if (PyType_Ready (&membuf_object_type) < 0)
- return;
+ return -1;
Py_INCREF (&membuf_object_type);
- PyModule_AddObject (gdb_module, "Membuf", (PyObject *)
- &membuf_object_type);
+ return PyModule_AddObject (gdb_module, "Membuf", (PyObject *)
+ &membuf_object_type);
}
static PyGetSetDef inferior_object_getset[] =
-void
+int
gdbpy_initialize_thread (void)
{
if (PyType_Ready (&thread_object_type) < 0)
- return;
+ return -1;
Py_INCREF (&thread_object_type);
- PyModule_AddObject (gdb_module, "InferiorThread",
- (PyObject *) &thread_object_type);
+ return PyModule_AddObject (gdb_module, "InferiorThread",
+ (PyObject *) &thread_object_type);
}
return (PyObject *) str_obj;
}
-void
+int
gdbpy_initialize_lazy_string (void)
{
if (PyType_Ready (&lazy_string_object_type) < 0)
- return;
+ return -1;
Py_INCREF (&lazy_string_object_type);
+ return 0;
}
/* Determine whether the printer object pointed to by OBJ is a
return (PyObject *) object;
}
-void
+int
gdbpy_initialize_objfile (void)
{
objfpy_objfile_data_key
= register_objfile_data_with_cleanup (NULL, py_free_objfile);
if (PyType_Ready (&objfile_object_type) < 0)
- return;
+ return -1;
Py_INCREF (&objfile_object_type);
- PyModule_AddObject (gdb_module, "Objfile",
- (PyObject *) &objfile_object_type);
+ return PyModule_AddObject (gdb_module, "Objfile",
+ (PyObject *) &objfile_object_type);
}
\f
\f
/* Initialize the 'parameters' module. */
-void
+int
gdbpy_initialize_parameters (void)
{
int i;
parmpy_object_type.tp_new = PyType_GenericNew;
if (PyType_Ready (&parmpy_object_type) < 0)
- return;
+ return -1;
set_doc_cst = PyString_FromString ("set_doc");
if (! set_doc_cst)
- return;
+ return -1;
show_doc_cst = PyString_FromString ("show_doc");
if (! show_doc_cst)
- return;
+ return -1;
for (i = 0; parm_constants[i].name; ++i)
{
if (PyModule_AddIntConstant (gdb_module,
parm_constants[i].name,
parm_constants[i].value) < 0)
- return;
+ return -1;
}
Py_INCREF (&parmpy_object_type);
- PyModule_AddObject (gdb_module, "Parameter",
- (PyObject *) &parmpy_object_type);
+ return PyModule_AddObject (gdb_module, "Parameter",
+ (PyObject *) &parmpy_object_type);
}
\f
return (PyObject *) object;
}
-void
+int
gdbpy_initialize_pspace (void)
{
pspy_pspace_data_key
= register_program_space_data_with_cleanup (NULL, py_free_pspace);
if (PyType_Ready (&pspace_object_type) < 0)
- return;
+ return -1;
Py_INCREF (&pspace_object_type);
- PyModule_AddObject (gdb_module, "Progspace",
- (PyObject *) &pspace_object_type);
+ return PyModule_AddObject (gdb_module, "Progspace",
+ (PyObject *) &pspace_object_type);
}
\f
}
}
-void
+int
gdbpy_initialize_symbols (void)
{
if (PyType_Ready (&symbol_object_type) < 0)
- return;
+ return -1;
/* Register an objfile "free" callback so we can properly
invalidate symbol when an object file that is about to be
sympy_objfile_data_key
= register_objfile_data_with_cleanup (NULL, del_objfile_symbols);
- PyModule_AddIntConstant (gdb_module, "SYMBOL_LOC_UNDEF", LOC_UNDEF);
- PyModule_AddIntConstant (gdb_module, "SYMBOL_LOC_CONST", LOC_CONST);
- PyModule_AddIntConstant (gdb_module, "SYMBOL_LOC_STATIC", LOC_STATIC);
- PyModule_AddIntConstant (gdb_module, "SYMBOL_LOC_REGISTER", LOC_REGISTER);
- PyModule_AddIntConstant (gdb_module, "SYMBOL_LOC_ARG", LOC_ARG);
- PyModule_AddIntConstant (gdb_module, "SYMBOL_LOC_REF_ARG", LOC_REF_ARG);
- PyModule_AddIntConstant (gdb_module, "SYMBOL_LOC_LOCAL", LOC_LOCAL);
- PyModule_AddIntConstant (gdb_module, "SYMBOL_LOC_TYPEDEF", LOC_TYPEDEF);
- PyModule_AddIntConstant (gdb_module, "SYMBOL_LOC_LABEL", LOC_LABEL);
- PyModule_AddIntConstant (gdb_module, "SYMBOL_LOC_BLOCK", LOC_BLOCK);
- PyModule_AddIntConstant (gdb_module, "SYMBOL_LOC_CONST_BYTES",
- LOC_CONST_BYTES);
- PyModule_AddIntConstant (gdb_module, "SYMBOL_LOC_UNRESOLVED",
- LOC_UNRESOLVED);
- PyModule_AddIntConstant (gdb_module, "SYMBOL_LOC_OPTIMIZED_OUT",
- LOC_OPTIMIZED_OUT);
- PyModule_AddIntConstant (gdb_module, "SYMBOL_LOC_COMPUTED", LOC_COMPUTED);
- PyModule_AddIntConstant (gdb_module, "SYMBOL_LOC_REGPARM_ADDR",
- LOC_REGPARM_ADDR);
- PyModule_AddIntConstant (gdb_module, "SYMBOL_UNDEF_DOMAIN", UNDEF_DOMAIN);
- PyModule_AddIntConstant (gdb_module, "SYMBOL_VAR_DOMAIN", VAR_DOMAIN);
- PyModule_AddIntConstant (gdb_module, "SYMBOL_STRUCT_DOMAIN", STRUCT_DOMAIN);
- PyModule_AddIntConstant (gdb_module, "SYMBOL_LABEL_DOMAIN", LABEL_DOMAIN);
- PyModule_AddIntConstant (gdb_module, "SYMBOL_VARIABLES_DOMAIN",
- VARIABLES_DOMAIN);
- PyModule_AddIntConstant (gdb_module, "SYMBOL_FUNCTIONS_DOMAIN",
- FUNCTIONS_DOMAIN);
- PyModule_AddIntConstant (gdb_module, "SYMBOL_TYPES_DOMAIN", TYPES_DOMAIN);
+ if (PyModule_AddIntConstant (gdb_module, "SYMBOL_LOC_UNDEF", LOC_UNDEF) < 0
+ || PyModule_AddIntConstant (gdb_module, "SYMBOL_LOC_CONST",
+ LOC_CONST) < 0
+ || PyModule_AddIntConstant (gdb_module, "SYMBOL_LOC_STATIC",
+ LOC_STATIC) < 0
+ || PyModule_AddIntConstant (gdb_module, "SYMBOL_LOC_REGISTER",
+ LOC_REGISTER) < 0
+ || PyModule_AddIntConstant (gdb_module, "SYMBOL_LOC_ARG",
+ LOC_ARG) < 0
+ || PyModule_AddIntConstant (gdb_module, "SYMBOL_LOC_REF_ARG",
+ LOC_REF_ARG) < 0
+ || PyModule_AddIntConstant (gdb_module, "SYMBOL_LOC_LOCAL",
+ LOC_LOCAL) < 0
+ || PyModule_AddIntConstant (gdb_module, "SYMBOL_LOC_TYPEDEF",
+ LOC_TYPEDEF) < 0
+ || PyModule_AddIntConstant (gdb_module, "SYMBOL_LOC_LABEL",
+ LOC_LABEL) < 0
+ || PyModule_AddIntConstant (gdb_module, "SYMBOL_LOC_BLOCK",
+ LOC_BLOCK) < 0
+ || PyModule_AddIntConstant (gdb_module, "SYMBOL_LOC_CONST_BYTES",
+ LOC_CONST_BYTES) < 0
+ || PyModule_AddIntConstant (gdb_module, "SYMBOL_LOC_UNRESOLVED",
+ LOC_UNRESOLVED) < 0
+ || PyModule_AddIntConstant (gdb_module, "SYMBOL_LOC_OPTIMIZED_OUT",
+ LOC_OPTIMIZED_OUT) < 0
+ || PyModule_AddIntConstant (gdb_module, "SYMBOL_LOC_COMPUTED",
+ LOC_COMPUTED) < 0
+ || PyModule_AddIntConstant (gdb_module, "SYMBOL_LOC_REGPARM_ADDR",
+ LOC_REGPARM_ADDR) < 0
+ || PyModule_AddIntConstant (gdb_module, "SYMBOL_UNDEF_DOMAIN",
+ UNDEF_DOMAIN) < 0
+ || PyModule_AddIntConstant (gdb_module, "SYMBOL_VAR_DOMAIN",
+ VAR_DOMAIN) < 0
+ || PyModule_AddIntConstant (gdb_module, "SYMBOL_STRUCT_DOMAIN",
+ STRUCT_DOMAIN) < 0
+ || PyModule_AddIntConstant (gdb_module, "SYMBOL_LABEL_DOMAIN",
+ LABEL_DOMAIN) < 0
+ || PyModule_AddIntConstant (gdb_module, "SYMBOL_VARIABLES_DOMAIN",
+ VARIABLES_DOMAIN) < 0
+ || PyModule_AddIntConstant (gdb_module, "SYMBOL_FUNCTIONS_DOMAIN",
+ FUNCTIONS_DOMAIN) < 0
+ || PyModule_AddIntConstant (gdb_module, "SYMBOL_TYPES_DOMAIN",
+ TYPES_DOMAIN) < 0)
+ return -1;
Py_INCREF (&symbol_object_type);
- PyModule_AddObject (gdb_module, "Symbol", (PyObject *) &symbol_object_type);
+ return PyModule_AddObject (gdb_module, "Symbol",
+ (PyObject *) &symbol_object_type);
}
\f
}
}
-void
+int
gdbpy_initialize_symtabs (void)
{
symtab_object_type.tp_new = PyType_GenericNew;
if (PyType_Ready (&symtab_object_type) < 0)
- return;
+ return -1;
sal_object_type.tp_new = PyType_GenericNew;
if (PyType_Ready (&sal_object_type) < 0)
- return;
+ return -1;
/* Register an objfile "free" callback so we can properly
invalidate symbol tables, and symbol table and line data
= register_objfile_data_with_cleanup (NULL, del_objfile_sal);
Py_INCREF (&symtab_object_type);
- PyModule_AddObject (gdb_module, "Symtab",
- (PyObject *) &symtab_object_type);
+ if (PyModule_AddObject (gdb_module, "Symtab",
+ (PyObject *) &symtab_object_type) < 0)
+ return -1;
Py_INCREF (&sal_object_type);
- PyModule_AddObject (gdb_module, "Symtab_and_line",
- (PyObject *) &sal_object_type);
+ return PyModule_AddObject (gdb_module, "Symtab_and_line",
+ (PyObject *) &sal_object_type);
}
\f
return (PyObject *) type_to_type_object (type);
}
-void
+int
gdbpy_initialize_types (void)
{
int i;
= register_objfile_data_with_cleanup (save_objfile_types, NULL);
if (PyType_Ready (&type_object_type) < 0)
- return;
+ return -1;
if (PyType_Ready (&field_object_type) < 0)
- return;
+ return -1;
if (PyType_Ready (&type_iterator_object_type) < 0)
- return;
+ return -1;
for (i = 0; pyty_codes[i].name; ++i)
{
/* Cast needed for Python 2.4. */
(char *) pyty_codes[i].name,
pyty_codes[i].code) < 0)
- return;
+ return -1;
}
Py_INCREF (&type_object_type);
- PyModule_AddObject (gdb_module, "Type", (PyObject *) &type_object_type);
+ if (PyModule_AddObject (gdb_module, "Type",
+ (PyObject *) &type_object_type) < 0)
+ return -1;
Py_INCREF (&type_iterator_object_type);
- PyModule_AddObject (gdb_module, "TypeIterator",
- (PyObject *) &type_iterator_object_type);
+ if (PyModule_AddObject (gdb_module, "TypeIterator",
+ (PyObject *) &type_iterator_object_type) < 0)
+ return -1;
Py_INCREF (&field_object_type);
- PyModule_AddObject (gdb_module, "Field", (PyObject *) &field_object_type);
+ return PyModule_AddObject (gdb_module, "Field",
+ (PyObject *) &field_object_type);
}
\f
return PyObject_TypeCheck (obj, &value_object_type);
}
-void
+int
gdbpy_initialize_values (void)
{
if (PyType_Ready (&value_object_type) < 0)
- return;
+ return -1;
Py_INCREF (&value_object_type);
- PyModule_AddObject (gdb_module, "Value", (PyObject *) &value_object_type);
-
- values_in_python = NULL;
+ return PyModule_AddObject (gdb_module, "Value",
+ (PyObject *) &value_object_type);
}
\f
struct gdbarch *arch_object_to_gdbarch (PyObject *obj);
void gdbpy_initialize_gdb_readline (void);
-void gdbpy_initialize_auto_load (void);
-void gdbpy_initialize_values (void);
-void gdbpy_initialize_frames (void);
-void gdbpy_initialize_symtabs (void);
-void gdbpy_initialize_commands (void);
-void gdbpy_initialize_symbols (void);
-void gdbpy_initialize_symtabs (void);
-void gdbpy_initialize_blocks (void);
-void gdbpy_initialize_types (void);
-void gdbpy_initialize_functions (void);
-void gdbpy_initialize_pspace (void);
-void gdbpy_initialize_objfile (void);
-void gdbpy_initialize_breakpoints (void);
-void gdbpy_initialize_finishbreakpoints (void);
-void gdbpy_initialize_lazy_string (void);
-void gdbpy_initialize_parameters (void);
-void gdbpy_initialize_thread (void);
-void gdbpy_initialize_inferior (void);
-void gdbpy_initialize_eventregistry (void);
-void gdbpy_initialize_event (void);
-void gdbpy_initialize_py_events (void);
-void gdbpy_initialize_stop_event (void);
-void gdbpy_initialize_signal_event (void);
-void gdbpy_initialize_breakpoint_event (void);
-void gdbpy_initialize_continue_event (void);
-void gdbpy_initialize_exited_event (void);
-void gdbpy_initialize_thread_event (void);
-void gdbpy_initialize_new_objfile_event (void);
-void gdbpy_initialize_arch (void);
+int gdbpy_initialize_auto_load (void)
+ CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION;
+int gdbpy_initialize_values (void)
+ CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION;
+int gdbpy_initialize_frames (void)
+ CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION;
+int gdbpy_initialize_symtabs (void)
+ CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION;
+int gdbpy_initialize_commands (void)
+ CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION;
+int gdbpy_initialize_symbols (void)
+ CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION;
+int gdbpy_initialize_symtabs (void)
+ CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION;
+int gdbpy_initialize_blocks (void)
+ CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION;
+int gdbpy_initialize_types (void)
+ CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION;
+int gdbpy_initialize_functions (void)
+ CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION;
+int gdbpy_initialize_pspace (void)
+ CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION;
+int gdbpy_initialize_objfile (void)
+ CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION;
+int gdbpy_initialize_breakpoints (void)
+ CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION;
+int gdbpy_initialize_finishbreakpoints (void)
+ CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION;
+int gdbpy_initialize_lazy_string (void)
+ CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION;
+int gdbpy_initialize_parameters (void)
+ CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION;
+int gdbpy_initialize_thread (void)
+ CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION;
+int gdbpy_initialize_inferior (void)
+ CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION;
+int gdbpy_initialize_eventregistry (void)
+ CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION;
+int gdbpy_initialize_event (void)
+ CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION;
+int gdbpy_initialize_py_events (void)
+ CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION;
+int gdbpy_initialize_stop_event (void)
+ CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION;
+int gdbpy_initialize_signal_event (void)
+ CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION;
+int gdbpy_initialize_breakpoint_event (void)
+ CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION;
+int gdbpy_initialize_continue_event (void)
+ CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION;
+int gdbpy_initialize_exited_event (void)
+ CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION;
+int gdbpy_initialize_thread_event (void)
+ CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION;
+int gdbpy_initialize_new_objfile_event (void)
+ CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION;
+int gdbpy_initialize_arch (void)
+ CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION;
struct cleanup *make_cleanup_py_decref (PyObject *py);
struct cleanup *make_cleanup_py_xdecref (PyObject *py);
#include "interps.h"
#include "event-top.h"
+/* True if Python has been successfully initialized, false
+ otherwise. */
+
+int gdb_python_initialized;
+
static PyMethodDef GdbMethods[];
#ifdef IS_PY3K
}
/* Initialize the Python event handler. */
-static void
+static int
gdbpy_initialize_events (void)
{
if (serial_pipe (gdbpy_event_fds) == 0)
gdbpy_event_list_end = &gdbpy_event_list;
serial_async (gdbpy_event_fds[0], gdbpy_run_events, NULL);
}
+
+ return 0;
}
\f
#else
gdb_module = Py_InitModule ("_gdb", GdbMethods);
#endif
+ if (gdb_module == NULL)
+ goto fail;
/* The casts to (char*) are for python 2.4. */
- PyModule_AddStringConstant (gdb_module, "VERSION", (char*) version);
- PyModule_AddStringConstant (gdb_module, "HOST_CONFIG", (char*) host_name);
- PyModule_AddStringConstant (gdb_module, "TARGET_CONFIG",
- (char*) target_name);
+ if (PyModule_AddStringConstant (gdb_module, "VERSION", (char*) version) < 0
+ || PyModule_AddStringConstant (gdb_module, "HOST_CONFIG",
+ (char*) host_name) < 0
+ || PyModule_AddStringConstant (gdb_module, "TARGET_CONFIG",
+ (char*) target_name) < 0)
+ goto fail;
/* Add stream constants. */
- PyModule_AddIntConstant (gdb_module, "STDOUT", 0);
- PyModule_AddIntConstant (gdb_module, "STDERR", 1);
- PyModule_AddIntConstant (gdb_module, "STDLOG", 2);
+ if (PyModule_AddIntConstant (gdb_module, "STDOUT", 0) < 0
+ || PyModule_AddIntConstant (gdb_module, "STDERR", 1) < 0
+ || PyModule_AddIntConstant (gdb_module, "STDLOG", 2) < 0)
+ goto fail;
gdbpy_gdb_error = PyErr_NewException ("gdb.error", PyExc_RuntimeError, NULL);
- PyModule_AddObject (gdb_module, "error", gdbpy_gdb_error);
+ if (gdbpy_gdb_error == NULL
+ || PyModule_AddObject (gdb_module, "error", gdbpy_gdb_error) < 0)
+ goto fail;
gdbpy_gdb_memory_error = PyErr_NewException ("gdb.MemoryError",
gdbpy_gdb_error, NULL);
- PyModule_AddObject (gdb_module, "MemoryError", gdbpy_gdb_memory_error);
+ if (gdbpy_gdb_memory_error == NULL
+ || PyModule_AddObject (gdb_module, "MemoryError",
+ gdbpy_gdb_memory_error) < 0)
+ goto fail;
gdbpy_gdberror_exc = PyErr_NewException ("gdb.GdbError", NULL, NULL);
- PyModule_AddObject (gdb_module, "GdbError", gdbpy_gdberror_exc);
+ if (gdbpy_gdberror_exc == NULL
+ || PyModule_AddObject (gdb_module, "GdbError", gdbpy_gdberror_exc) < 0)
+ goto fail;
gdbpy_initialize_gdb_readline ();
- gdbpy_initialize_auto_load ();
- gdbpy_initialize_values ();
- gdbpy_initialize_frames ();
- gdbpy_initialize_commands ();
- gdbpy_initialize_symbols ();
- gdbpy_initialize_symtabs ();
- gdbpy_initialize_blocks ();
- gdbpy_initialize_functions ();
- gdbpy_initialize_parameters ();
- gdbpy_initialize_types ();
- gdbpy_initialize_pspace ();
- gdbpy_initialize_objfile ();
- gdbpy_initialize_breakpoints ();
- gdbpy_initialize_finishbreakpoints ();
- gdbpy_initialize_lazy_string ();
- gdbpy_initialize_thread ();
- gdbpy_initialize_inferior ();
- gdbpy_initialize_events ();
-
- gdbpy_initialize_eventregistry ();
- gdbpy_initialize_py_events ();
- gdbpy_initialize_event ();
- gdbpy_initialize_stop_event ();
- gdbpy_initialize_signal_event ();
- gdbpy_initialize_breakpoint_event ();
- gdbpy_initialize_continue_event ();
- gdbpy_initialize_exited_event ();
- gdbpy_initialize_thread_event ();
- gdbpy_initialize_new_objfile_event () ;
- gdbpy_initialize_arch ();
+
+ if (gdbpy_initialize_auto_load () < 0
+ || gdbpy_initialize_values () < 0
+ || gdbpy_initialize_frames () < 0
+ || gdbpy_initialize_commands () < 0
+ || gdbpy_initialize_symbols () < 0
+ || gdbpy_initialize_symtabs () < 0
+ || gdbpy_initialize_blocks () < 0
+ || gdbpy_initialize_functions () < 0
+ || gdbpy_initialize_parameters () < 0
+ || gdbpy_initialize_types () < 0
+ || gdbpy_initialize_pspace () < 0
+ || gdbpy_initialize_objfile () < 0
+ || gdbpy_initialize_breakpoints () < 0
+ || gdbpy_initialize_finishbreakpoints () < 0
+ || gdbpy_initialize_lazy_string () < 0
+ || gdbpy_initialize_thread () < 0
+ || gdbpy_initialize_inferior () < 0
+ || gdbpy_initialize_events () < 0
+ || gdbpy_initialize_eventregistry () < 0
+ || gdbpy_initialize_py_events () < 0
+ || gdbpy_initialize_event () < 0
+ || gdbpy_initialize_stop_event () < 0
+ || gdbpy_initialize_signal_event () < 0
+ || gdbpy_initialize_breakpoint_event () < 0
+ || gdbpy_initialize_continue_event () < 0
+ || gdbpy_initialize_exited_event () < 0
+ || gdbpy_initialize_thread_event () < 0
+ || gdbpy_initialize_new_objfile_event () < 0
+ || gdbpy_initialize_arch () < 0)
+ goto fail;
observer_attach_before_prompt (before_prompt_hook);
gdbpy_to_string_cst = PyString_FromString ("to_string");
+ if (gdbpy_to_string_cst == NULL)
+ goto fail;
gdbpy_children_cst = PyString_FromString ("children");
+ if (gdbpy_children_cst == NULL)
+ goto fail;
gdbpy_display_hint_cst = PyString_FromString ("display_hint");
+ if (gdbpy_display_hint_cst == NULL)
+ goto fail;
gdbpy_doc_cst = PyString_FromString ("__doc__");
+ if (gdbpy_doc_cst == NULL)
+ goto fail;
gdbpy_enabled_cst = PyString_FromString ("enabled");
+ if (gdbpy_enabled_cst == NULL)
+ goto fail;
gdbpy_value_cst = PyString_FromString ("value");
+ if (gdbpy_value_cst == NULL)
+ goto fail;
/* Release the GIL while gdb runs. */
PyThreadState_Swap (NULL);
PyEval_ReleaseLock ();
make_final_cleanup (finalize_python, NULL);
+
+ gdb_python_initialized = 1;
+ return;
+
+ fail:
+ gdbpy_print_stack ();
+ /* Do not set 'gdb_python_initialized'. */
+ return;
+
#endif /* HAVE_PYTHON */
}