gdb: use caller objfile in dwarf_evaluate_loc_desc::push_dwarf_reg_entry_value
[deliverable/binutils-gdb.git] / gdb / python / py-breakpoint.c
index 16c717c5bb4d2dd7508574b8ea30756476310a57..11345ad305267b9b7df439492f1a69a19cfab669 100644 (file)
@@ -1,6 +1,6 @@
 /* Python interface to breakpoints
 
-   Copyright (C) 2008-2019 Free Software Foundation, Inc.
+   Copyright (C) 2008-2020 Free Software Foundation, Inc.
 
    This file is part of GDB.
 
@@ -145,7 +145,7 @@ bppy_set_enabled (PyObject *self, PyObject *newvalue, void *closure)
       else
        disable_breakpoint (self_bp->bp);
     }
-  catch (const gdb_exception_RETURN_MASK_ALL &except)
+  catch (const gdb_exception &except)
     {
       GDB_PY_SET_HANDLE_EXCEPTION (except);
     }
@@ -250,7 +250,7 @@ bppy_set_task (PyObject *self, PyObject *newvalue, void *closure)
        {
          valid_id = valid_task_id (id);
        }
-      catch (const gdb_exception_RETURN_MASK_ALL &except)
+      catch (const gdb_exception &except)
        {
          GDB_PY_SET_HANDLE_EXCEPTION (except);
        }
@@ -292,7 +292,7 @@ bppy_delete_breakpoint (PyObject *self, PyObject *args)
     {
       delete_breakpoint (self_bp->bp);
     }
-  catch (const gdb_exception_RETURN_MASK_ALL &except)
+  catch (const gdb_exception &except)
     {
       GDB_PY_HANDLE_EXCEPTION (except);
     }
@@ -333,7 +333,7 @@ bppy_set_ignore_count (PyObject *self, PyObject *newvalue, void *closure)
     {
       set_ignore_count (self_bp->number, (int) value, 0);
     }
-  catch (const gdb_exception_RETURN_MASK_ALL &except)
+  catch (const gdb_exception &except)
     {
       GDB_PY_SET_HANDLE_EXCEPTION (except);
     }
@@ -379,7 +379,6 @@ bppy_set_hit_count (PyObject *self, PyObject *newvalue, void *closure)
 static PyObject *
 bppy_get_location (PyObject *self, void *closure)
 {
-  const char *str;
   gdbpy_breakpoint_object *obj = (gdbpy_breakpoint_object *) self;
 
   BPPY_REQUIRE_VALID (obj);
@@ -387,12 +386,7 @@ bppy_get_location (PyObject *self, void *closure)
   if (obj->bp->type != bp_breakpoint)
     Py_RETURN_NONE;
 
-  struct event_location *location = obj->bp->location.get ();
-  /* "catch throw" makes a breakpoint of type bp_breakpoint that does
-     not have a location.  */
-  if (location == nullptr)
-    Py_RETURN_NONE;
-  str = event_location_to_string (location);
+  const char *str = event_location_to_string (obj->bp->location.get ());
   if (! str)
     str = "";
   return host_string_to_python_string (str).release ();
@@ -445,7 +439,7 @@ bppy_set_condition (PyObject *self, PyObject *newvalue, void *closure)
   gdb::unique_xmalloc_ptr<char> exp_holder;
   const char *exp = NULL;
   gdbpy_breakpoint_object *self_bp = (gdbpy_breakpoint_object *) self;
-  struct gdb_exception except = exception_none;
+  struct gdb_exception except;
 
   BPPY_SET_REQUIRE_VALID (self_bp);
 
@@ -469,9 +463,9 @@ bppy_set_condition (PyObject *self, PyObject *newvalue, void *closure)
     {
       set_breakpoint_condition (self_bp->bp, exp, 0);
     }
-  catch (const gdb_exception_RETURN_MASK_ALL &ex)
+  catch (gdb_exception &ex)
     {
-      except = ex;
+      except = std::move (ex);
     }
 
   GDB_PY_SET_HANDLE_EXCEPTION (except);
@@ -498,7 +492,7 @@ bppy_get_commands (PyObject *self, void *closure)
     {
       print_command_lines (current_uiout, breakpoint_commands (bp), 0);
     }
-  catch (const gdb_exception_RETURN_MASK_ALL &except)
+  catch (const gdb_exception &except)
     {
       current_uiout->redirect (NULL);
       gdbpy_convert_exception (except);
@@ -515,7 +509,7 @@ static int
 bppy_set_commands (PyObject *self, PyObject *newvalue, void *closure)
 {
   gdbpy_breakpoint_object *self_bp = (gdbpy_breakpoint_object *) self;
-  struct gdb_exception except = exception_none;
+  struct gdb_exception except;
 
   BPPY_SET_REQUIRE_VALID (self_bp);
 
@@ -540,9 +534,9 @@ bppy_set_commands (PyObject *self, PyObject *newvalue, void *closure)
       counted_command_line lines = read_command_lines_1 (reader, 1, nullptr);
       breakpoint_set_commands (self_bp->bp, std::move (lines));
     }
-  catch (const gdb_exception_RETURN_MASK_ALL &ex)
+  catch (gdb_exception &ex)
     {
-      except = ex;
+      except = std::move (ex);
     }
 
   GDB_PY_SET_HANDLE_EXCEPTION (except);
@@ -834,13 +828,16 @@ bppy_init (PyObject *self, PyObject *args, PyObject *kwargs)
                location = new_explicit_location (&explicit_loc);
              }
 
+           const struct breakpoint_ops *ops =
+             breakpoint_ops_for_event_location (location.get (), false);
+
            create_breakpoint (python_gdbarch,
                               location.get (), NULL, -1, NULL,
                               0,
                               temporary_bp, bp_breakpoint,
                               0,
                               AUTO_BOOLEAN_TRUE,
-                              &bkpt_breakpoint_ops,
+                              ops,
                               0, 1, internal_bp, 0);
            break;
          }
@@ -864,7 +861,7 @@ bppy_init (PyObject *self, PyObject *args, PyObject *kwargs)
          error(_("Do not understand breakpoint type to set."));
        }
     }
-  catch (const gdb_exception_RETURN_MASK_ALL &except)
+  catch (const gdb_exception &except)
     {
       bppy_pending_object = NULL;
       gdbpy_convert_exception (except);
@@ -877,10 +874,9 @@ bppy_init (PyObject *self, PyObject *args, PyObject *kwargs)
 
 \f
 
-static int
-build_bp_list (struct breakpoint *b, void *arg)
+static bool
+build_bp_list (struct breakpoint *b, PyObject *list)
 {
-  PyObject *list = (PyObject *) arg;
   PyObject *bp = (PyObject *) b->py_bp_object;
   int iserr = 0;
 
@@ -892,9 +888,9 @@ build_bp_list (struct breakpoint *b, void *arg)
     iserr = PyList_Append (list, bp);
 
   if (iserr == -1)
-    return 1;
+    return true;
 
-  return 0;
+  return false;
 }
 
 /* Static function to return a tuple holding all breakpoints.  */
@@ -912,7 +908,11 @@ gdbpy_breakpoints (PyObject *self, PyObject *args)
   /* If iterate_over_breakpoints returns non NULL it signals an error
      condition.  In that case abandon building the list and return
      NULL.  */
-  if (iterate_over_breakpoints (build_bp_list, list.get ()) != NULL)
+  auto callback = [&] (breakpoint *bp)
+    {
+      return build_bp_list(bp, list.get ());
+    };
+  if (iterate_over_breakpoints (callback) != NULL)
     return NULL;
 
   return PyList_AsTuple (list.get ());
@@ -1003,7 +1003,6 @@ static void
 gdbpy_breakpoint_created (struct breakpoint *bp)
 {
   gdbpy_breakpoint_object *newbp;
-  PyGILState_STATE state;
 
   if (!user_breakpoint_p (bp) && bppy_pending_object == NULL)
     return;
@@ -1015,11 +1014,13 @@ gdbpy_breakpoint_created (struct breakpoint *bp)
       && bp->type != bp_access_watchpoint)
     return;
 
-  state = PyGILState_Ensure ();
+  struct gdbarch *garch = bp->gdbarch ? bp->gdbarch : get_current_arch ();
+  gdbpy_enter enter_py (garch, current_language);
 
   if (bppy_pending_object)
     {
       newbp = bppy_pending_object;
+      Py_INCREF (newbp);
       bppy_pending_object = NULL;
     }
   else
@@ -1030,7 +1031,6 @@ gdbpy_breakpoint_created (struct breakpoint *bp)
       newbp->bp = bp;
       newbp->bp->py_bp_object = newbp;
       newbp->is_finish_bp = 0;
-      Py_INCREF (newbp);
       ++bppy_live;
     }
   else
@@ -1046,8 +1046,6 @@ gdbpy_breakpoint_created (struct breakpoint *bp)
                           gdb_py_events.breakpoint_created) < 0)
        gdbpy_print_stack ();
     }
-
-  PyGILState_Release (state);
 }
 
 /* Callback that is used when a breakpoint is deleted.  This will
@@ -1056,13 +1054,14 @@ static void
 gdbpy_breakpoint_deleted (struct breakpoint *b)
 {
   int num = b->number;
-  PyGILState_STATE state;
   struct breakpoint *bp = NULL;
 
-  state = PyGILState_Ensure ();
   bp = get_breakpoint (num);
   if (bp)
     {
+      struct gdbarch *garch = bp->gdbarch ? bp->gdbarch : get_current_arch ();
+      gdbpy_enter enter_py (garch, current_language);
+
       gdbpy_ref<gdbpy_breakpoint_object> bp_obj (bp->py_bp_object);
       if (bp_obj != NULL)
        {
@@ -1077,7 +1076,6 @@ gdbpy_breakpoint_deleted (struct breakpoint *b)
          --bppy_live;
        }
     }
-  PyGILState_Release (state);
 }
 
 /* Callback that is used when a breakpoint is modified.  */
@@ -1086,13 +1084,14 @@ static void
 gdbpy_breakpoint_modified (struct breakpoint *b)
 {
   int num = b->number;
-  PyGILState_STATE state;
   struct breakpoint *bp = NULL;
 
-  state = PyGILState_Ensure ();
   bp = get_breakpoint (num);
   if (bp)
     {
+      struct gdbarch *garch = bp->gdbarch ? bp->gdbarch : get_current_arch ();
+      gdbpy_enter enter_py (garch, current_language);
+
       PyObject *bp_obj = (PyObject *) bp->py_bp_object;
       if (bp_obj)
        {
@@ -1104,7 +1103,6 @@ gdbpy_breakpoint_modified (struct breakpoint *b)
            }
        }
     }
-  PyGILState_Release (state);
 }
 
 \f
This page took 0.032071 seconds and 4 git commands to generate.