/* Python interface to finish breakpoints
- Copyright (C) 2011-2020 Free Software Foundation, Inc.
+ Copyright (C) 2011-2021 Free Software Foundation, Inc.
This file is part of GDB.
bpfinishpy_dealloc (PyObject *self)
{
struct finish_breakpoint_object *self_bpfinish =
- (struct finish_breakpoint_object *) self;
+ (struct finish_breakpoint_object *) self;
Py_XDECREF (self_bpfinish->function_value);
Py_XDECREF (self_bpfinish->return_type);
bpfinishpy_pre_stop_hook (struct gdbpy_breakpoint_object *bp_obj)
{
struct finish_breakpoint_object *self_finishbp =
- (struct finish_breakpoint_object *) bp_obj;
+ (struct finish_breakpoint_object *) bp_obj;
/* Can compute return_value only once. */
gdb_assert (!self_finishbp->return_value);
try
{
struct value *function =
- value_object_to_value (self_finishbp->function_value);
+ value_object_to_value (self_finishbp->function_value);
struct type *value_type =
- type_object_to_type (self_finishbp->return_type);
+ type_object_to_type (self_finishbp->return_type);
struct value *ret = get_return_value (function, value_type);
if (ret)
- {
- self_finishbp->return_value = value_to_value_object (ret);
- if (!self_finishbp->return_value)
- gdbpy_print_stack ();
- }
+ {
+ self_finishbp->return_value = value_to_value_object (ret);
+ if (!self_finishbp->return_value)
+ gdbpy_print_stack ();
+ }
else
- {
- Py_INCREF (Py_None);
- self_finishbp->return_value = Py_None;
- }
+ {
+ Py_INCREF (Py_None);
+ self_finishbp->return_value = Py_None;
+ }
}
catch (const gdb_exception &except)
{
if (inferior_ptid == null_ptid)
{
PyErr_SetString (PyExc_ValueError,
- _("No thread currently selected."));
+ _("No thread currently selected."));
return -1;
}
{
internal_bp = PyObject_IsTrue (internal);
if (internal_bp == -1)
- {
- PyErr_SetString (PyExc_ValueError,
- _("The value of `internal' must be a boolean."));
- return -1;
- }
+ {
+ PyErr_SetString (PyExc_ValueError,
+ _("The value of `internal' must be a boolean."));
+ return -1;
+ }
}
/* Find the function we will return from. */
try
{
if (get_frame_pc_if_available (frame, &pc))
- {
- function = find_pc_function (pc);
- if (function != NULL)
- {
- struct type *ret_type =
+ {
+ function = find_pc_function (pc);
+ if (function != NULL)
+ {
+ struct type *ret_type =
check_typedef (TYPE_TARGET_TYPE (SYMBOL_TYPE (function)));
- /* Remember only non-void return types. */
- if (TYPE_CODE (ret_type) != TYPE_CODE_VOID)
- {
- struct value *func_value;
-
- /* Ignore Python errors at this stage. */
- self_bpfinish->return_type = type_to_type_object (ret_type);
- PyErr_Clear ();
- func_value = read_var_value (function, NULL, frame);
- self_bpfinish->function_value =
- value_to_value_object (func_value);
- PyErr_Clear ();
- }
- }
- }
+ /* Remember only non-void return types. */
+ if (ret_type->code () != TYPE_CODE_VOID)
+ {
+ struct value *func_value;
+
+ /* Ignore Python errors at this stage. */
+ self_bpfinish->return_type = type_to_type_object (ret_type);
+ PyErr_Clear ();
+ func_value = read_var_value (function, NULL, frame);
+ self_bpfinish->function_value =
+ value_to_value_object (func_value);
+ PyErr_Clear ();
+ }
+ }
+ }
}
catch (const gdb_exception &except)
{
event_location_up location
= new_address_location (get_frame_pc (prev_frame), NULL, 0);
create_breakpoint (python_gdbarch,
- location.get (), NULL, thread, NULL,
- 0,
- 1 /*temp_flag*/,
- bp_breakpoint,
- 0,
- AUTO_BOOLEAN_TRUE,
- &bkpt_breakpoint_ops,
- 0, 1, internal_bp, 0);
+ location.get (), NULL, thread, NULL, false,
+ 0,
+ 1 /*temp_flag*/,
+ bp_breakpoint,
+ 0,
+ AUTO_BOOLEAN_TRUE,
+ &bkpt_breakpoint_ops,
+ 0, 1, internal_bp, 0);
}
catch (const gdb_exception &except)
{
/* Callback for `bpfinishpy_detect_out_scope'. Triggers Python's
`B->out_of_scope' function if B is a FinishBreakpoint out of its scope. */
-static bool
+static void
bpfinishpy_detect_out_scope_cb (struct breakpoint *b,
struct breakpoint *bp_stopped)
{
if (py_bp != NULL && b->py_bp_object->is_finish_bp)
{
struct finish_breakpoint_object *finish_bp =
- (struct finish_breakpoint_object *) py_bp;
+ (struct finish_breakpoint_object *) py_bp;
/* Check scope if not currently stopped at the FinishBreakpoint. */
if (b != bp_stopped)
- {
- try
- {
- if (b->pspace == current_inferior ()->pspace
- && (!target_has_registers
- || frame_find_by_id (b->frame_id) == NULL))
- bpfinishpy_out_of_scope (finish_bp);
- }
- catch (const gdb_exception &except)
- {
- gdbpy_convert_exception (except);
- gdbpy_print_stack ();
- }
- }
+ {
+ try
+ {
+ if (b->pspace == current_inferior ()->pspace
+ && (!target_has_registers ()
+ || frame_find_by_id (b->frame_id) == NULL))
+ bpfinishpy_out_of_scope (finish_bp);
+ }
+ catch (const gdb_exception &except)
+ {
+ gdbpy_convert_exception (except);
+ gdbpy_print_stack ();
+ }
+ }
}
-
- return 0;
}
/* Attached to `stop' notifications, check if the execution has run
{
gdbpy_enter enter_py (get_current_arch (), current_language);
- iterate_over_breakpoints ([&] (breakpoint *bp)
- {
- return bpfinishpy_detect_out_scope_cb
- (bp, bs == NULL ? NULL : bs->breakpoint_at);
- });
+ for (breakpoint *bp : all_breakpoints_safe ())
+ bpfinishpy_detect_out_scope_cb (bp, bs == NULL ? NULL : bs->breakpoint_at);
}
/* Attached to `exit' notifications, triggers all the necessary out of
{
gdbpy_enter enter_py (target_gdbarch (), current_language);
- iterate_over_breakpoints ([&] (breakpoint *bp)
- {
- return bpfinishpy_detect_out_scope_cb (bp, nullptr);
- });
+ for (breakpoint *bp : all_breakpoints_safe ())
+ bpfinishpy_detect_out_scope_cb (bp, nullptr);
}
/* Initialize the Python finish breakpoint code. */
(PyObject *) &finish_breakpoint_object_type) < 0)
return -1;
- gdb::observers::normal_stop.attach (bpfinishpy_handle_stop);
- gdb::observers::inferior_exit.attach (bpfinishpy_handle_exit);
+ gdb::observers::normal_stop.attach (bpfinishpy_handle_stop,
+ "py-finishbreakpoint");
+ gdb::observers::inferior_exit.attach (bpfinishpy_handle_exit,
+ "py-finishbreakpoint");
return 0;
}