Change inferior_to_inferior_object to return a gdbpy_ref
Most callers of inferior_to_inferior_object already use a gdbpy_ref, so this changes inferior_to_inferior_object to return one. Doing this revealed that create_thread_object was not correctly handling the case where inferior_to_inferior_object failed, so this patch fixes this as well. gdb/ChangeLog 2019-01-02 Tom Tromey <tom@tromey.com> * python/python-internal.h (inferior_to_inferior_object): Change return type. * python/py-exitedevent.c (create_exited_event_object): Update. * python/py-inferior.c (inferior_to_inferior_object): Return gdbpy_ref. (python_new_inferior, python_inferior_deleted) (thread_to_thread_object, delete_thread_object) (build_inferior_list, gdbpy_selected_inferior): Update. * python/py-infthread.c (create_thread_object): Update. Also fail if inferior_to_inferior_object fails.
This commit is contained in:
parent
d20172fc53
commit
61fd3e7389
5 changed files with 31 additions and 16 deletions
|
@ -1,3 +1,16 @@
|
||||||
|
2019-01-02 Tom Tromey <tom@tromey.com>
|
||||||
|
|
||||||
|
* python/python-internal.h (inferior_to_inferior_object): Change
|
||||||
|
return type.
|
||||||
|
* python/py-exitedevent.c (create_exited_event_object): Update.
|
||||||
|
* python/py-inferior.c (inferior_to_inferior_object): Return
|
||||||
|
gdbpy_ref.
|
||||||
|
(python_new_inferior, python_inferior_deleted)
|
||||||
|
(thread_to_thread_object, delete_thread_object)
|
||||||
|
(build_inferior_list, gdbpy_selected_inferior): Update.
|
||||||
|
* python/py-infthread.c (create_thread_object): Update. Also fail
|
||||||
|
if inferior_to_inferior_object fails.
|
||||||
|
|
||||||
2019-01-02 Simon Marchi <simon.marchi@ericsson.com>
|
2019-01-02 Simon Marchi <simon.marchi@ericsson.com>
|
||||||
|
|
||||||
* inferior.h (class inferior) <displaced_step_state>: New field.
|
* inferior.h (class inferior) <displaced_step_state>: New field.
|
||||||
|
|
|
@ -39,7 +39,7 @@ create_exited_event_object (const LONGEST *exit_code, struct inferior *inf)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
gdbpy_ref<inferior_object> inf_obj (inferior_to_inferior_object (inf));
|
gdbpy_ref<inferior_object> inf_obj = inferior_to_inferior_object (inf);
|
||||||
if (inf_obj == NULL || evpy_add_attribute (exited_event.get (),
|
if (inf_obj == NULL || evpy_add_attribute (exited_event.get (),
|
||||||
"inferior",
|
"inferior",
|
||||||
(PyObject *) inf_obj.get ()) < 0)
|
(PyObject *) inf_obj.get ()) < 0)
|
||||||
|
|
|
@ -208,7 +208,7 @@ python_new_objfile (struct objfile *objfile)
|
||||||
return it and increment the reference count, otherwise, create it.
|
return it and increment the reference count, otherwise, create it.
|
||||||
Return NULL on failure. */
|
Return NULL on failure. */
|
||||||
|
|
||||||
inferior_object *
|
gdbpy_ref<inferior_object>
|
||||||
inferior_to_inferior_object (struct inferior *inferior)
|
inferior_to_inferior_object (struct inferior *inferior)
|
||||||
{
|
{
|
||||||
inferior_object *inf_obj;
|
inferior_object *inf_obj;
|
||||||
|
@ -218,7 +218,7 @@ inferior_to_inferior_object (struct inferior *inferior)
|
||||||
{
|
{
|
||||||
inf_obj = PyObject_New (inferior_object, &inferior_object_type);
|
inf_obj = PyObject_New (inferior_object, &inferior_object_type);
|
||||||
if (!inf_obj)
|
if (!inf_obj)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
inf_obj->inferior = inferior;
|
inf_obj->inferior = inferior;
|
||||||
inf_obj->threads = NULL;
|
inf_obj->threads = NULL;
|
||||||
|
@ -227,13 +227,11 @@ inferior_to_inferior_object (struct inferior *inferior)
|
||||||
/* PyObject_New initializes the new object with a refcount of 1. This
|
/* PyObject_New initializes the new object with a refcount of 1. This
|
||||||
counts for the reference we are keeping in the inferior data. */
|
counts for the reference we are keeping in the inferior data. */
|
||||||
set_inferior_data (inferior, infpy_inf_data_key, inf_obj);
|
set_inferior_data (inferior, infpy_inf_data_key, inf_obj);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* We are returning a new reference. */
|
/* We are returning a new reference. */
|
||||||
Py_INCREF ((PyObject *)inf_obj);
|
gdb_assert (inf_obj != nullptr);
|
||||||
|
return gdbpy_ref<inferior_object>::new_reference (inf_obj);
|
||||||
return inf_obj;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Called when a new inferior is created. Notifies any Python event
|
/* Called when a new inferior is created. Notifies any Python event
|
||||||
|
@ -249,7 +247,7 @@ python_new_inferior (struct inferior *inf)
|
||||||
if (evregpy_no_listeners_p (gdb_py_events.new_inferior))
|
if (evregpy_no_listeners_p (gdb_py_events.new_inferior))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
gdbpy_ref<inferior_object> inf_obj (inferior_to_inferior_object (inf));
|
gdbpy_ref<inferior_object> inf_obj = inferior_to_inferior_object (inf);
|
||||||
if (inf_obj == NULL)
|
if (inf_obj == NULL)
|
||||||
{
|
{
|
||||||
gdbpy_print_stack ();
|
gdbpy_print_stack ();
|
||||||
|
@ -277,7 +275,7 @@ python_inferior_deleted (struct inferior *inf)
|
||||||
if (evregpy_no_listeners_p (gdb_py_events.inferior_deleted))
|
if (evregpy_no_listeners_p (gdb_py_events.inferior_deleted))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
gdbpy_ref<inferior_object> inf_obj (inferior_to_inferior_object (inf));
|
gdbpy_ref<inferior_object> inf_obj = inferior_to_inferior_object (inf);
|
||||||
if (inf_obj == NULL)
|
if (inf_obj == NULL)
|
||||||
{
|
{
|
||||||
gdbpy_print_stack ();
|
gdbpy_print_stack ();
|
||||||
|
@ -295,7 +293,7 @@ python_inferior_deleted (struct inferior *inf)
|
||||||
gdbpy_ref<>
|
gdbpy_ref<>
|
||||||
thread_to_thread_object (thread_info *thr)
|
thread_to_thread_object (thread_info *thr)
|
||||||
{
|
{
|
||||||
gdbpy_ref<inferior_object> inf_obj (inferior_to_inferior_object (thr->inf));
|
gdbpy_ref<inferior_object> inf_obj = inferior_to_inferior_object (thr->inf);
|
||||||
if (inf_obj == NULL)
|
if (inf_obj == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
|
@ -358,8 +356,7 @@ delete_thread_object (struct thread_info *tp, int ignore)
|
||||||
|
|
||||||
gdbpy_enter enter_py (python_gdbarch, python_language);
|
gdbpy_enter enter_py (python_gdbarch, python_language);
|
||||||
|
|
||||||
gdbpy_ref<inferior_object> inf_obj
|
gdbpy_ref<inferior_object> inf_obj = inferior_to_inferior_object (tp->inf);
|
||||||
((inferior_object *) inferior_to_inferior_object (tp->inf));
|
|
||||||
if (inf_obj == NULL)
|
if (inf_obj == NULL)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@ -466,7 +463,7 @@ static int
|
||||||
build_inferior_list (struct inferior *inf, void *arg)
|
build_inferior_list (struct inferior *inf, void *arg)
|
||||||
{
|
{
|
||||||
PyObject *list = (PyObject *) arg;
|
PyObject *list = (PyObject *) arg;
|
||||||
gdbpy_ref<inferior_object> inferior (inferior_to_inferior_object (inf));
|
gdbpy_ref<inferior_object> inferior = inferior_to_inferior_object (inf);
|
||||||
|
|
||||||
if (inferior == NULL)
|
if (inferior == NULL)
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -925,7 +922,8 @@ py_free_inferior (struct inferior *inf, void *datum)
|
||||||
PyObject *
|
PyObject *
|
||||||
gdbpy_selected_inferior (PyObject *self, PyObject *args)
|
gdbpy_selected_inferior (PyObject *self, PyObject *args)
|
||||||
{
|
{
|
||||||
return (PyObject *) inferior_to_inferior_object (current_inferior ());
|
return ((PyObject *)
|
||||||
|
inferior_to_inferior_object (current_inferior ()).release ());
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
|
|
|
@ -41,12 +41,16 @@ create_thread_object (struct thread_info *tp)
|
||||||
{
|
{
|
||||||
thread_object *thread_obj;
|
thread_object *thread_obj;
|
||||||
|
|
||||||
|
gdbpy_ref<inferior_object> inf_obj = inferior_to_inferior_object (tp->inf);
|
||||||
|
if (inf_obj == NULL)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
thread_obj = PyObject_New (thread_object, &thread_object_type);
|
thread_obj = PyObject_New (thread_object, &thread_object_type);
|
||||||
if (!thread_obj)
|
if (!thread_obj)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
thread_obj->thread = tp;
|
thread_obj->thread = tp;
|
||||||
thread_obj->inf_obj = (PyObject *) inferior_to_inferior_object (tp->inf);
|
thread_obj->inf_obj = (PyObject *) inf_obj.release ();
|
||||||
|
|
||||||
return thread_obj;
|
return thread_obj;
|
||||||
}
|
}
|
||||||
|
|
|
@ -521,7 +521,7 @@ PyObject *gdbarch_to_arch_object (struct gdbarch *gdbarch);
|
||||||
|
|
||||||
thread_object *create_thread_object (struct thread_info *tp);
|
thread_object *create_thread_object (struct thread_info *tp);
|
||||||
gdbpy_ref<> thread_to_thread_object (thread_info *thr);;
|
gdbpy_ref<> thread_to_thread_object (thread_info *thr);;
|
||||||
inferior_object *inferior_to_inferior_object (inferior *inf);
|
gdbpy_ref<inferior_object> inferior_to_inferior_object (inferior *inf);
|
||||||
|
|
||||||
const struct block *block_object_to_block (PyObject *obj);
|
const struct block *block_object_to_block (PyObject *obj);
|
||||||
struct symbol *symbol_object_to_symbol (PyObject *obj);
|
struct symbol *symbol_object_to_symbol (PyObject *obj);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue