gdb: fix python/lib/gdb/__init__.py formatting
[deliverable/binutils-gdb.git] / gdb / python / py-finishbreakpoint.c
index e05fb5550e5d5be9121e273f0436dec9c81ab1a2..1d8373d807edbbf1df9538e88f56ddad96dff9fc 100644 (file)
@@ -1,6 +1,6 @@
 /* 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.
 
@@ -78,7 +78,7 @@ static void
 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);
@@ -94,7 +94,7 @@ void
 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);
@@ -105,22 +105,22 @@ bpfinishpy_pre_stop_hook (struct gdbpy_breakpoint_object *bp_obj)
   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)
     {
@@ -221,7 +221,7 @@ bpfinishpy_init (PyObject *self, PyObject *args, PyObject *kwargs)
   if (inferior_ptid == null_ptid)
     {
       PyErr_SetString (PyExc_ValueError,
-                       _("No thread currently selected."));
+                      _("No thread currently selected."));
       return -1;
     }
 
@@ -231,11 +231,11 @@ bpfinishpy_init (PyObject *self, PyObject *args, PyObject *kwargs)
     {
       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.  */
@@ -245,28 +245,28 @@ bpfinishpy_init (PyObject *self, PyObject *args, PyObject *kwargs)
   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)
     {
@@ -294,14 +294,14 @@ bpfinishpy_init (PyObject *self, PyObject *args, PyObject *kwargs)
       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)
     {
@@ -342,7 +342,7 @@ bpfinishpy_out_of_scope (struct finish_breakpoint_object *bpfinish_obj)
 /* 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)
 {
@@ -353,27 +353,25 @@ bpfinishpy_detect_out_scope_cb (struct breakpoint *b,
   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
@@ -384,11 +382,8 @@ bpfinishpy_handle_stop (struct bpstats *bs, int print_frame)
 {
   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
@@ -399,10 +394,8 @@ bpfinishpy_handle_exit (struct inferior *inf)
 {
   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.  */
@@ -417,8 +410,10 @@ gdbpy_initialize_finishbreakpoints (void)
                              (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;
 }
This page took 0.028929 seconds and 4 git commands to generate.