Add an objfile getter to gdb.Type
[deliverable/binutils-gdb.git] / gdb / python / py-objfile.c
index c5212b59d677d417533b9705bb7a9a961f24e0aa..199c567a044ffa1b60a401ff8f4f28d60be79c5f 100644 (file)
@@ -24,7 +24,6 @@
 #include "language.h"
 #include "build-id.h"
 #include "symtab.h"
-#include "py-ref.h"
 
 typedef struct
 {
@@ -131,15 +130,14 @@ objfpy_get_build_id (PyObject *self, void *closure)
 
   OBJFPY_REQUIRE_VALID (obj);
 
-  TRY
+  try
     {
       build_id = build_id_bfd_get (objfile->obfd);
     }
-  CATCH (except, RETURN_MASK_ALL)
+  catch (const gdb_exception &except)
     {
       GDB_PY_HANDLE_EXCEPTION (except);
     }
-  END_CATCH
 
   if (build_id != NULL)
     {
@@ -240,7 +238,6 @@ objfpy_get_printers (PyObject *o, void *ignore)
 static int
 objfpy_set_printers (PyObject *o, PyObject *value, void *ignore)
 {
-  PyObject *tmp;
   objfile_object *self = (objfile_object *) o;
 
   if (! value)
@@ -258,10 +255,9 @@ objfpy_set_printers (PyObject *o, PyObject *value, void *ignore)
     }
 
   /* Take care in case the LHS and RHS are related somehow.  */
-  tmp = self->printers;
+  gdbpy_ref<> tmp (self->printers);
   Py_INCREF (value);
   self->printers = value;
-  Py_XDECREF (tmp);
 
   return 0;
 }
@@ -281,7 +277,6 @@ objfpy_get_frame_filters (PyObject *o, void *ignore)
 static int
 objfpy_set_frame_filters (PyObject *o, PyObject *filters, void *ignore)
 {
-  PyObject *tmp;
   objfile_object *self = (objfile_object *) o;
 
   if (! filters)
@@ -299,10 +294,9 @@ objfpy_set_frame_filters (PyObject *o, PyObject *filters, void *ignore)
     }
 
   /* Take care in case the LHS and RHS are related somehow.  */
-  tmp = self->frame_filters;
+  gdbpy_ref<> tmp (self->frame_filters);
   Py_INCREF (filters);
   self->frame_filters = filters;
-  Py_XDECREF (tmp);
 
   return 0;
 }
@@ -323,7 +317,6 @@ objfpy_get_frame_unwinders (PyObject *o, void *ignore)
 static int
 objfpy_set_frame_unwinders (PyObject *o, PyObject *unwinders, void *ignore)
 {
-  PyObject *tmp;
   objfile_object *self = (objfile_object *) o;
 
   if (!unwinders)
@@ -341,10 +334,9 @@ objfpy_set_frame_unwinders (PyObject *o, PyObject *unwinders, void *ignore)
     }
 
   /* Take care in case the LHS and RHS are related somehow.  */
-  tmp = self->frame_unwinders;
+  gdbpy_ref<> tmp (self->frame_unwinders);
   Py_INCREF (unwinders);
   self->frame_unwinders = unwinders;
-  Py_XDECREF (tmp);
 
   return 0;
 }
@@ -376,7 +368,6 @@ objfpy_get_xmethods (PyObject *o, void *ignore)
 static int
 objfpy_set_type_printers (PyObject *o, PyObject *value, void *ignore)
 {
-  PyObject *tmp;
   objfile_object *self = (objfile_object *) o;
 
   if (! value)
@@ -394,10 +385,9 @@ objfpy_set_type_printers (PyObject *o, PyObject *value, void *ignore)
     }
 
   /* Take care in case the LHS and RHS are related somehow.  */
-  tmp = self->type_printers;
+  gdbpy_ref<> tmp (self->type_printers);
   Py_INCREF (value);
   self->type_printers = value;
-  Py_XDECREF (tmp);
 
   return 0;
 }
@@ -430,17 +420,16 @@ objfpy_add_separate_debug_file (PyObject *self, PyObject *args, PyObject *kw)
   if (!gdb_PyArg_ParseTupleAndKeywords (args, kw, "s", keywords, &file_name))
     return NULL;
 
-  TRY
+  try
     {
       gdb_bfd_ref_ptr abfd (symfile_bfd_open (file_name));
 
       symbol_file_add_separate (abfd.get (), file_name, 0, obj->objfile);
     }
-  CATCH (except, RETURN_MASK_ALL)
+  catch (const gdb_exception &except)
     {
       GDB_PY_HANDLE_EXCEPTION (except);
     }
-  END_CATCH
 
   Py_RETURN_NONE;
 }
@@ -509,9 +498,7 @@ objfpy_build_id_matches (const struct bfd_build_id *build_id,
 static struct objfile *
 objfpy_lookup_objfile_by_name (const char *name)
 {
-  struct objfile *objfile;
-
-  ALL_OBJFILES (objfile)
+  for (objfile *objfile : current_program_space->objfiles ())
     {
       const char *filename;
 
@@ -537,9 +524,7 @@ objfpy_lookup_objfile_by_name (const char *name)
 static struct objfile *
 objfpy_lookup_objfile_by_build_id (const char *build_id)
 {
-  struct objfile *objfile;
-
-  ALL_OBJFILES (objfile)
+  for (objfile *objfile : current_program_space->objfiles ())
     {
       const struct bfd_build_id *obfd_build_id;
 
This page took 0.025294 seconds and 4 git commands to generate.