From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2126) id 866243836E69; Tue, 31 May 2022 20:58:23 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 866243836E69 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Tom Tromey To: gdb-cvs@sourceware.org Subject: [binutils-gdb] Use unique_ptr for objfiles X-Act-Checkin: binutils-gdb X-Git-Author: Tom Tromey X-Git-Refname: refs/heads/master X-Git-Oldrev: ebad7c66133526eb9ea9b21dad2df49a65200df0 X-Git-Newrev: e2904e1ff0b0158cf6d8d335ca3f80ff7dc9eb6c Message-Id: <20220531205823.866243836E69@sourceware.org> Date: Tue, 31 May 2022 20:58:23 +0000 (GMT) X-BeenThere: gdb-cvs@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 31 May 2022 20:58:23 -0000 https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3De2904e1ff0b0= 158cf6d8d335ca3f80ff7dc9eb6c commit e2904e1ff0b0158cf6d8d335ca3f80ff7dc9eb6c Author: Tom Tromey Date: Sat May 21 09:50:13 2022 -0600 Use unique_ptr for objfiles =20 A while back, I changed objfiles to be held via a shared_ptr. The idea at the time was that this was a step toward writing to the index cache in the background, and this would let gdb keep a reference alive to do so. However, since then we've rewritten the DWARF reader, and the new index can do this without requiring a shared pointer -- in fact there are patches pending to implement this. =20 This patch switches objfile management to unique_ptr, which makes more sense now. =20 Regression tested on x86-64 Fedora 34. Diff: --- gdb/objfiles.c | 4 +--- gdb/objfiles.h | 2 +- gdb/progspace.c | 6 +++--- gdb/progspace.h | 8 ++++---- 4 files changed, 9 insertions(+), 11 deletions(-) diff --git a/gdb/objfiles.c b/gdb/objfiles.c index 80f68fda1c1..60d8aa5cb78 100644 --- a/gdb/objfiles.c +++ b/gdb/objfiles.c @@ -468,9 +468,7 @@ objfile::make (bfd *bfd_, const char *name_, objfile_fl= ags flags_, if (parent !=3D nullptr) add_separate_debug_objfile (result, parent); =20 - /* Using std::make_shared might be a bit nicer here, but that would - require making the constructor public. */ - current_program_space->add_objfile (std::shared_ptr (result), + current_program_space->add_objfile (std::unique_ptr (result), parent); =20 /* Rebuild section map next time we need it. */ diff --git a/gdb/objfiles.h b/gdb/objfiles.h index 9da12ff12e0..a7098b46279 100644 --- a/gdb/objfiles.h +++ b/gdb/objfiles.h @@ -409,7 +409,7 @@ public: remove it from the program space's list. In some cases, you may need to hold a reference to an objfile that is independent of its existence on the program space's list; for this case, the - destructor must be public so that shared_ptr can reference + destructor must be public so that unique_ptr can reference it. */ ~objfile (); =20 diff --git a/gdb/progspace.c b/gdb/progspace.c index 1ee4fe3f940..8735343fabc 100644 --- a/gdb/progspace.c +++ b/gdb/progspace.c @@ -174,7 +174,7 @@ program_space::free_all_objfiles () /* See progspace.h. */ =20 void -program_space::add_objfile (std::shared_ptr &&objfile, +program_space::add_objfile (std::unique_ptr &&objfile, struct objfile *before) { if (before =3D=3D nullptr) @@ -182,7 +182,7 @@ program_space::add_objfile (std::shared_ptr &&= objfile, else { auto iter =3D std::find_if (objfiles_list.begin (), objfiles_list.en= d (), - [=3D] (const std::shared_ptr<::objfile> &objf) + [=3D] (const std::unique_ptr<::objfile> &objf) { return objf.get () =3D=3D before; }); @@ -203,7 +203,7 @@ program_space::remove_objfile (struct objfile *objfile) reinit_frame_cache (); =20 auto iter =3D std::find_if (objfiles_list.begin (), objfiles_list.end (), - [=3D] (const std::shared_ptr<::objfile> &objf) + [=3D] (const std::unique_ptr<::objfile> &objf) { return objf.get () =3D=3D objfile; }); diff --git a/gdb/progspace.h b/gdb/progspace.h index 73beb7a4710..662e569488e 100644 --- a/gdb/progspace.h +++ b/gdb/progspace.h @@ -41,9 +41,9 @@ struct program_space_data; struct address_space_data; struct so_list; =20 -typedef std::list> objfile_list; +typedef std::list> objfile_list; =20 -/* An iterator that wraps an iterator over std::shared_ptr, +/* An iterator that wraps an iterator over std::unique_ptr, and dereferences the returned object. This is useful for iterating over a list of shared pointers and returning raw pointers -- which helped avoid touching a lot of code when changing how objfiles are @@ -234,7 +234,7 @@ struct program_space /* Add OBJFILE to the list of objfiles, putting it just before BEFORE. If BEFORE is nullptr, it will go at the end of the list. */ - void add_objfile (std::shared_ptr &&objfile, + void add_objfile (std::unique_ptr &&objfile, struct objfile *before); =20 /* Remove OBJFILE from the list of objfiles. */ @@ -354,7 +354,7 @@ struct program_space struct objfile *symfile_object_file =3D NULL; =20 /* All known objfiles are kept in a linked list. */ - std::list> objfiles_list; + std::list> objfiles_list; =20 /* List of shared objects mapped into this space. Managed by solib.c. */