From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca (simark.ca [158.69.221.121]) by sourceware.org (Postfix) with ESMTPS id 312F83858D34 for ; Thu, 9 Jul 2020 03:49:32 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 312F83858D34 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=simark.ca Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=simark@simark.ca Received: from [10.0.0.11] (173-246-6-90.qc.cable.ebox.net [173.246.6.90]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by simark.ca (Postfix) with ESMTPSA id 9D4161E111; Wed, 8 Jul 2020 23:49:31 -0400 (EDT) Subject: Re: [PATCH 3/3] Make scoped_restore_current_thread's cdtors exception free (RFC) To: Pedro Alves , gdb-patches@sourceware.org References: <20200708233125.1030-1-pedro@palves.net> <20200708233125.1030-4-pedro@palves.net> From: Simon Marchi Message-ID: <58a4020f-fbbb-611f-eb23-c1b3fa25d4f2@simark.ca> Date: Wed, 8 Jul 2020 23:49:30 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 MIME-Version: 1.0 In-Reply-To: <20200708233125.1030-4-pedro@palves.net> Content-Type: text/plain; charset=utf-8 Content-Language: fr Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-3.9 required=5.0 tests=BAYES_00, KAM_DMARC_STATUS, SPF_HELO_PASS, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) 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: Thu, 09 Jul 2020 03:49:33 -0000 On 2020-07-08 7:31 p.m., Pedro Alves wrote: > If the remote target closes while we're reading registers/memory for > restoring the selected frame in scoped_restore_current_thread's dtor, > the corresponding TARGET_CLOSE_ERROR error is swallowed by the > scoped_restore_current_thread's dtor, because letting exceptions > escape from a dtor is bad. It isn't great to lose that errors like > that, though. I've been thinking about how to avoid it, and I came up > with this patch. > > The idea here is to make scoped_restore_current_thread's dtor do as > little as possible, to avoid any work that might throw in the first > place. And to do that, instead of having the dtor call > restore_selected_frame, which re-finds the previously selected frame, > just record the frame_id/level of the desired selected frame, and have > get_selected_frame find the frame the next time it is called. In > effect, this implements most of Cagney's suggestion, here: > > /* On demand, create the selected frame and then return it. If the > selected frame can not be created, this function prints then throws > an error. When MESSAGE is non-NULL, use it for the error message, > otherwize use a generic error message. */ > /* FIXME: cagney/2002-11-28: At present, when there is no selected > frame, this function always returns the current (inner most) frame. > It should instead, when a thread has previously had its frame > selected (but not resumed) and the frame cache invalidated, find > and then return that thread's previously selected frame. */ > extern struct frame_info *get_selected_frame (const char *message); > > The only thing missing to fully implement that would be to make > reinit_frame_cache just clear selected_frame instead of calling > select_frame(NULL), and the call select_frame(NULL) explicitly in the > places where we really wanted reinit_frame_cache to go back to the > current frame too. That can done separately, though, I'm not > proposing to do that in this patch. > > restore_selected_frame should really move from thread.c to frame.c, > but I didn't do that here, just to avoid churn in the patch while it > collects comments. I will do that as a preparatory patch if people > agree with this approach. > > Incidentally, this patch alone would fix the crashes fixed by the > previous patches in the series, because with this, > scoped_restore_current_thread's constructor doesn't throw either. I don't understand all the code changes, the but the idea sounds fine to me. > -/* Select frame FI (or NULL - to invalidate the current frame). */ > +/* Select frame FI (or NULL - to invalidate the selected frame). */ > > void > select_frame (struct frame_info *fi) > { > selected_frame = fi; > + selected_frame_level = frame_relative_level (fi); > + if (selected_frame_level == 0) > + { > + /* Treat the current frame especially -- we want to always > + save/restore it without warning, even if the frame ID changes > + (see restore_selected_frame). Also get_frame_id may access > + the target's registers/memory, and thus skipping get_frame_id > + optimizes the common case. */ > + selected_frame_level = -1; > + selected_frame_id = null_frame_id; > + } > + else > + selected_frame_id = get_frame_id (fi); > + I don't really understand this part, why don't we want to set selected_frame_level and selected_frame_id when the level is 0. I'm more interested by why it wouldn't be correct or how it would break things, rather than the optimization aspect. Simon