From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id C220D3857C6F for ; Tue, 31 May 2022 14:45:00 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org C220D3857C6F Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-670-Ye-VKoSsOHOa7IjWPlGEag-1; Tue, 31 May 2022 10:44:56 -0400 X-MC-Unique: Ye-VKoSsOHOa7IjWPlGEag-1 Received: by mail-wr1-f70.google.com with SMTP id e7-20020adfa747000000b0020fe61b0c62so2126750wrd.22 for ; Tue, 31 May 2022 07:44:56 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=EvVJTk5Wfs7yCKsSlI6sVS+exOAqXSOgIZSlTpniPAk=; b=NNs0YZe+geAbmAfNm4odi2mtwDto7NbGlz98vHpn4waPjuq3dYAXnGNPKbhmO/TQ6r hKa37N8BdcfnuXgyTXpdaR7K5WODDYcQWrpJ6Z1FI6B23e79FwJZmLlihSKIIojzDUtZ KjD70RU9qAoVDj68F9jv+piquhY1inQ41acecxpUX80jfw1YAU4gCErSCOHeLnoeYog+ vS+5K9GNBVeJKuZGxPUXUKG2o1MQolJB1uZiBj85oPXwuUOyMxYAuCKpBIlZC4BtXnWK VcOYVHQQ8+bxbdhsA9+qwCT5SWQsTKWXQmLsmgNq+CgLth2/CYpRyc+LxkDASDRPcNW6 CLSg== X-Gm-Message-State: AOAM533YVJvaZcgHmKQ+5IMdgis9qZcQe3QJj2F26YxuvmMesxeAd5Ag emdcrb9tyDR7jbepS5JQUavTNHVirfhPiNZ/r48HdmiRew99nOzRrwXNpT8K3AXohrCNjUSrUXF 0Y3sduQ7Zpe+E+1Xn1puMPQ== X-Received: by 2002:a5d:4f08:0:b0:20f:c7dc:8477 with SMTP id c8-20020a5d4f08000000b0020fc7dc8477mr41063164wru.713.1654008295331; Tue, 31 May 2022 07:44:55 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxZ+SsLEgFHVhAUuYpG/jZ0k+tsX4+BXy7yV6VoDV+ipNY1zqV1jQgRlx8CYpWk1DgtJg7KqQ== X-Received: by 2002:a5d:4f08:0:b0:20f:c7dc:8477 with SMTP id c8-20020a5d4f08000000b0020fc7dc8477mr41063157wru.713.1654008295116; Tue, 31 May 2022 07:44:55 -0700 (PDT) Received: from localhost (host109-152-215-36.range109-152.btcentralplus.com. [109.152.215.36]) by smtp.gmail.com with ESMTPSA id 63-20020a1c1942000000b003974cb37a94sm2356608wmz.22.2022.05.31.07.44.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 31 May 2022 07:44:54 -0700 (PDT) Date: Tue, 31 May 2022 15:44:53 +0100 From: Andrew Burgess To: Tom Tromey Cc: gdb-patches@sourceware.org Subject: Re: [PATCH] Use unique_ptr for objfiles Message-ID: <20220531144453.GA6045@redhat.com> References: <20220530191421.397009-1-tom@tromey.com> MIME-Version: 1.0 In-Reply-To: <20220530191421.397009-1-tom@tromey.com> X-Operating-System: Linux/5.8.18-100.fc31.x86_64 (x86_64) X-Uptime: 15:44:35 up 3 days, 5:34, X-Editor: GNU Emacs [ http://www.gnu.org/software/emacs ] X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-Spam-Status: No, score=-10.6 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_BARRACUDACENTRAL, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 31 May 2022 14:45:02 -0000 * Tom Tromey [2022-05-30 13:14:21 -0600]: > 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. > > This patch switches objfile management to unique_ptr, which makes more > sense now. LGTM. Thanks, Andrew > > Regression tested on x86-64 Fedora 34. > --- > 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_flags flags_, > if (parent != nullptr) > add_separate_debug_objfile (result, parent); > > - /* 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); > > /* 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 @@ struct objfile > 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 (); > > 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. */ > > void > -program_space::add_objfile (std::shared_ptr &&objfile, > +program_space::add_objfile (std::unique_ptr &&objfile, > struct objfile *before) > { > if (before == nullptr) > @@ -182,7 +182,7 @@ program_space::add_objfile (std::shared_ptr &&objfile, > else > { > auto iter = std::find_if (objfiles_list.begin (), objfiles_list.end (), > - [=] (const std::shared_ptr<::objfile> &objf) > + [=] (const std::unique_ptr<::objfile> &objf) > { > return objf.get () == before; > }); > @@ -203,7 +203,7 @@ program_space::remove_objfile (struct objfile *objfile) > reinit_frame_cache (); > > auto iter = std::find_if (objfiles_list.begin (), objfiles_list.end (), > - [=] (const std::shared_ptr<::objfile> &objf) > + [=] (const std::unique_ptr<::objfile> &objf) > { > return objf.get () == 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; > > -typedef std::list> objfile_list; > +typedef std::list> objfile_list; > > -/* 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); > > /* Remove OBJFILE from the list of objfiles. */ > @@ -354,7 +354,7 @@ struct program_space > struct objfile *symfile_object_file = NULL; > > /* All known objfiles are kept in a linked list. */ > - std::list> objfiles_list; > + std::list> objfiles_list; > > /* List of shared objects mapped into this space. Managed by > solib.c. */ > -- > 2.34.1 >