From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id /3hjDgmNL2HEQwAAWB0awg (envelope-from ) for ; Wed, 01 Sep 2021 10:24:09 -0400 Received: by simark.ca (Postfix, from userid 112) id 238AF1EE21; Wed, 1 Sep 2021 10:24:09 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-1.7 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,MAILING_LIST_MULTI,NICE_REPLY_A,RDNS_DYNAMIC, URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from sourceware.org (ip-8-43-85-97.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 2D3351E813 for ; Wed, 1 Sep 2021 10:24:08 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id C9709385AC2B for ; Wed, 1 Sep 2021 14:24:07 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C9709385AC2B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1630506247; bh=hiZva8mt7PBNiOqB/dGhjpJTE3qyPjaLOvvrfcNo9PM=; h=Subject:To:References:Date:In-Reply-To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=MA5yhOsjaySr0bx2KLedxdOu42fr7pTNr9ub24IzLUftAsXziuqJRYaOBzbX3kr8O PPypQRiZSlTfjr1VrwgIqUO/sF9ggLOsX54KlnJxOgiWXCi57pc3x/1yff9iIydwjy KBMbU9UqlkhaijXVQkezy1lCZKwtUSaD6UVrm3og= Received: from smtp.polymtl.ca (smtp.polymtl.ca [132.207.4.11]) by sourceware.org (Postfix) with ESMTPS id 7A1343858411 for ; Wed, 1 Sep 2021 14:23:39 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 7A1343858411 Received: from simark.ca (simark.ca [158.69.221.121]) (authenticated bits=0) by smtp.polymtl.ca (8.14.7/8.14.7) with ESMTP id 181ENXNh029133 (version=TLSv1/SSLv3 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 1 Sep 2021 10:23:37 -0400 DKIM-Filter: OpenDKIM Filter v2.11.0 smtp.polymtl.ca 181ENXNh029133 Received: from [10.0.0.11] (192-222-157-6.qc.cable.ebox.net [192.222.157.6]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPSA id DA5C61E813; Wed, 1 Sep 2021 10:23:32 -0400 (EDT) Subject: Re: [PATCH 2/3] gdb: make thread_suspend_state::stop_pc optional To: Andrew Burgess , gdb-patches@sourceware.org References: Message-ID: <8c0e958f-e5a6-8ed4-7326-99153e7c5faf@polymtl.ca> Date: Wed, 1 Sep 2021 10:23:32 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.13.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-Poly-FromMTA: (simark.ca [158.69.221.121]) at Wed, 1 Sep 2021 14:23:33 +0000 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: , From: Simon Marchi via Gdb-patches Reply-To: Simon Marchi Errors-To: gdb-patches-bounces+public-inbox=simark.ca@sourceware.org Sender: "Gdb-patches" On 2021-08-30 4:03 p.m., Andrew Burgess wrote: > Currently the stop_pc field of thread_suspect_state is a CORE_ADDR and > when we want to indicate that there is no stop_pc available we set > this field back to a special value. > > There are actually two special values used, in post_create_inferior > the stop_pc is set to 0. This is a little unfortunate, there are > plenty of embedded targets where 0 is a valid pc address. The more > common special value for stop_pc was set in > thread_info::set_executing, where the value (~(CORE_ADDR) 0) was used. > > This commit changes things so that the stop_pc is instead a > gdb::optional. We can now explicitly reset the field to an > uninitialised state, we also have (when compiling with _GLIBCXX_DEBUG > defined) asserts that we don't read the stop_pc when its in an > uninitialised state (see gdbsupport/gdb_optional.h). Thanks, I think it's a good idea. > One situation where a thread will not have a stop_pc value is when the > thread is stopped as a consequence of GDB being in all stop mode, and > some other thread stopped at an interesting event. When GDB brings > all the other threads to a stop those other threads will not have a > stop_pc set (thus avoiding an unnecessary read of $pc). > > Previously, when GDB passed through handle_one (in infrun.c) the > threads executing flag was set to false and the stop_pc field was left > unchanged, i.e. it would (previous) have been left as ~0. > > Now, handle_one leaves the stop_pc with no value. > > This caused a problem when we later try to set these threads running > again, in proceed() we compare the current pc with the cached > stop_pc. If the thread was stopped in via handle_one then the stop_pc > would have been left as ~0, and the compare (in proceed) > would (likely) fail. Now however, this compare tries to read the > stop_pc when it has no value, this would trigger an assert. > > To resolve this I've added thread_info::stop_pc_p() which returns true > if the thread has a cached stop_pc. We should only ever call > thread_info::stop_pc() if we know that there is a cached stop_pc. We could also make stop_pc return gdb::optional. I think it would be slightly better, since anybody calling stop_pc would see that it returns an optional and be forced to consider that. Otherwise, one could call stop_pc and not know that stop_pc_p exists. But otherwise it's the same. LGTM in any case. Simon