Change event code to use gdbpy_ref
This changes the event code in the Python layer to use gdbpy_ref, simplifying the logic in many places. It also changes evpy_emit_event not to steal a reference to its argument. This is simpler to do now that gdbpy_ref is in use; it's also a reasonable cleanup in its own right. While doing this I realized that evpy_emit_event should not be calling gdbpy_print_stack (all the outermost callers do this if needed), so I removed this as well. 2017-01-10 Tom Tromey <tom@tromey.com> * python/py-threadevent.c (create_thread_event_object): Use gdbpy_ref. * python/py-stopevent.c (create_stop_event_object): Simplify. (emit_stop_event): Use gdbpy_ref. * python/py-signalevent.c (create_signal_event_object): Use gdbpy_ref. * python/py-newobjfileevent.c (create_new_objfile_event_object) (emit_new_objfile_event, create_clear_objfiles_event_object) (emit_clear_objfiles_event): Use gdbpy_ref. * python/py-infevents.c (create_inferior_call_event_object) (create_register_changed_event_object) (create_memory_changed_event_object, emit_inferior_call_event) (emit_memory_changed_event, emit_register_changed_event): Use gdbpy_ref. * python/py-exitedevent.c (create_exited_event_object) (emit_exited_event): Use gdbpy_ref. * python/py-event.h (evpy_emit_event): Remove CPYCHECKER_STEALS_REFERENCE_TO_ARG annotation. * python/py-event.c (evpy_emit_event): Use gdbpy_ref. * python/py-continueevent.c (emit_continue_event): Use gdbpy_ref. * python/py-breakpoint.c (gdbpy_breakpoint_created) (gdbpy_breakpoint_deleted, gdbpy_breakpoint_modified): Use gdbpy_ref. * python/py-bpevent.c (create_breakpoint_event_object): Use gdbpy_ref.
This commit is contained in:
parent
a68ff33e0d
commit
abf5651e47
12 changed files with 167 additions and 272 deletions
|
@ -23,16 +23,7 @@
|
|||
PyObject *
|
||||
create_stop_event_object (PyTypeObject *py_type)
|
||||
{
|
||||
PyObject *stop_event_obj = create_thread_event_object (py_type);
|
||||
|
||||
if (!stop_event_obj)
|
||||
goto fail;
|
||||
|
||||
return stop_event_obj;
|
||||
|
||||
fail:
|
||||
Py_XDECREF (stop_event_obj);
|
||||
return NULL;
|
||||
return create_thread_event_object (py_type);
|
||||
}
|
||||
|
||||
/* Callback observers when a stop event occurs. This function will create a
|
||||
|
@ -45,8 +36,8 @@ create_stop_event_object (PyTypeObject *py_type)
|
|||
int
|
||||
emit_stop_event (struct bpstats *bs, enum gdb_signal stop_signal)
|
||||
{
|
||||
PyObject *stop_event_obj = NULL; /* Appease GCC warning. */
|
||||
PyObject *list = NULL;
|
||||
gdbpy_ref stop_event_obj;
|
||||
gdbpy_ref list;
|
||||
PyObject *first_bp = NULL;
|
||||
struct bpstats *current_bs;
|
||||
|
||||
|
@ -64,13 +55,13 @@ emit_stop_event (struct bpstats *bs, enum gdb_signal stop_signal)
|
|||
|
||||
if (list == NULL)
|
||||
{
|
||||
list = PyList_New (0);
|
||||
if (!list)
|
||||
goto fail;
|
||||
list.reset (PyList_New (0));
|
||||
if (list == NULL)
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (PyList_Append (list, current_py_bp))
|
||||
goto fail;
|
||||
if (PyList_Append (list.get (), current_py_bp))
|
||||
return -1;
|
||||
|
||||
if (first_bp == NULL)
|
||||
first_bp = current_py_bp;
|
||||
|
@ -79,36 +70,31 @@ emit_stop_event (struct bpstats *bs, enum gdb_signal stop_signal)
|
|||
|
||||
if (list != NULL)
|
||||
{
|
||||
stop_event_obj = create_breakpoint_event_object (list, first_bp);
|
||||
if (!stop_event_obj)
|
||||
goto fail;
|
||||
Py_DECREF (list);
|
||||
stop_event_obj.reset (create_breakpoint_event_object (list.get (),
|
||||
first_bp));
|
||||
if (stop_event_obj == NULL)
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Check if the signal is "Signal 0" or "Trace/breakpoint trap". */
|
||||
if (stop_signal != GDB_SIGNAL_0
|
||||
&& stop_signal != GDB_SIGNAL_TRAP)
|
||||
{
|
||||
stop_event_obj =
|
||||
create_signal_event_object (stop_signal);
|
||||
if (!stop_event_obj)
|
||||
goto fail;
|
||||
stop_event_obj.reset (create_signal_event_object (stop_signal));
|
||||
if (stop_event_obj == NULL)
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* If all fails emit an unknown stop event. All event types should
|
||||
be known and this should eventually be unused. */
|
||||
if (!stop_event_obj)
|
||||
if (stop_event_obj == NULL)
|
||||
{
|
||||
stop_event_obj = create_stop_event_object (&stop_event_object_type);
|
||||
if (!stop_event_obj)
|
||||
goto fail;
|
||||
stop_event_obj.reset (create_stop_event_object (&stop_event_object_type));
|
||||
if (stop_event_obj == NULL)
|
||||
return -1;
|
||||
}
|
||||
|
||||
return evpy_emit_event (stop_event_obj, gdb_py_events.stop);
|
||||
|
||||
fail:
|
||||
Py_XDECREF (list);
|
||||
return -1;
|
||||
return evpy_emit_event (stop_event_obj.get (), gdb_py_events.stop);
|
||||
}
|
||||
|
||||
GDBPY_NEW_EVENT_TYPE (stop,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue