From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id kA/kDac5LWHSeAAAWB0awg (envelope-from ) for ; Mon, 30 Aug 2021 16:03:51 -0400 Received: by simark.ca (Postfix, from userid 112) id 36DCF1EE1C; Mon, 30 Aug 2021 16:03:51 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED, MAILING_LIST_MULTI,T_DKIM_INVALID,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from sourceware.org (server2.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 185CE1E813 for ; Mon, 30 Aug 2021 16:03:50 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id D58303857C69 for ; Mon, 30 Aug 2021 20:03:49 +0000 (GMT) Received: from mail-wm1-x330.google.com (mail-wm1-x330.google.com [IPv6:2a00:1450:4864:20::330]) by sourceware.org (Postfix) with ESMTPS id 6EFB33858404 for ; Mon, 30 Aug 2021 20:03:17 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 6EFB33858404 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=embecosm.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=embecosm.com Received: by mail-wm1-x330.google.com with SMTP id x2-20020a1c7c02000000b002e6f1f69a1eso261379wmc.5 for ; Mon, 30 Aug 2021 13:03:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=/VujfklHmtNrsW1R+xtzjB0VFL8qS9zgOIRxwP2mfbA=; b=A6ZpWU0h9WeGUPg8MwimS5GizaAe/NrN9YnXikWfViYPNfSLZbK+bCGQ/h1AQl+mfs IIglLSlxa8WyIdo+4yJRnRZiL7hNULNftxV8xSxSJpxpMLF0x9qtqjAPoQxnC27tt9j4 tS4IjuT4Fs4WWKiE9htQWDERnzu3eieAVUFaVdGOac/xNm+tSN722yqZNBAvYPufDu97 LoHWogPLSevtZz1KwTGYRPG6nUHnrWlODdCTuqMeWYt/BGIwcTn0sy842uGOmXruDAV0 nGG9nJ4pumdmS1eED6nn4TfwEKsb/PFQehWAqEXVxxV6/U08HCSg2RQK5/KHnW3sUkzN 8nkg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=/VujfklHmtNrsW1R+xtzjB0VFL8qS9zgOIRxwP2mfbA=; b=iqF1HJdFJwU1SSg9GB8hnnhG74aANeGjnaVwHAPiaQS8ysyIIrxj4MaV1zbMRAW7E0 3OywLVxN7SCumr7IK+08na7A8qaYLhBCgE0XDPLgJnPd0kGqFJ45apBsRYbbJUj37DRR 6h0Ly5GfjV7DGmkzwBgSVdAMgb5RlepTlUsSTmmfEYsEcRF73aumslTVzGLqYMVvB0TQ LnEeHO5Rz/BoQd8VpAwGNInb1swzVwi/gxrSrsgbH2ksJhbOJIB4k0cVDYNGV1iz9HE/ 44+OKQAhuwzaghefJAZH9uvdsj/1kZ75noTUsgrQYkwdf7ZaMr+Cj8SRs74cjSn1JYQr ZPYA== X-Gm-Message-State: AOAM530DJKuls9vC04y4Sn/wNrwjlWz5Ek7KJa8iEH/D0rWoC4D4ieGP LuT46agY/fLtLWLK3CRel1YVp9TzBaOYow== X-Google-Smtp-Source: ABdhPJz14ND3umNYVxO+fgFU1wxQ3uCwhRQcn2tjklNjHnZsA5gTiU16sHJJCrm06ce0s/Oh6scQMQ== X-Received: by 2002:a05:600c:3b9c:: with SMTP id n28mr700523wms.184.1630353796302; Mon, 30 Aug 2021 13:03:16 -0700 (PDT) Received: from localhost (host86-188-49-44.range86-188.btcentralplus.com. [86.188.49.44]) by smtp.gmail.com with ESMTPSA id m4sm447847wml.28.2021.08.30.13.03.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Aug 2021 13:03:15 -0700 (PDT) From: Andrew Burgess To: gdb-patches@sourceware.org Subject: [PATCH 2/3] gdb: make thread_suspend_state::stop_pc optional Date: Mon, 30 Aug 2021 21:03:10 +0100 Message-Id: X-Mailer: git-send-email 2.25.4 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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: , Errors-To: gdb-patches-bounces+public-inbox=simark.ca@sourceware.org Sender: "Gdb-patches" 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). 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. After running the testsuite I've seen no other situations where stop_pc is read uninitialised. --- gdb/gdbthread.h | 26 ++++++++++++++++++++++---- gdb/infcmd.c | 2 +- gdb/infrun.c | 3 ++- gdb/thread.c | 2 +- 4 files changed, 26 insertions(+), 7 deletions(-) diff --git a/gdb/gdbthread.h b/gdb/gdbthread.h index 734fe3bce64..245445a859b 100644 --- a/gdb/gdbthread.h +++ b/gdb/gdbthread.h @@ -197,9 +197,12 @@ struct thread_suspend_state stop_reason: if the thread's PC has changed since the thread last stopped, a pending breakpoint waitstatus is discarded. - - If the thread is running, this is set to -1, to avoid leaving - it with a stale value, to make it easier to catch bugs. */ - CORE_ADDR stop_pc = 0; + - If the thread is running, then this field has its value removed by + calling stop_pc.reset() (see thread_info::set_executing()). + Attempting to read a gdb::optional with no value is undefined + behaviour and will trigger an assertion error when _GLIBCXX_DEBUG is + defined, which should make error easier to track down. */ + gdb::optional stop_pc; }; /* Base class for target-specific thread data. */ @@ -326,7 +329,7 @@ class thread_info : public refcounted_object, CORE_ADDR stop_pc () const { - return m_suspend.stop_pc; + return *m_suspend.stop_pc; } /* Set this thread's stop PC. */ @@ -336,6 +339,21 @@ class thread_info : public refcounted_object, m_suspend.stop_pc = stop_pc; } + /* Remove the stop_pc stored on this thread. */ + + void clear_stop_pc () + { + m_suspend.stop_pc.reset (); + } + + /* Return true if this thread has a cached stop pc value, otherwise + return false. */ + + bool stop_pc_p () const + { + return m_suspend.stop_pc.has_value (); + } + /* Return true if this thread has a pending wait status. */ bool has_pending_waitstatus () const diff --git a/gdb/infcmd.c b/gdb/infcmd.c index e6ee49bc43d..d948f4bafc5 100644 --- a/gdb/infcmd.c +++ b/gdb/infcmd.c @@ -249,7 +249,7 @@ post_create_inferior (int from_tty) missing registers info), ignore it. */ thread_info *thr = inferior_thread (); - thr->set_stop_pc (0); + thr->clear_stop_pc (); try { regcache *rc = get_thread_regcache (thr); diff --git a/gdb/infrun.c b/gdb/infrun.c index 11440894b15..5554523a049 100644 --- a/gdb/infrun.c +++ b/gdb/infrun.c @@ -3051,7 +3051,8 @@ proceed (CORE_ADDR addr, enum gdb_signal siggnal) if (addr == (CORE_ADDR) -1) { - if (pc == cur_thr->stop_pc () + if (cur_thr->stop_pc_p () + && pc == cur_thr->stop_pc () && breakpoint_here_p (aspace, pc) == ordinary_breakpoint_here && execution_direction != EXEC_REVERSE) /* There is a breakpoint at the address we will resume at, diff --git a/gdb/thread.c b/gdb/thread.c index c95a9186681..10c3dcd6991 100644 --- a/gdb/thread.c +++ b/gdb/thread.c @@ -324,7 +324,7 @@ thread_info::set_executing (bool executing) { m_executing = executing; if (executing) - this->set_stop_pc (~(CORE_ADDR) 0); + this->clear_stop_pc (); } /* See gdbthread.h. */ -- 2.25.4