From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by sourceware.org (Postfix) with ESMTPS id 3CD253858D28 for ; Wed, 3 May 2023 19:46:01 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 3CD253858D28 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=suse.de 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 0FB13206B5; Wed, 3 May 2023 19:46:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1683143160; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=fT3f1bzhHFL/m0DttSZW6e3TPw2JiZebJ+JPTFrnuDw=; b=dlsr4JliG/pT0zVIk8KdWk8a9xKSfu5jb0ftPssZPIZ43kD92qtZdQKfnwXTojH6N1jpuX ljOmXid8EoMaxhsuyr95ufoHaRs6Jfxd6T3P0OqvSPgdKDaMek+8dERX9C/gvKd0mTSppc SoVwbTwKI0kZ2sBURhzIwydvd9lDpUc= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1683143160; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=fT3f1bzhHFL/m0DttSZW6e3TPw2JiZebJ+JPTFrnuDw=; b=8xRPRG9p2Cbr1+6coOhh+4MuNczLHH9CXbwOumnRlGl3tX4jZZ022RWH6G5eIeDODPYQaE lhSIP9m0yWwi19BA== 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 EFD3D13584; Wed, 3 May 2023 19:45:59 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id zIVjOfe5UmQoZQAAMHmgww (envelope-from ); Wed, 03 May 2023 19:45:59 +0000 Message-ID: Date: Wed, 3 May 2023 21:45:59 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.10.1 Subject: Re: [PATCH] [gdb/build] Fix frame_list position in frame.c Content-Language: en-US To: Simon Marchi , gdb-patches@sourceware.org References: <20230503175826.4242-1-tdevries@suse.de> <7ccea69e-7cce-9016-06a4-e63b3bf16a17@polymtl.ca> From: Tom de Vries In-Reply-To: <7ccea69e-7cce-9016-06a4-e63b3bf16a17@polymtl.ca> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-14.7 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,NICE_REPLY_A,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 List-Id: 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_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_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_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 () >> { >> - /* 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_list; ... and indeed those assertions trigger, so done. > In any case, this LGTM, thanks for doing this. > > Approved-By: Simon Marchi > Committed, thanks for the review. - Tom