public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [review] Store objfiles on a std::list
@ 2019-11-04  1:35 Tom Tromey (Code Review)
  2019-11-04  5:34 ` Christian Biesinger (Code Review)
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: Tom Tromey (Code Review) @ 2019-11-04  1:35 UTC (permalink / raw)
  To: gdb-patches

Change URL: https://gnutoolchain-gerrit.osci.io/r/c/binutils-gdb/+/499
......................................................................

Store objfiles on a std::list

This removes objfile::next and changes objfiles to be stored in a
std::list.

gdb/ChangeLog
2019-11-03  Tom Tromey  <tom@tromey.com>

	* progspace.c (program_space::add_objfile)
	(program_space::remove_objfile): Update.
	(program_space::multi_objfile_p): Remove.
	* objfiles.h (struct objfile) <next>: Remove.
	* objfiles.c (objfile::objfile): Update.
	(put_objfile_before): Update.
	(unlink_objfile): Update.
	* progspace.h (object_files): Remove.
	(struct program_space) <objfiles_head>: Remove.
	<objfiles_list>: New member.
	<objfiles_range, objfiles_safe_range>: Change type.
	(objfiles): Change return type.
	(objfiles_safe): Update.
	(multi_objfile_p): Rewrite and inline.
	(object_files): Remove macro.

Change-Id: Ib4430e3db6f9a390399924379a5c10426c514853
---
M gdb/ChangeLog
M gdb/objfiles.c
M gdb/objfiles.h
M gdb/progspace.c
M gdb/progspace.h
5 files changed, 45 insertions(+), 59 deletions(-)



diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 6a3afe3..4938e6f 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,23 @@
 2019-11-03  Tom Tromey  <tom@tromey.com>
 
+	* progspace.c (program_space::add_objfile)
+	(program_space::remove_objfile): Update.
+	(program_space::multi_objfile_p): Remove.
+	* objfiles.h (struct objfile) <next>: Remove.
+	* objfiles.c (objfile::objfile): Update.
+	(put_objfile_before): Update.
+	(unlink_objfile): Update.
+	* progspace.h (object_files): Remove.
+	(struct program_space) <objfiles_head>: Remove.
+	<objfiles_list>: New member.
+	<objfiles_range, objfiles_safe_range>: Change type.
+	(objfiles): Change return type.
+	(objfiles_safe): Update.
+	(multi_objfile_p): Rewrite and inline.
+	(object_files): Remove macro.
+
+2019-11-03  Tom Tromey  <tom@tromey.com>
+
 	* gdbsupport/safe-iterator.h (basic_safe_iterator): Simplify.  Add
 	second constructor.
 	(basic_safe_range): New class.
diff --git a/gdb/objfiles.c b/gdb/objfiles.c
index 34f6a29..31265c1 100644
--- a/gdb/objfiles.c
+++ b/gdb/objfiles.c
@@ -54,6 +54,7 @@
 #include "btrace.h"
 #include "gdbsupport/pathstuff.h"
 
+#include <algorithm>
 #include <vector>
 
 /* Keep a registry of per-objfile data-pointers required by other GDB
diff --git a/gdb/objfiles.h b/gdb/objfiles.h
index 68df50d..e5a6e70 100644
--- a/gdb/objfiles.h
+++ b/gdb/objfiles.h
@@ -486,12 +486,6 @@
   }
 
 
-  /* All struct objfile's are chained together by their next pointers.
-     The program space field "objfiles"  (frequently referenced via
-     the macro "object_files") points to the first link in this chain.  */
-
-  struct objfile *next = nullptr;
-
   /* The object file's original name as specified by the user,
      made absolute, and tilde-expanded.  However, it is not canonicalized
      (i.e., it has not been passed through gdb_realpath).
diff --git a/gdb/progspace.c b/gdb/progspace.c
index a39b34c..d1bf0c6 100644
--- a/gdb/progspace.c
+++ b/gdb/progspace.c
@@ -25,6 +25,7 @@
 #include "solib.h"
 #include "gdbthread.h"
 #include "inferior.h"
+#include <algorithm>
 
 /* The last program space number assigned.  */
 int last_program_space_num = 0;
@@ -158,21 +159,15 @@
 void
 program_space::add_objfile (struct objfile *objfile, struct objfile *before)
 {
-  for (struct objfile **objp = &objfiles_head;
-       *objp != NULL;
-       objp = &((*objp)->next))
+  if (before == nullptr)
+    objfiles_list.push_back (objfile);
+  else
     {
-      if (*objp == before)
-	{
-	  objfile->next = *objp;
-	  *objp = objfile;
-	  return;
-	}
+      auto iter = std::find (objfiles_list.begin (), objfiles_list.end (),
+			     before);
+      gdb_assert (iter != objfiles_list.end ());
+      objfiles_list.insert (iter, objfile);
     }
-
-  internal_error (__FILE__, __LINE__,
-		  _("put_objfile_before: before objfile not in list"));
-
 }
 
 /* See progspace.h.  */
@@ -180,32 +175,13 @@
 void
 program_space::remove_objfile (struct objfile *objfile)
 {
-  struct objfile **objpp;
+  auto iter = std::find (objfiles_list.begin (), objfiles_list.end (),
+			 objfile);
+  gdb_assert (iter != objfiles_list.end ());
+  objfiles_list.erase (iter);
 
-  for (objpp = &object_files; *objpp != NULL; objpp = &((*objpp)->next))
-    {
-      if (*objpp == objfile)
-	{
-	  *objpp = (*objpp)->next;
-	  objfile->next = NULL;
-
-	  if (objfile == symfile_object_file)
-	    symfile_object_file = NULL;
-
-	  return;
-	}
-    }
-
-  internal_error (__FILE__, __LINE__,
-		  _("remove_objfile: objfile already unlinked"));
-}
-
-/* See progspace.h.  */
-
-bool
-program_space::multi_objfile_p () const
-{
-  return objfiles_head != nullptr && objfiles_head->next != nullptr;
+  if (objfile == symfile_object_file)
+    symfile_object_file = NULL;
 }
 
 /* Copies program space SRC to DEST.  Copies the main executable file,
diff --git a/gdb/progspace.h b/gdb/progspace.h
index 86bc22a..a731eb6 100644
--- a/gdb/progspace.h
+++ b/gdb/progspace.h
@@ -27,6 +27,7 @@
 #include "registry.h"
 #include "gdbsupport/next-iterator.h"
 #include "gdbsupport/safe-iterator.h"
+#include <list>
 
 struct target_ops;
 struct bfd;
@@ -138,20 +139,18 @@
   program_space (address_space *aspace_);
   ~program_space ();
 
-  typedef next_adapter<struct objfile> objfiles_range;
+  typedef std::list<struct objfile *> objfiles_range;
 
   /* Return an iterable object that can be used to iterate over all
      objfiles.  The basic use is in a foreach, like:
 
      for (objfile *objf : pspace->objfiles ()) { ... }  */
-  objfiles_range objfiles ()
+  objfiles_range &objfiles ()
   {
-    return objfiles_range (objfiles_head);
+    return objfiles_list;
   }
 
-  typedef next_adapter<struct objfile,
-		       basic_safe_iterator<next_iterator<objfile>>>
-    objfiles_safe_range;
+  typedef basic_safe_range<objfiles_range> objfiles_safe_range;
 
   /* An iterable object that can be used to iterate over all objfiles.
      The basic use is in a foreach, like:
@@ -162,7 +161,7 @@
      deleted during iteration.  */
   objfiles_safe_range objfiles_safe ()
   {
-    return objfiles_safe_range (objfiles_head);
+    return objfiles_safe_range (objfiles_list);
   }
 
   /* Add OBJFILE to the list of objfiles, putting it just before
@@ -175,7 +174,10 @@
 
   /* Return true if there is more than one object file loaded; false
      otherwise.  */
-  bool multi_objfile_p () const;
+  bool multi_objfile_p () const
+  {
+    return objfiles_list.size () > 1;
+  }
 
 
   /* Pointer to next in linked list.  */
@@ -228,9 +230,8 @@
      (e.g. the argument to the "symbol-file" or "file" command).  */
   struct objfile *symfile_object_file = NULL;
 
-  /* All known objfiles are kept in a linked list.  This points to
-     the head of this list.  */
-  struct objfile *objfiles_head = NULL;
+  /* All known objfiles are kept in a linked list.  */
+  std::list<struct objfile *> objfiles_list;
 
   /* The set of target sections matching the sections mapped into
      this program space.  Managed by both exec_ops and solib.c.  */
@@ -271,10 +272,6 @@
 
 #define symfile_objfile current_program_space->symfile_object_file
 
-/* All known objfiles are kept in a linked list.  This points to the
-   root of this list.  */
-#define object_files current_program_space->objfiles_head
-
 /* The set of target sections matching the sections mapped into the
    current program space.  */
 #define current_target_sections (&current_program_space->target_sections)

-- 
Gerrit-Project: binutils-gdb
Gerrit-Branch: master
Gerrit-Change-Id: Ib4430e3db6f9a390399924379a5c10426c514853
Gerrit-Change-Number: 499
Gerrit-PatchSet: 1
Gerrit-Owner: Tom Tromey <tromey@sourceware.org>
Gerrit-MessageType: newchange

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [review] Store objfiles on a std::list
  2019-11-04  1:35 [review] Store objfiles on a std::list Tom Tromey (Code Review)
@ 2019-11-04  5:34 ` Christian Biesinger (Code Review)
  2019-11-05  0:16 ` Tom Tromey (Code Review)
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Christian Biesinger (Code Review) @ 2019-11-04  5:34 UTC (permalink / raw)
  To: Tom Tromey, gdb-patches; +Cc: Christian Biesinger

Christian Biesinger has posted comments on this change.

Change URL: https://gnutoolchain-gerrit.osci.io/r/c/binutils-gdb/+/499
......................................................................


Patch Set 1:

(1 comment)

https://gnutoolchain-gerrit.osci.io/r/c/binutils-gdb/+/499/1/gdb/progspace.h 
File gdb/progspace.h:

https://gnutoolchain-gerrit.osci.io/r/c/binutils-gdb/+/499/1/gdb/progspace.h@179 
PS1, Line 179: 
137 | struct program_space
    | ...
174 | 
175 |   /* Return true if there is more than one object file loaded; false
176 |      otherwise.  */
177 |   bool multi_objfile_p () const
178 |   {
179 >     return objfiles_list.size () > 1;
180 |   }
181 | 
182 | 
183 |   /* Pointer to next in linked list.  */
184 |   struct program_space *next = NULL;

return !objfiles_list.empty ()?



-- 
Gerrit-Project: binutils-gdb
Gerrit-Branch: master
Gerrit-Change-Id: Ib4430e3db6f9a390399924379a5c10426c514853
Gerrit-Change-Number: 499
Gerrit-PatchSet: 1
Gerrit-Owner: Tom Tromey <tromey@sourceware.org>
Gerrit-CC: Christian Biesinger <cbiesinger@google.com>
Gerrit-Comment-Date: Mon, 04 Nov 2019 05:34:00 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Gerrit-MessageType: comment

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [review] Store objfiles on a std::list
  2019-11-04  1:35 [review] Store objfiles on a std::list Tom Tromey (Code Review)
  2019-11-04  5:34 ` Christian Biesinger (Code Review)
@ 2019-11-05  0:16 ` Tom Tromey (Code Review)
  2019-11-05  0:38 ` Christian Biesinger (Code Review)
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Tom Tromey (Code Review) @ 2019-11-05  0:16 UTC (permalink / raw)
  To: gdb-patches; +Cc: Christian Biesinger

Tom Tromey has posted comments on this change.

Change URL: https://gnutoolchain-gerrit.osci.io/r/c/binutils-gdb/+/499
......................................................................


Patch Set 1:

(1 comment)

https://gnutoolchain-gerrit.osci.io/r/c/binutils-gdb/+/499/1/gdb/progspace.h 
File gdb/progspace.h:

https://gnutoolchain-gerrit.osci.io/r/c/binutils-gdb/+/499/1/gdb/progspace.h@179 
PS1, Line 179: 
137 | struct program_space
    | ...
174 | 
175 |   /* Return true if there is more than one object file loaded; false
176 |      otherwise.  */
177 |   bool multi_objfile_p () const
178 |   {
179 >     return objfiles_list.size () > 1;
180 |   }
181 | 
182 | 
183 |   /* Pointer to next in linked list.  */
184 |   struct program_space *next = NULL;

> return !objfiles_list. […]

This spot has to return false if there are 0 or 1 objfiles,
and true otherwise, so I think it's correct as-is.



-- 
Gerrit-Project: binutils-gdb
Gerrit-Branch: master
Gerrit-Change-Id: Ib4430e3db6f9a390399924379a5c10426c514853
Gerrit-Change-Number: 499
Gerrit-PatchSet: 1
Gerrit-Owner: Tom Tromey <tromey@sourceware.org>
Gerrit-Reviewer: Tom Tromey <tromey@sourceware.org>
Gerrit-CC: Christian Biesinger <cbiesinger@google.com>
Gerrit-Comment-Date: Tue, 05 Nov 2019 00:16:36 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: Christian Biesinger <cbiesinger@google.com>
Gerrit-MessageType: comment

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [review] Store objfiles on a std::list
  2019-11-04  1:35 [review] Store objfiles on a std::list Tom Tromey (Code Review)
  2019-11-04  5:34 ` Christian Biesinger (Code Review)
  2019-11-05  0:16 ` Tom Tromey (Code Review)
@ 2019-11-05  0:38 ` Christian Biesinger (Code Review)
  2019-12-12 23:50 ` [pushed] " Sourceware to Gerrit sync (Code Review)
  2019-12-12 23:50 ` Sourceware to Gerrit sync (Code Review)
  4 siblings, 0 replies; 6+ messages in thread
From: Christian Biesinger (Code Review) @ 2019-11-05  0:38 UTC (permalink / raw)
  To: Tom Tromey, gdb-patches; +Cc: Christian Biesinger

Christian Biesinger has posted comments on this change.

Change URL: https://gnutoolchain-gerrit.osci.io/r/c/binutils-gdb/+/499
......................................................................


Patch Set 1:

(1 comment)

https://gnutoolchain-gerrit.osci.io/r/c/binutils-gdb/+/499/1/gdb/progspace.h 
File gdb/progspace.h:

https://gnutoolchain-gerrit.osci.io/r/c/binutils-gdb/+/499/1/gdb/progspace.h@179 
PS1, Line 179: 
137 | struct program_space
    | ...
174 | 
175 |   /* Return true if there is more than one object file loaded; false
176 |      otherwise.  */
177 |   bool multi_objfile_p () const
178 |   {
179 >     return objfiles_list.size () > 1;
180 |   }
181 | 
182 | 
183 |   /* Pointer to next in linked list.  */
184 |   struct program_space *next = NULL;

> This spot has to return false if there are 0 or 1 objfiles, […]

Sorry, you are of course correct. And as of C++11 size() is guaranteed to be a constant time call, so that's ok.



-- 
Gerrit-Project: binutils-gdb
Gerrit-Branch: master
Gerrit-Change-Id: Ib4430e3db6f9a390399924379a5c10426c514853
Gerrit-Change-Number: 499
Gerrit-PatchSet: 1
Gerrit-Owner: Tom Tromey <tromey@sourceware.org>
Gerrit-Reviewer: Tom Tromey <tromey@sourceware.org>
Gerrit-CC: Christian Biesinger <cbiesinger@google.com>
Gerrit-Comment-Date: Tue, 05 Nov 2019 00:37:55 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: Christian Biesinger <cbiesinger@google.com>
Comment-In-Reply-To: Tom Tromey <tromey@sourceware.org>
Gerrit-MessageType: comment

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [pushed] Store objfiles on a std::list
  2019-11-04  1:35 [review] Store objfiles on a std::list Tom Tromey (Code Review)
                   ` (3 preceding siblings ...)
  2019-12-12 23:50 ` [pushed] " Sourceware to Gerrit sync (Code Review)
@ 2019-12-12 23:50 ` Sourceware to Gerrit sync (Code Review)
  4 siblings, 0 replies; 6+ messages in thread
From: Sourceware to Gerrit sync (Code Review) @ 2019-12-12 23:50 UTC (permalink / raw)
  To: Tom Tromey, gdb-patches; +Cc: Christian Biesinger

Sourceware to Gerrit sync has submitted this change.

Change URL: https://gnutoolchain-gerrit.osci.io/r/c/binutils-gdb/+/499
......................................................................

Store objfiles on a std::list

This removes objfile::next and changes objfiles to be stored in a
std::list.

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

	* progspace.c (program_space::add_objfile)
	(program_space::remove_objfile): Update.
	(program_space::multi_objfile_p): Remove.
	* objfiles.h (struct objfile) <next>: Remove.
	* objfiles.c (objfile::objfile): Update.
	(put_objfile_before): Update.
	(unlink_objfile): Update.
	* progspace.h (object_files): Remove.
	(struct program_space) <objfiles_head>: Remove.
	<objfiles_list>: New member.
	<objfiles_range, objfiles_safe_range>: Change type.
	(objfiles): Change return type.
	(objfiles_safe): Update.
	(multi_objfile_p): Rewrite and inline.
	(object_files): Remove macro.

Change-Id: Ib4430e3db6f9a390399924379a5c10426c514853
---
M gdb/ChangeLog
M gdb/objfiles.c
M gdb/objfiles.h
M gdb/progspace.c
M gdb/progspace.h
5 files changed, 45 insertions(+), 59 deletions(-)


diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 368d7f0..9b96f3d 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,23 @@
 2019-12-12  Tom Tromey  <tom@tromey.com>
 
+	* progspace.c (program_space::add_objfile)
+	(program_space::remove_objfile): Update.
+	(program_space::multi_objfile_p): Remove.
+	* objfiles.h (struct objfile) <next>: Remove.
+	* objfiles.c (objfile::objfile): Update.
+	(put_objfile_before): Update.
+	(unlink_objfile): Update.
+	* progspace.h (object_files): Remove.
+	(struct program_space) <objfiles_head>: Remove.
+	<objfiles_list>: New member.
+	<objfiles_range, objfiles_safe_range>: Change type.
+	(objfiles): Change return type.
+	(objfiles_safe): Update.
+	(multi_objfile_p): Rewrite and inline.
+	(object_files): Remove macro.
+
+2019-12-12  Tom Tromey  <tom@tromey.com>
+
 	* gdbsupport/safe-iterator.h (basic_safe_iterator): Simplify.  Add
 	second constructor.
 	(basic_safe_range): New class.
diff --git a/gdb/objfiles.c b/gdb/objfiles.c
index 34f6a29..31265c1 100644
--- a/gdb/objfiles.c
+++ b/gdb/objfiles.c
@@ -54,6 +54,7 @@
 #include "btrace.h"
 #include "gdbsupport/pathstuff.h"
 
+#include <algorithm>
 #include <vector>
 
 /* Keep a registry of per-objfile data-pointers required by other GDB
diff --git a/gdb/objfiles.h b/gdb/objfiles.h
index 0656cfe..f9bf102 100644
--- a/gdb/objfiles.h
+++ b/gdb/objfiles.h
@@ -486,12 +486,6 @@
   }
 
 
-  /* All struct objfile's are chained together by their next pointers.
-     The program space field "objfiles"  (frequently referenced via
-     the macro "object_files") points to the first link in this chain.  */
-
-  struct objfile *next = nullptr;
-
   /* The object file's original name as specified by the user,
      made absolute, and tilde-expanded.  However, it is not canonicalized
      (i.e., it has not been passed through gdb_realpath).
diff --git a/gdb/progspace.c b/gdb/progspace.c
index a39b34c..d1bf0c6 100644
--- a/gdb/progspace.c
+++ b/gdb/progspace.c
@@ -25,6 +25,7 @@
 #include "solib.h"
 #include "gdbthread.h"
 #include "inferior.h"
+#include <algorithm>
 
 /* The last program space number assigned.  */
 int last_program_space_num = 0;
@@ -158,21 +159,15 @@
 void
 program_space::add_objfile (struct objfile *objfile, struct objfile *before)
 {
-  for (struct objfile **objp = &objfiles_head;
-       *objp != NULL;
-       objp = &((*objp)->next))
+  if (before == nullptr)
+    objfiles_list.push_back (objfile);
+  else
     {
-      if (*objp == before)
-	{
-	  objfile->next = *objp;
-	  *objp = objfile;
-	  return;
-	}
+      auto iter = std::find (objfiles_list.begin (), objfiles_list.end (),
+			     before);
+      gdb_assert (iter != objfiles_list.end ());
+      objfiles_list.insert (iter, objfile);
     }
-
-  internal_error (__FILE__, __LINE__,
-		  _("put_objfile_before: before objfile not in list"));
-
 }
 
 /* See progspace.h.  */
@@ -180,32 +175,13 @@
 void
 program_space::remove_objfile (struct objfile *objfile)
 {
-  struct objfile **objpp;
+  auto iter = std::find (objfiles_list.begin (), objfiles_list.end (),
+			 objfile);
+  gdb_assert (iter != objfiles_list.end ());
+  objfiles_list.erase (iter);
 
-  for (objpp = &object_files; *objpp != NULL; objpp = &((*objpp)->next))
-    {
-      if (*objpp == objfile)
-	{
-	  *objpp = (*objpp)->next;
-	  objfile->next = NULL;
-
-	  if (objfile == symfile_object_file)
-	    symfile_object_file = NULL;
-
-	  return;
-	}
-    }
-
-  internal_error (__FILE__, __LINE__,
-		  _("remove_objfile: objfile already unlinked"));
-}
-
-/* See progspace.h.  */
-
-bool
-program_space::multi_objfile_p () const
-{
-  return objfiles_head != nullptr && objfiles_head->next != nullptr;
+  if (objfile == symfile_object_file)
+    symfile_object_file = NULL;
 }
 
 /* Copies program space SRC to DEST.  Copies the main executable file,
diff --git a/gdb/progspace.h b/gdb/progspace.h
index 86bc22a..a731eb6 100644
--- a/gdb/progspace.h
+++ b/gdb/progspace.h
@@ -27,6 +27,7 @@
 #include "registry.h"
 #include "gdbsupport/next-iterator.h"
 #include "gdbsupport/safe-iterator.h"
+#include <list>
 
 struct target_ops;
 struct bfd;
@@ -138,20 +139,18 @@
   program_space (address_space *aspace_);
   ~program_space ();
 
-  typedef next_adapter<struct objfile> objfiles_range;
+  typedef std::list<struct objfile *> objfiles_range;
 
   /* Return an iterable object that can be used to iterate over all
      objfiles.  The basic use is in a foreach, like:
 
      for (objfile *objf : pspace->objfiles ()) { ... }  */
-  objfiles_range objfiles ()
+  objfiles_range &objfiles ()
   {
-    return objfiles_range (objfiles_head);
+    return objfiles_list;
   }
 
-  typedef next_adapter<struct objfile,
-		       basic_safe_iterator<next_iterator<objfile>>>
-    objfiles_safe_range;
+  typedef basic_safe_range<objfiles_range> objfiles_safe_range;
 
   /* An iterable object that can be used to iterate over all objfiles.
      The basic use is in a foreach, like:
@@ -162,7 +161,7 @@
      deleted during iteration.  */
   objfiles_safe_range objfiles_safe ()
   {
-    return objfiles_safe_range (objfiles_head);
+    return objfiles_safe_range (objfiles_list);
   }
 
   /* Add OBJFILE to the list of objfiles, putting it just before
@@ -175,7 +174,10 @@
 
   /* Return true if there is more than one object file loaded; false
      otherwise.  */
-  bool multi_objfile_p () const;
+  bool multi_objfile_p () const
+  {
+    return objfiles_list.size () > 1;
+  }
 
 
   /* Pointer to next in linked list.  */
@@ -228,9 +230,8 @@
      (e.g. the argument to the "symbol-file" or "file" command).  */
   struct objfile *symfile_object_file = NULL;
 
-  /* All known objfiles are kept in a linked list.  This points to
-     the head of this list.  */
-  struct objfile *objfiles_head = NULL;
+  /* All known objfiles are kept in a linked list.  */
+  std::list<struct objfile *> objfiles_list;
 
   /* The set of target sections matching the sections mapped into
      this program space.  Managed by both exec_ops and solib.c.  */
@@ -271,10 +272,6 @@
 
 #define symfile_objfile current_program_space->symfile_object_file
 
-/* All known objfiles are kept in a linked list.  This points to the
-   root of this list.  */
-#define object_files current_program_space->objfiles_head
-
 /* The set of target sections matching the sections mapped into the
    current program space.  */
 #define current_target_sections (&current_program_space->target_sections)

-- 
Gerrit-Project: binutils-gdb
Gerrit-Branch: master
Gerrit-Change-Id: Ib4430e3db6f9a390399924379a5c10426c514853
Gerrit-Change-Number: 499
Gerrit-PatchSet: 2
Gerrit-Owner: Tom Tromey <tromey@sourceware.org>
Gerrit-Reviewer: Tom Tromey <tromey@sourceware.org>
Gerrit-CC: Christian Biesinger <cbiesinger@google.com>
Gerrit-MessageType: merged

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [pushed] Store objfiles on a std::list
  2019-11-04  1:35 [review] Store objfiles on a std::list Tom Tromey (Code Review)
                   ` (2 preceding siblings ...)
  2019-11-05  0:38 ` Christian Biesinger (Code Review)
@ 2019-12-12 23:50 ` Sourceware to Gerrit sync (Code Review)
  2019-12-12 23:50 ` Sourceware to Gerrit sync (Code Review)
  4 siblings, 0 replies; 6+ messages in thread
From: Sourceware to Gerrit sync (Code Review) @ 2019-12-12 23:50 UTC (permalink / raw)
  To: Tom Tromey, gdb-patches; +Cc: Christian Biesinger

The original change was created by Tom Tromey.

Change URL: https://gnutoolchain-gerrit.osci.io/r/c/binutils-gdb/+/499
......................................................................

Store objfiles on a std::list

This removes objfile::next and changes objfiles to be stored in a
std::list.

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

	* progspace.c (program_space::add_objfile)
	(program_space::remove_objfile): Update.
	(program_space::multi_objfile_p): Remove.
	* objfiles.h (struct objfile) <next>: Remove.
	* objfiles.c (objfile::objfile): Update.
	(put_objfile_before): Update.
	(unlink_objfile): Update.
	* progspace.h (object_files): Remove.
	(struct program_space) <objfiles_head>: Remove.
	<objfiles_list>: New member.
	<objfiles_range, objfiles_safe_range>: Change type.
	(objfiles): Change return type.
	(objfiles_safe): Update.
	(multi_objfile_p): Rewrite and inline.
	(object_files): Remove macro.

Change-Id: Ib4430e3db6f9a390399924379a5c10426c514853
---
M gdb/ChangeLog
M gdb/objfiles.c
M gdb/objfiles.h
M gdb/progspace.c
M gdb/progspace.h
5 files changed, 45 insertions(+), 59 deletions(-)



diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 368d7f0..9b96f3d 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,23 @@
 2019-12-12  Tom Tromey  <tom@tromey.com>
 
+	* progspace.c (program_space::add_objfile)
+	(program_space::remove_objfile): Update.
+	(program_space::multi_objfile_p): Remove.
+	* objfiles.h (struct objfile) <next>: Remove.
+	* objfiles.c (objfile::objfile): Update.
+	(put_objfile_before): Update.
+	(unlink_objfile): Update.
+	* progspace.h (object_files): Remove.
+	(struct program_space) <objfiles_head>: Remove.
+	<objfiles_list>: New member.
+	<objfiles_range, objfiles_safe_range>: Change type.
+	(objfiles): Change return type.
+	(objfiles_safe): Update.
+	(multi_objfile_p): Rewrite and inline.
+	(object_files): Remove macro.
+
+2019-12-12  Tom Tromey  <tom@tromey.com>
+
 	* gdbsupport/safe-iterator.h (basic_safe_iterator): Simplify.  Add
 	second constructor.
 	(basic_safe_range): New class.
diff --git a/gdb/objfiles.c b/gdb/objfiles.c
index 34f6a29..31265c1 100644
--- a/gdb/objfiles.c
+++ b/gdb/objfiles.c
@@ -54,6 +54,7 @@
 #include "btrace.h"
 #include "gdbsupport/pathstuff.h"
 
+#include <algorithm>
 #include <vector>
 
 /* Keep a registry of per-objfile data-pointers required by other GDB
diff --git a/gdb/objfiles.h b/gdb/objfiles.h
index 0656cfe..f9bf102 100644
--- a/gdb/objfiles.h
+++ b/gdb/objfiles.h
@@ -486,12 +486,6 @@
   }
 
 
-  /* All struct objfile's are chained together by their next pointers.
-     The program space field "objfiles"  (frequently referenced via
-     the macro "object_files") points to the first link in this chain.  */
-
-  struct objfile *next = nullptr;
-
   /* The object file's original name as specified by the user,
      made absolute, and tilde-expanded.  However, it is not canonicalized
      (i.e., it has not been passed through gdb_realpath).
diff --git a/gdb/progspace.c b/gdb/progspace.c
index a39b34c..d1bf0c6 100644
--- a/gdb/progspace.c
+++ b/gdb/progspace.c
@@ -25,6 +25,7 @@
 #include "solib.h"
 #include "gdbthread.h"
 #include "inferior.h"
+#include <algorithm>
 
 /* The last program space number assigned.  */
 int last_program_space_num = 0;
@@ -158,21 +159,15 @@
 void
 program_space::add_objfile (struct objfile *objfile, struct objfile *before)
 {
-  for (struct objfile **objp = &objfiles_head;
-       *objp != NULL;
-       objp = &((*objp)->next))
+  if (before == nullptr)
+    objfiles_list.push_back (objfile);
+  else
     {
-      if (*objp == before)
-	{
-	  objfile->next = *objp;
-	  *objp = objfile;
-	  return;
-	}
+      auto iter = std::find (objfiles_list.begin (), objfiles_list.end (),
+			     before);
+      gdb_assert (iter != objfiles_list.end ());
+      objfiles_list.insert (iter, objfile);
     }
-
-  internal_error (__FILE__, __LINE__,
-		  _("put_objfile_before: before objfile not in list"));
-
 }
 
 /* See progspace.h.  */
@@ -180,32 +175,13 @@
 void
 program_space::remove_objfile (struct objfile *objfile)
 {
-  struct objfile **objpp;
+  auto iter = std::find (objfiles_list.begin (), objfiles_list.end (),
+			 objfile);
+  gdb_assert (iter != objfiles_list.end ());
+  objfiles_list.erase (iter);
 
-  for (objpp = &object_files; *objpp != NULL; objpp = &((*objpp)->next))
-    {
-      if (*objpp == objfile)
-	{
-	  *objpp = (*objpp)->next;
-	  objfile->next = NULL;
-
-	  if (objfile == symfile_object_file)
-	    symfile_object_file = NULL;
-
-	  return;
-	}
-    }
-
-  internal_error (__FILE__, __LINE__,
-		  _("remove_objfile: objfile already unlinked"));
-}
-
-/* See progspace.h.  */
-
-bool
-program_space::multi_objfile_p () const
-{
-  return objfiles_head != nullptr && objfiles_head->next != nullptr;
+  if (objfile == symfile_object_file)
+    symfile_object_file = NULL;
 }
 
 /* Copies program space SRC to DEST.  Copies the main executable file,
diff --git a/gdb/progspace.h b/gdb/progspace.h
index 86bc22a..a731eb6 100644
--- a/gdb/progspace.h
+++ b/gdb/progspace.h
@@ -27,6 +27,7 @@
 #include "registry.h"
 #include "gdbsupport/next-iterator.h"
 #include "gdbsupport/safe-iterator.h"
+#include <list>
 
 struct target_ops;
 struct bfd;
@@ -138,20 +139,18 @@
   program_space (address_space *aspace_);
   ~program_space ();
 
-  typedef next_adapter<struct objfile> objfiles_range;
+  typedef std::list<struct objfile *> objfiles_range;
 
   /* Return an iterable object that can be used to iterate over all
      objfiles.  The basic use is in a foreach, like:
 
      for (objfile *objf : pspace->objfiles ()) { ... }  */
-  objfiles_range objfiles ()
+  objfiles_range &objfiles ()
   {
-    return objfiles_range (objfiles_head);
+    return objfiles_list;
   }
 
-  typedef next_adapter<struct objfile,
-		       basic_safe_iterator<next_iterator<objfile>>>
-    objfiles_safe_range;
+  typedef basic_safe_range<objfiles_range> objfiles_safe_range;
 
   /* An iterable object that can be used to iterate over all objfiles.
      The basic use is in a foreach, like:
@@ -162,7 +161,7 @@
      deleted during iteration.  */
   objfiles_safe_range objfiles_safe ()
   {
-    return objfiles_safe_range (objfiles_head);
+    return objfiles_safe_range (objfiles_list);
   }
 
   /* Add OBJFILE to the list of objfiles, putting it just before
@@ -175,7 +174,10 @@
 
   /* Return true if there is more than one object file loaded; false
      otherwise.  */
-  bool multi_objfile_p () const;
+  bool multi_objfile_p () const
+  {
+    return objfiles_list.size () > 1;
+  }
 
 
   /* Pointer to next in linked list.  */
@@ -228,9 +230,8 @@
      (e.g. the argument to the "symbol-file" or "file" command).  */
   struct objfile *symfile_object_file = NULL;
 
-  /* All known objfiles are kept in a linked list.  This points to
-     the head of this list.  */
-  struct objfile *objfiles_head = NULL;
+  /* All known objfiles are kept in a linked list.  */
+  std::list<struct objfile *> objfiles_list;
 
   /* The set of target sections matching the sections mapped into
      this program space.  Managed by both exec_ops and solib.c.  */
@@ -271,10 +272,6 @@
 
 #define symfile_objfile current_program_space->symfile_object_file
 
-/* All known objfiles are kept in a linked list.  This points to the
-   root of this list.  */
-#define object_files current_program_space->objfiles_head
-
 /* The set of target sections matching the sections mapped into the
    current program space.  */
 #define current_target_sections (&current_program_space->target_sections)

-- 
Gerrit-Project: binutils-gdb
Gerrit-Branch: master
Gerrit-Change-Id: Ib4430e3db6f9a390399924379a5c10426c514853
Gerrit-Change-Number: 499
Gerrit-PatchSet: 2
Gerrit-Owner: Tom Tromey <tromey@sourceware.org>
Gerrit-Reviewer: Tom Tromey <tromey@sourceware.org>
Gerrit-CC: Christian Biesinger <cbiesinger@google.com>
Gerrit-MessageType: newpatchset

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2019-12-12 23:50 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-11-04  1:35 [review] Store objfiles on a std::list Tom Tromey (Code Review)
2019-11-04  5:34 ` Christian Biesinger (Code Review)
2019-11-05  0:16 ` Tom Tromey (Code Review)
2019-11-05  0:38 ` Christian Biesinger (Code Review)
2019-12-12 23:50 ` [pushed] " Sourceware to Gerrit sync (Code Review)
2019-12-12 23:50 ` Sourceware to Gerrit sync (Code Review)

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).