Message ID | 20230503175826.4242-1-tdevries@suse.de |
---|---|
State | Committed |
Headers |
Return-Path: <gdb-patches-bounces+patchwork=sourceware.org@sourceware.org> X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 09F77385770E for <patchwork@sourceware.org>; Wed, 3 May 2023 17:58:52 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 09F77385770E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1683136732; bh=M0CElmccCEepmrSeNKOnsTS+BoQclVDAX5hOydHAbzY=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=v3AJfpy5U5W1KW/9FJapxRo+fKsx5dWF2i8uc1ob0zBYrPVFZL4Tiqjp4wlm9vpJy 51nvkIwrVENYXSgYQA+d8JRw44+Ysa4dm0XaJQu+V6l8zJFSyi17i2XjnRaP0t9l/L N+CYiXtaa36UEcQGdDJg8AKeuKydDyGfu0eecjDk= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by sourceware.org (Postfix) with ESMTPS id 62CE73858D28 for <gdb-patches@sourceware.org>; Wed, 3 May 2023 17:58:28 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 62CE73858D28 Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 903DB20183; Wed, 3 May 2023 17:58:27 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 7883C13584; Wed, 3 May 2023 17:58:27 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id gvRGHMOgUmQtMwAAMHmgww (envelope-from <tdevries@suse.de>); Wed, 03 May 2023 17:58:27 +0000 To: gdb-patches@sourceware.org Cc: Simon Marchi <simon.marchi@polymtl.ca> Subject: [PATCH] [gdb/build] Fix frame_list position in frame.c Date: Wed, 3 May 2023 19:58:26 +0200 Message-Id: <20230503175826.4242-1-tdevries@suse.de> X-Mailer: git-send-email 2.35.3 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-12.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, SPF_HELO_NONE, SPF_PASS, 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 <gdb-patches.sourceware.org> List-Unsubscribe: <https://sourceware.org/mailman/options/gdb-patches>, <mailto:gdb-patches-request@sourceware.org?subject=unsubscribe> List-Archive: <https://sourceware.org/pipermail/gdb-patches/> List-Post: <mailto:gdb-patches@sourceware.org> List-Help: <mailto:gdb-patches-request@sourceware.org?subject=help> List-Subscribe: <https://sourceware.org/mailman/listinfo/gdb-patches>, <mailto:gdb-patches-request@sourceware.org?subject=subscribe> From: Tom de Vries via Gdb-patches <gdb-patches@sourceware.org> Reply-To: Tom de Vries <tdevries@suse.de> Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" <gdb-patches-bounces+patchwork=sourceware.org@sourceware.org> |
Series |
[gdb/build] Fix frame_list position in frame.c
|
|
Commit Message
Tom de Vries
May 3, 2023, 5:58 p.m. UTC
In commit 995a34b1772 ("Guard against frame.c destructors running before frame-info.c's") the following problem was addressed. The frame_info_ptr destructor: ... ~frame_info_ptr () { frame_list.erase (frame_list.iterator_to (*this)); } ... uses frame_list, which is a static member of class frame_info_ptr, instantiated in frame-info.c: ... intrusive_list<frame_info_ptr> frame_info_ptr::frame_list; ... Then there's a static frame_info_pointer variable named selected_frame in frame.c: ... static frame_info_ptr selected_frame; ... Because the destructor of selected_frame uses frame_list, its destructor needs to be called before the destructor of frame_list. But because they're in different compilation units, the initialization order and consequently destruction order is not guarantueed. The commit fixed this by handling the case that the destructor of frame_list is called first, adding a check on is_linked (): ... ~frame_info_ptr () { - frame_list.erase (frame_list.iterator_to (*this)); + /* If this node has static storage, it may be deleted after + frame_list. Attempting to erase ourselves would then trigger + internal errors, so make sure we are still linked first. */ + if (is_linked ()) + frame_list.erase (frame_list.iterator_to (*this)); } ... However, since then frame_list has been moved into frame.c, and initialization/destruction order is guarantueed inside a compilation unit. Revert aforementioned commit, and fix the destruction order problem by moving frame_list before selected_frame. Reverting the commit is another way of fixing the already fixed Wdangling-pointer warning reported in PR build/30413, in a different way than commit 9b0ccb1ebae ("Pass const frame_info_ptr reference for skip_[language_]trampoline"). Tested on x86_64-linux. PR build/30413 Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30413 --- gdb/frame.c | 11 +++++++---- gdb/frame.h | 9 ++++----- 2 files changed, 11 insertions(+), 9 deletions(-) base-commit: 2ad00a4b42f89b61fdab24940b67713daf81c988
Comments
On 5/3/23 13:58, Tom de Vries wrote: > In commit 995a34b1772 ("Guard against frame.c destructors running before > frame-info.c's") the following problem was addressed. > > The frame_info_ptr destructor: > ... > ~frame_info_ptr () > { > frame_list.erase (frame_list.iterator_to (*this)); > } > ... > uses frame_list, which is a static member of class frame_info_ptr, > instantiated in frame-info.c: > ... > intrusive_list<frame_info_ptr> frame_info_ptr::frame_list; > ... > > Then there's a static frame_info_pointer variable named selected_frame in > frame.c: > ... > static frame_info_ptr selected_frame; > ... > > Because the destructor of selected_frame uses frame_list, its destructor needs > to be called before the destructor of frame_list. > > But because they're in different compilation units, the initialization order and > consequently destruction order is not guarantueed. > > The commit fixed this by handling the case that the destructor of frame_list > is called first, adding a check on is_linked (): > ... > ~frame_info_ptr () > { > - frame_list.erase (frame_list.iterator_to (*this)); > + /* If this node has static storage, it may be deleted after > + frame_list. Attempting to erase ourselves would then trigger > + internal errors, so make sure we are still linked first. */ > + if (is_linked ()) > + frame_list.erase (frame_list.iterator_to (*this)); > } > ... > > However, since then frame_list has been moved into frame.c, and > initialization/destruction order is guarantueed inside a compilation unit. > > Revert aforementioned commit, and fix the destruction order problem by moving > frame_list before selected_frame. > > Reverting the commit is another way of fixing the already fixed > Wdangling-pointer warning reported in PR build/30413, in a different way than > commit 9b0ccb1ebae ("Pass const frame_info_ptr reference for > skip_[language_]trampoline"). > > Tested on x86_64-linux. > > PR build/30413 > Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30413 > --- > gdb/frame.c | 11 +++++++---- > gdb/frame.h | 9 ++++----- > 2 files changed, 11 insertions(+), 9 deletions(-) > > diff --git a/gdb/frame.c b/gdb/frame.c > index 36fb02f3c8e..531eadf3d54 100644 > --- a/gdb/frame.c > +++ b/gdb/frame.c > @@ -1733,6 +1733,13 @@ get_current_frame (void) > static frame_id selected_frame_id = null_frame_id; > static int selected_frame_level = -1; > > +/* See frame.h. This definition should come before any definition of a static > + frame_info_ptr, to ensure that frame_list is destroyed after any static > + frame_info_ptr. This is necessary because the destructor of frame_info_ptr Spurious double space. > + uses frame_list. */ > + > +intrusive_list<frame_info_ptr> frame_info_ptr::frame_list; > + > /* The cached frame_info object pointing to the selected frame. > Looked up on demand by get_selected_frame. */ > static frame_info_ptr selected_frame; > @@ -3275,10 +3282,6 @@ maintenance_print_frame_id (const char *args, int from_tty) > > /* See frame-info-ptr.h. */ > > -intrusive_list<frame_info_ptr> frame_info_ptr::frame_list; > - > -/* See frame-info-ptr.h. */ > - > frame_info_ptr::frame_info_ptr (struct frame_info *ptr) > : m_ptr (ptr) > { > diff --git a/gdb/frame.h b/gdb/frame.h > index 6ed8db0af56..ed19dfdc090 100644 > --- a/gdb/frame.h > +++ b/gdb/frame.h > @@ -254,11 +254,10 @@ class frame_info_ptr : public intrusive_list_node<frame_info_ptr> > > ~frame_info_ptr () > { > - /* If this node has static storage, it may be deleted after > - frame_list. Attempting to erase ourselves would then trigger > - internal errors, so make sure we are still linked first. */ > - if (is_linked ()) > - frame_list.erase (frame_list.iterator_to (*this)); > + /* If this node has static storage, it should be be deleted before > + frame_list. Verify this by checking that it is still in the list. */ > + gdb_assert (is_linked ()); > + frame_list.erase (frame_list.iterator_to (*this)); The assert is a bit redundant with the assertions in intrusive_list::erase_element: gdb_assert (elem_node->prev != INTRUSIVE_LIST_UNLINKED_VALUE); gdb_assert (elem_node->next != INTRUSIVE_LIST_UNLINKED_VALUE); I would maybe remove the assert, but keep the comment (at least the first sentence)? In any case, this LGTM, thanks for doing this. Approved-By: Simon Marchi <simon.marchi@efficios.com> Simon
On 5/3/23 20:47, Simon Marchi wrote: > On 5/3/23 13:58, Tom de Vries wrote: >> In commit 995a34b1772 ("Guard against frame.c destructors running before >> frame-info.c's") the following problem was addressed. >> >> The frame_info_ptr destructor: >> ... >> ~frame_info_ptr () >> { >> frame_list.erase (frame_list.iterator_to (*this)); >> } >> ... >> uses frame_list, which is a static member of class frame_info_ptr, >> instantiated in frame-info.c: >> ... >> intrusive_list<frame_info_ptr> frame_info_ptr::frame_list; >> ... >> >> Then there's a static frame_info_pointer variable named selected_frame in >> frame.c: >> ... >> static frame_info_ptr selected_frame; >> ... >> >> Because the destructor of selected_frame uses frame_list, its destructor needs >> to be called before the destructor of frame_list. >> >> But because they're in different compilation units, the initialization order and >> consequently destruction order is not guarantueed. >> >> The commit fixed this by handling the case that the destructor of frame_list >> is called first, adding a check on is_linked (): >> ... >> ~frame_info_ptr () >> { >> - frame_list.erase (frame_list.iterator_to (*this)); >> + /* If this node has static storage, it may be deleted after >> + frame_list. Attempting to erase ourselves would then trigger >> + internal errors, so make sure we are still linked first. */ >> + if (is_linked ()) >> + frame_list.erase (frame_list.iterator_to (*this)); >> } >> ... >> >> However, since then frame_list has been moved into frame.c, and >> initialization/destruction order is guarantueed inside a compilation unit. >> >> Revert aforementioned commit, and fix the destruction order problem by moving >> frame_list before selected_frame. >> >> Reverting the commit is another way of fixing the already fixed >> Wdangling-pointer warning reported in PR build/30413, in a different way than >> commit 9b0ccb1ebae ("Pass const frame_info_ptr reference for >> skip_[language_]trampoline"). >> >> Tested on x86_64-linux. >> >> PR build/30413 >> Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30413 >> --- >> gdb/frame.c | 11 +++++++---- >> gdb/frame.h | 9 ++++----- >> 2 files changed, 11 insertions(+), 9 deletions(-) >> >> diff --git a/gdb/frame.c b/gdb/frame.c >> index 36fb02f3c8e..531eadf3d54 100644 >> --- a/gdb/frame.c >> +++ b/gdb/frame.c >> @@ -1733,6 +1733,13 @@ get_current_frame (void) >> static frame_id selected_frame_id = null_frame_id; >> static int selected_frame_level = -1; >> >> +/* See frame.h. This definition should come before any definition of a static >> + frame_info_ptr, to ensure that frame_list is destroyed after any static >> + frame_info_ptr. This is necessary because the destructor of frame_info_ptr > > Spurious double space. > Fixed. >> + uses frame_list. */ >> + >> +intrusive_list<frame_info_ptr> frame_info_ptr::frame_list; >> + >> /* The cached frame_info object pointing to the selected frame. >> Looked up on demand by get_selected_frame. */ >> static frame_info_ptr selected_frame; >> @@ -3275,10 +3282,6 @@ maintenance_print_frame_id (const char *args, int from_tty) >> >> /* See frame-info-ptr.h. */ >> >> -intrusive_list<frame_info_ptr> frame_info_ptr::frame_list; >> - >> -/* See frame-info-ptr.h. */ >> - >> frame_info_ptr::frame_info_ptr (struct frame_info *ptr) >> : m_ptr (ptr) >> { >> diff --git a/gdb/frame.h b/gdb/frame.h >> index 6ed8db0af56..ed19dfdc090 100644 >> --- a/gdb/frame.h >> +++ b/gdb/frame.h >> @@ -254,11 +254,10 @@ class frame_info_ptr : public intrusive_list_node<frame_info_ptr> >> >> ~frame_info_ptr () >> { >> - /* If this node has static storage, it may be deleted after >> - frame_list. Attempting to erase ourselves would then trigger >> - internal errors, so make sure we are still linked first. */ >> - if (is_linked ()) >> - frame_list.erase (frame_list.iterator_to (*this)); >> + /* If this node has static storage, it should be be deleted before >> + frame_list. Verify this by checking that it is still in the list. */ >> + gdb_assert (is_linked ()); >> + frame_list.erase (frame_list.iterator_to (*this)); > > The assert is a bit redundant with the assertions in > intrusive_list::erase_element: > > gdb_assert (elem_node->prev != INTRUSIVE_LIST_UNLINKED_VALUE); > gdb_assert (elem_node->next != INTRUSIVE_LIST_UNLINKED_VALUE); > > I would maybe remove the assert, but keep the comment (at least the > first sentence)? > Ack, I checked by doing: ... +static frame_info_ptr bad_frame; intrusive_list<frame_info_ptr> frame_info_ptr::frame_list; ... and indeed those assertions trigger, so done. > In any case, this LGTM, thanks for doing this. > > Approved-By: Simon Marchi <simon.marchi@efficios.com> > Committed, thanks for the review. - Tom
Tom de Vries <tdevries@suse.de> writes: > On 5/3/23 20:47, Simon Marchi wrote: > >> In any case, this LGTM, thanks for doing this. Seconded, thanks for getting rid of that if guard. I find the new state of affairs (everything defined in the same unit, in the correct order) easier to grok.
On 5/4/23 11:01, Kévin Le Gouguec wrote: > Tom de Vries <tdevries@suse.de> writes: > >> On 5/3/23 20:47, Simon Marchi wrote: >> >>> In any case, this LGTM, thanks for doing this. > > Seconded, thanks for getting rid of that if guard. I find the new state > of affairs (everything defined in the same unit, in the correct order) > easier to grok. Hi Kévin, thanks for the review and the confirmation. - Tom
diff --git a/gdb/frame.c b/gdb/frame.c index 36fb02f3c8e..531eadf3d54 100644 --- a/gdb/frame.c +++ b/gdb/frame.c @@ -1733,6 +1733,13 @@ get_current_frame (void) static frame_id selected_frame_id = null_frame_id; static int selected_frame_level = -1; +/* See frame.h. This definition should come before any definition of a static + frame_info_ptr, to ensure that frame_list is destroyed after any static + frame_info_ptr. This is necessary because the destructor of frame_info_ptr + uses frame_list. */ + +intrusive_list<frame_info_ptr> frame_info_ptr::frame_list; + /* The cached frame_info object pointing to the selected frame. Looked up on demand by get_selected_frame. */ static frame_info_ptr selected_frame; @@ -3275,10 +3282,6 @@ maintenance_print_frame_id (const char *args, int from_tty) /* See frame-info-ptr.h. */ -intrusive_list<frame_info_ptr> frame_info_ptr::frame_list; - -/* See frame-info-ptr.h. */ - frame_info_ptr::frame_info_ptr (struct frame_info *ptr) : m_ptr (ptr) { diff --git a/gdb/frame.h b/gdb/frame.h index 6ed8db0af56..ed19dfdc090 100644 --- a/gdb/frame.h +++ b/gdb/frame.h @@ -254,11 +254,10 @@ class frame_info_ptr : public intrusive_list_node<frame_info_ptr> ~frame_info_ptr () { - /* If this node has static storage, it may be deleted after - frame_list. Attempting to erase ourselves would then trigger - internal errors, so make sure we are still linked first. */ - if (is_linked ()) - frame_list.erase (frame_list.iterator_to (*this)); + /* If this node has static storage, it should be be deleted before + frame_list. Verify this by checking that it is still in the list. */ + gdb_assert (is_linked ()); + frame_list.erase (frame_list.iterator_to (*this)); } frame_info_ptr &operator= (const frame_info_ptr &other)