From patchwork Thu Dec 12 23:50:10 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Simon Marchi (Code Review)" X-Patchwork-Id: 36815 Received: (qmail 102072 invoked by alias); 12 Dec 2019 23:50:30 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 101543 invoked by uid 89); 12 Dec 2019 23:50:27 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-21.8 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3 autolearn=ham version=3.3.1 spammy= X-HELO: mx1.osci.io Received: from polly.osci.io (HELO mx1.osci.io) (8.43.85.229) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 12 Dec 2019 23:50:24 +0000 Received: by mx1.osci.io (Postfix, from userid 994) id 9E74920484; Thu, 12 Dec 2019 18:50:20 -0500 (EST) Received: from gnutoolchain-gerrit.osci.io (gnutoolchain-gerrit.osci.io [8.43.85.239]) by mx1.osci.io (Postfix) with ESMTP id 7E21220C1E; Thu, 12 Dec 2019 18:50:10 -0500 (EST) Received: from localhost (localhost [127.0.0.1]) by gnutoolchain-gerrit.osci.io (Postfix) with ESMTP id 66FD920AF6; Thu, 12 Dec 2019 18:50:10 -0500 (EST) X-Gerrit-PatchSet: 2 Date: Thu, 12 Dec 2019 18:50:10 -0500 From: "Sourceware to Gerrit sync (Code Review)" To: Tom Tromey , gdb-patches@sourceware.org Cc: Christian Biesinger Auto-Submitted: auto-generated X-Gerrit-MessageType: merged Subject: [pushed] Store objfiles on a std::list X-Gerrit-Change-Id: Ib4430e3db6f9a390399924379a5c10426c514853 X-Gerrit-Change-Number: 499 X-Gerrit-ChangeURL: X-Gerrit-Commit: d0801dd8f22a3e739c6a7d126d45829df981794d In-Reply-To: References: Reply-To: noreply@gnutoolchain-gerrit.osci.io, tromey@sourceware.org, cbiesinger@google.com, gdb-patches@sourceware.org MIME-Version: 1.0 Content-Disposition: inline User-Agent: Gerrit/3.0.3-79-g83ff7f88f1 Message-Id: <20191212235010.66FD920AF6@gnutoolchain-gerrit.osci.io> 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 * progspace.c (program_space::add_objfile) (program_space::remove_objfile): Update. (program_space::multi_objfile_p): Remove. * objfiles.h (struct objfile) : Remove. * objfiles.c (objfile::objfile): Update. (put_objfile_before): Update. (unlink_objfile): Update. * progspace.h (object_files): Remove. (struct program_space) : Remove. : New member. : 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 + * progspace.c (program_space::add_objfile) + (program_space::remove_objfile): Update. + (program_space::multi_objfile_p): Remove. + * objfiles.h (struct objfile) : Remove. + * objfiles.c (objfile::objfile): Update. + (put_objfile_before): Update. + (unlink_objfile): Update. + * progspace.h (object_files): Remove. + (struct program_space) : Remove. + : New member. + : Change type. + (objfiles): Change return type. + (objfiles_safe): Update. + (multi_objfile_p): Rewrite and inline. + (object_files): Remove macro. + +2019-12-12 Tom Tromey + * 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 #include /* 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 /* 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 struct target_ops; struct bfd; @@ -138,20 +139,18 @@ program_space (address_space *aspace_); ~program_space (); - typedef next_adapter objfiles_range; + typedef std::list 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>> - objfiles_safe_range; + typedef basic_safe_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 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 (¤t_program_space->target_sections)