Introduce a separate debug objfile iterator
authorTom Tromey <tom@tromey.com>
Sun, 10 Mar 2019 21:37:20 +0000 (15:37 -0600)
committerTom Tromey <tom@tromey.com>
Wed, 10 Apr 2019 14:05:17 +0000 (08:05 -0600)
This introduces a new iterator and range adapter for iteration over
the separate debug files of a given objfile.  As in the current
approach, the requested objfile is returned first, followed by the
separate debug objfiles.

gdb/ChangeLog
2019-04-10  Tom Tromey  <tom@tromey.com>

* symtab.c (lookup_global_symbol_from_objfile)
(lookup_symbol_in_objfile_from_linkage_name): Use the iterator.
* objfiles.h (class separate_debug_iterator): New.
(class separate_debug_range): New.
(struct objfile) <separate_debug_objfiles>: New method.
(objfile_separate_debug_iterate): Don't declare.
* objfiles.c (separate_debug_iterator::operator++): Rename from
objfile_separate_debug_iterate.
(objfile_relocate, objfile_rebase, objfile_has_symbols): Use the
iterator.
* minsyms.c (lookup_minimal_symbol_by_pc_section): Use the
iterator.

gdb/ChangeLog
gdb/minsyms.c
gdb/objfiles.c
gdb/objfiles.h
gdb/symtab.c

index 7a8338e3402601dba4cd4a0ab7a436bab14df03c..f0797b6012c8ba06c207f9ce352a6a8e116cf314 100644 (file)
@@ -1,3 +1,18 @@
+2019-04-10  Tom Tromey  <tom@tromey.com>
+
+       * symtab.c (lookup_global_symbol_from_objfile)
+       (lookup_symbol_in_objfile_from_linkage_name): Use the iterator.
+       * objfiles.h (class separate_debug_iterator): New.
+       (class separate_debug_range): New.
+       (struct objfile) <separate_debug_objfiles>: New method.
+       (objfile_separate_debug_iterate): Don't declare.
+       * objfiles.c (separate_debug_iterator::operator++): Rename from
+       objfile_separate_debug_iterate.
+       (objfile_relocate, objfile_rebase, objfile_has_symbols): Use the
+       iterator.
+       * minsyms.c (lookup_minimal_symbol_by_pc_section): Use the
+       iterator.
+
 2019-04-10  Tom Tromey  <tom@tromey.com>
 
        * symfile.c (reread_symbols): Remove old comment.
index 34198d122dc9b875e6383c4fb616bbf98deef750..8037329a862f020344c03a01281c755a19f099c4 100644 (file)
@@ -696,7 +696,6 @@ lookup_minimal_symbol_by_pc_section (CORE_ADDR pc_in, struct obj_section *sectio
   int lo;
   int hi;
   int newobj;
-  struct objfile *objfile;
   struct minimal_symbol *msymbol;
   struct minimal_symbol *best_symbol = NULL;
   struct objfile *best_objfile = NULL;
@@ -722,9 +721,7 @@ lookup_minimal_symbol_by_pc_section (CORE_ADDR pc_in, struct obj_section *sectio
 
   gdb_assert (section != NULL);
 
-  for (objfile = section->objfile;
-       objfile != NULL;
-       objfile = objfile_separate_debug_iterate (section->objfile, objfile))
+  for (struct objfile *objfile : section->objfile->separate_debug_objfiles ())
     {
       CORE_ADDR pc = pc_in;
 
index ada5edc42fab32e6ef61d0a4f1d7cb9fa00c294f..e055365d37e0de0c72c6f5593b7733cdb9668927 100644 (file)
@@ -446,44 +446,50 @@ entry_point_address (void)
   return retval;
 }
 
-/* Iterator on PARENT and every separate debug objfile of PARENT.
-   The usage pattern is:
-     for (objfile = parent;
-          objfile;
-          objfile = objfile_separate_debug_iterate (parent, objfile))
-       ...
-*/
-
-struct objfile *
-objfile_separate_debug_iterate (const struct objfile *parent,
-                                const struct objfile *objfile)
+separate_debug_iterator &
+separate_debug_iterator::operator++ ()
 {
+  gdb_assert (m_objfile != nullptr);
+
   struct objfile *res;
 
   /* If any, return the first child.  */
-  res = objfile->separate_debug_objfile;
-  if (res)
-    return res;
+  res = m_objfile->separate_debug_objfile;
+  if (res != nullptr)
+    {
+      m_objfile = res;
+      return *this;
+    }
 
   /* Common case where there is no separate debug objfile.  */
-  if (objfile == parent)
-    return NULL;
+  if (m_objfile == m_parent)
+    {
+      m_objfile = nullptr;
+      return *this;
+    }
 
   /* Return the brother if any.  Note that we don't iterate on brothers of
      the parents.  */
-  res = objfile->separate_debug_objfile_link;
-  if (res)
-    return res;
+  res = m_objfile->separate_debug_objfile_link;
+  if (res != nullptr)
+    {
+      m_objfile = res;
+      return *this;
+    }
 
-  for (res = objfile->separate_debug_objfile_backlink;
-       res != parent;
+  for (res = m_objfile->separate_debug_objfile_backlink;
+       res != m_parent;
        res = res->separate_debug_objfile_backlink)
     {
-      gdb_assert (res != NULL);
-      if (res->separate_debug_objfile_link)
-        return res->separate_debug_objfile_link;
+      gdb_assert (res != nullptr);
+      if (res->separate_debug_objfile_link != nullptr)
+       {
+         m_objfile = res->separate_debug_objfile_link;
+         return *this;
+       }
     }
-  return NULL;
+  m_objfile = nullptr;
+  return *this;
 }
 
 /* Put one object file before a specified on in the global list.
@@ -860,15 +866,15 @@ void
 objfile_relocate (struct objfile *objfile,
                  const struct section_offsets *new_offsets)
 {
-  struct objfile *debug_objfile;
   int changed = 0;
 
   changed |= objfile_relocate1 (objfile, new_offsets);
 
-  for (debug_objfile = objfile->separate_debug_objfile;
-       debug_objfile;
-       debug_objfile = objfile_separate_debug_iterate (objfile, debug_objfile))
+  for (struct objfile *debug_objfile : objfile->separate_debug_objfiles ())
     {
+      if (debug_objfile == objfile)
+       continue;
+
       section_addr_info objfile_addrs
        = build_section_addr_info_from_objfile (objfile);
 
@@ -917,14 +923,9 @@ objfile_rebase1 (struct objfile *objfile, CORE_ADDR slide)
 void
 objfile_rebase (struct objfile *objfile, CORE_ADDR slide)
 {
-  struct objfile *debug_objfile;
   int changed = 0;
 
-  changed |= objfile_rebase1 (objfile, slide);
-
-  for (debug_objfile = objfile->separate_debug_objfile;
-       debug_objfile;
-       debug_objfile = objfile_separate_debug_iterate (objfile, debug_objfile))
+  for (struct objfile *debug_objfile : objfile->separate_debug_objfiles ())
     changed |= objfile_rebase1 (debug_objfile, slide);
 
   /* Relocate breakpoints as necessary, after things are relocated.  */
@@ -965,9 +966,7 @@ objfile_has_full_symbols (struct objfile *objfile)
 int
 objfile_has_symbols (struct objfile *objfile)
 {
-  struct objfile *o;
-
-  for (o = objfile; o; o = objfile_separate_debug_iterate (objfile, o))
+  for (struct objfile *o : objfile->separate_debug_objfiles ())
     if (objfile_has_partial_symbols (o) || objfile_has_full_symbols (o))
       return 1;
   return 0;
index 368d9f3abe255bc7481c875b033c7bf066c18b95..168f7fc275b4fdfa3e38820b6a02a6bdc5f9a7a4 100644 (file)
@@ -318,6 +318,63 @@ struct objfile_per_bfd_storage
   std::bitset<nr_languages> demangled_hash_languages;
 };
 
+/* An iterator that first returns a parent objfile, and then each
+   separate debug objfile.  */
+
+class separate_debug_iterator
+{
+public:
+
+  explicit separate_debug_iterator (struct objfile *objfile)
+    : m_objfile (objfile),
+      m_parent (objfile)
+  {
+  }
+
+  bool operator!= (const separate_debug_iterator &other)
+  {
+    return m_objfile != other.m_objfile;
+  }
+
+  separate_debug_iterator &operator++ ();
+
+  struct objfile *operator* ()
+  {
+    return m_objfile;
+  }
+
+private:
+
+  struct objfile *m_objfile;
+  struct objfile *m_parent;
+};
+
+/* A range adapter wrapping separate_debug_iterator.  */
+
+class separate_debug_range
+{
+public:
+
+  explicit separate_debug_range (struct objfile *objfile)
+    : m_objfile (objfile)
+  {
+  }
+
+  separate_debug_iterator begin ()
+  {
+    return separate_debug_iterator (m_objfile);
+  }
+
+  separate_debug_iterator end ()
+  {
+    return separate_debug_iterator (nullptr);
+  }
+
+private:
+
+  struct objfile *m_objfile;
+};
+
 /* Master structure for keeping track of each file from which
    gdb reads symbols.  There are several ways these get allocated: 1.
    The main symbol file, symfile_objfile, set by the symbol-file command,
@@ -396,6 +453,14 @@ struct objfile
     return msymbols_range (this);
   }
 
+  /* Return a range adapter for iterating over all the separate debug
+     objfiles of this objfile.  */
+
+  separate_debug_range separate_debug_objfiles ()
+  {
+    return separate_debug_range (this);
+  }
+
 
   /* All struct objfile's are chained together by their next pointers.
      The program space field "objfiles"  (frequently referenced via
@@ -563,9 +628,6 @@ extern CORE_ADDR entry_point_address (void);
 
 extern void build_objfile_section_table (struct objfile *);
 
-extern struct objfile *objfile_separate_debug_iterate (const struct objfile *,
-                                                       const struct objfile *);
-
 extern void put_objfile_before (struct objfile *, struct objfile *);
 
 extern void add_separate_debug_objfile (struct objfile *, struct objfile *);
index d25f560f084a23089154605e3631ce1a0d7aac66..16e641a830b597b2fd4879d2baf51f333c37c7cb 100644 (file)
@@ -2246,11 +2246,7 @@ lookup_global_symbol_from_objfile (struct objfile *main_objfile,
                                   const char *name,
                                   const domain_enum domain)
 {
-  struct objfile *objfile;
-
-  for (objfile = main_objfile;
-       objfile;
-       objfile = objfile_separate_debug_iterate (main_objfile, objfile))
+  for (struct objfile *objfile : main_objfile->separate_debug_objfiles ())
     {
       struct block_symbol result
         = lookup_symbol_in_objfile (objfile, GLOBAL_BLOCK, name, domain);
@@ -2327,7 +2323,7 @@ lookup_symbol_in_objfile_from_linkage_name (struct objfile *objfile,
                                            domain_enum domain)
 {
   enum language lang = current_language->la_language;
-  struct objfile *main_objfile, *cur_objfile;
+  struct objfile *main_objfile;
 
   demangle_result_storage storage;
   const char *modified_name = demangle_for_lookup (linkage_name, lang, storage);
@@ -2337,9 +2333,7 @@ lookup_symbol_in_objfile_from_linkage_name (struct objfile *objfile,
   else
     main_objfile = objfile;
 
-  for (cur_objfile = main_objfile;
-       cur_objfile;
-       cur_objfile = objfile_separate_debug_iterate (main_objfile, cur_objfile))
+  for (struct objfile *cur_objfile : main_objfile->separate_debug_objfiles ())
     {
       struct block_symbol result;
 
This page took 0.031353 seconds and 4 git commands to generate.