From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id sKMtJj1mnWj0AgMAWB0awg (envelope-from ) for ; Thu, 14 Aug 2025 00:29:49 -0400 Authentication-Results: simark.ca; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=y3mTjd0U; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 8C05E1E087; Thu, 14 Aug 2025 00:29:49 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-2.4 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED,RCVD_IN_VALIDITY_CERTIFIED_BLOCKED, RCVD_IN_VALIDITY_RPBL_BLOCKED,RCVD_IN_VALIDITY_SAFE_BLOCKED autolearn=ham autolearn_force=no version=4.0.1 Received: from server2.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 ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id B3CDD1E087 for ; Thu, 14 Aug 2025 00:29:48 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 28FFB3858D39 for ; Thu, 14 Aug 2025 04:29:48 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 28FFB3858D39 Authentication-Results: sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=y3mTjd0U Received: from mail-pg1-x52f.google.com (mail-pg1-x52f.google.com [IPv6:2607:f8b0:4864:20::52f]) by sourceware.org (Postfix) with ESMTPS id B60EE3858D20 for ; Thu, 14 Aug 2025 04:29:11 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B60EE3858D20 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=linaro.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org B60EE3858D20 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::52f ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1755145752; cv=none; b=L7+rAiDcBVBp/jlgCMwh/gXc2/jHxf8YqHaLP+F3s+61WzamSm1nwfF52xI+sKMpX2Gh1I6H/lJrlprx4tQMYr4Ysn6bQ5rKJvnJHGBJEnHsd5s2ZKfUWTz6W0NhAYBBb3/ZWhojDsAepZhb7bJcO6gHEnuKNxM4dpAxUXZzgXk= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1755145752; c=relaxed/simple; bh=LoD23EFnTLGm5s5rB/gzmMuEXE2IlSFgX68Npk1MQjU=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=NzUcMcBmBBuRh70P0xEbdXHvzxOOiHEN+/L01w5F1EoN5edEpfGeGjz1mSKK/HkOsJMyNMSFv0UiFs3tTlQtIDlJq8f8IXLSu51To/fiOHrSqti0CEWtgDiBBnaQTZkPdFR7IPd5z03sJo71k+ZDAjYSgU1pooJV7dsJiPdtKSw= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B60EE3858D20 Received: by mail-pg1-x52f.google.com with SMTP id 41be03b00d2f7-b47174b3429so281182a12.2 for ; Wed, 13 Aug 2025 21:29:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1755145751; x=1755750551; darn=sourceware.org; h=content-transfer-encoding:mime-version:message-id:date:user-agent :references:in-reply-to:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=md+i3PBmydhe6dMmeS1IBjTj3zwcxMYdPq0o2FmGDHA=; b=y3mTjd0U84uwEmgqavJW8ym8wRmK4kfgiCPhhqZg9fsVhAmk64MNKKy7c/+29pz36D MECyY+5PK43SH85x81MiDyOu1i3r4hXUyvoalGw7y4Y+7/PTeRzLDywbg/0p3ynohcix p/9O2oAW6t6EyrY9l/vHP8raa12cZUOdK5OytAcp8hHw6vkEAat8slpMiRSxt2jKLKyc VfNLr/Tw21BI1u05Pazc0JaqTFXOnmXacgWUlux21UV9vHotgc5C9g1SWi0c0itFKxuP 7j40o+s2OsuFTtCmNHHlsyLyxuUFCapG7ULCG35MWDHKM+9Hf+/kRqWEhBuOs3rf7R1N S6UA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1755145751; x=1755750551; h=content-transfer-encoding:mime-version:message-id:date:user-agent :references:in-reply-to:subject:cc:to:from:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=md+i3PBmydhe6dMmeS1IBjTj3zwcxMYdPq0o2FmGDHA=; b=dj+tBerFU4ZPNF3+o6TcWjzzZMkjAvdGn5TmgeYMq/fBBfEyoc5uk/Tzc/qhZ+6S47 CFoyxoHXFXSSHTZqeG1yt+EcgoldXgs2EOTxfrxfwIgtKyQr/EiVXQcXT/+Ti+RP3vve e7aG+vLS9z9B+uvyBNt6PuyJwoeq5rAgDSLqHJceBQx9MW4qF6/6VTe7p3+RME6zMRuh UZdaLY9eKqxu5mmwDkFoPBhM4je5drC9LKxJMTTo7ZH2gvl1dSzeGGrkktrAFaPrPrPl OVE/FyH+ox/uPWqFWGaj+qTRtSS2mkPb+0q4Nwp2v4FY4nJ1xCA4iG3By17TmXxPdsL3 hmQQ== X-Gm-Message-State: AOJu0Yz3kQDToxh5Yidag2jF+ouwEuPDTs/a1VoTqaGkrArg9lR0peRN tSgK39s+Oo7vb5/LCvUzVmn4cCs05PAz/oaOGMDJoi9TUJBSXnvoNU6hSm8DR0AO19Y1QVGadQ2 9yxaq X-Gm-Gg: ASbGncsHPcGCfHFdTyXIebQp0hUhbMdDw/36GUyJ+q1vBUqtxCDvgedOoPESjFAk48C l9CCr0ejLSy66gMFIhWt+5EKG8TCHeSlQemkb9fvHVNXJus9/RrPHZO8zQ8jcM7dik1yXO6Ydq4 oLUJrHKGDXyjdjdq1Qp8BsRSg75mRdo6uzuhCYequHZmQRkvYly19hOx7diJBiFsJ1/V3G45kDd MvPyRljXXXR0KHkIIOGNPMngTWiMqrWkw3HXEKS9T1gDFRidqJTkytOQjis50ddRthHAi9ZOkVk 6TVkAF6JM5VXaVJ/eHTrolAIbT/+y1C7kCTzq0OYeyYDltWs8h5Y27IDxCco/yR6r2IqV3tSI92 E9xzQxllqyM0hetudjN32jTuRxXum4giy X-Google-Smtp-Source: AGHT+IF47Zdtd1LvvbFvsUJVcs6KBi1WMPPiJBeTlodYWD6InVhgN+R19kZKki/BC4ub5BbKzJ05Gg== X-Received: by 2002:a17:903:3c6f:b0:240:2145:e526 with SMTP id d9443c01a7336-244584b921dmr22737955ad.6.1755145750578; Wed, 13 Aug 2025 21:29:10 -0700 (PDT) Received: from localhost ([2804:14c:87d5:567d:7642:cf37:4463:bdc4]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-241e8975cf9sm342722635ad.110.2025.08.13.21.29.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Aug 2025 21:29:09 -0700 (PDT) From: Thiago Jung Bauermann To: Markus Metzger Cc: gdb-patches@sourceware.org Subject: Re: [PATCH 2/2] gdb, remote: fix set_thread () in start_remote () In-Reply-To: <20250805071914.3832823-2-markus.t.metzger@intel.com> (Markus Metzger's message of "Tue, 5 Aug 2025 07:19:14 +0000") References: <20250805071914.3832823-1-markus.t.metzger@intel.com> <20250805071914.3832823-2-markus.t.metzger@intel.com> User-Agent: mu4e 1.12.11; emacs 30.1 Date: Thu, 14 Aug 2025 01:29:07 -0300 Message-ID: <87cy8yzfu4.fsf@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 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 Markus Metzger writes: > remote_target::start_remote_1 () calls set_continue_thread (minus_one_pti= d) > with the intent to > > /* Let the stub know that we want it to return the thread. */ > set_continue_thread (minus_one_ptid); > > I interpret it such that it expects a later get_current_thread () to > return the thread selected by the target: > > /* We have thread information; select the thread the target > says should be current. If we're reconnecting to a > multi-threaded program, this will ideally be the thread > that last reported an event before GDB disconnected. */ > ptid_t curr_thread =3D get_current_thread (wait_status); Oh, that makes sense. Thanks for digging into it! > This results in the packet sequence Hc-1, qC. > > Hc simply sets cont_thread: > > else if (cs.own_buf[1] =3D=3D 'c') > cs.cont_thread =3D thread_id; > > write_ok (cs.own_buf); > > and qC returns the general thread. This doesn't match. =F0=9F=A4=A6 > It also has some special treatment for null_ptid and minus_one_ptid: > > if (cs.general_thread !=3D null_ptid && cs.general_thread !=3D minus_= one_ptid) > ptid =3D cs.general_thread; > else > { > init_thread_iter (); > ptid =3D thread_iter->id; > } > > Similarly, Hg has some special treatment for null_ptid: > > if (cs.own_buf[1] =3D=3D 'g') > { > if (thread_id =3D=3D null_ptid) > { > /* GDB is telling us to choose any thread. Check if > the currently selected thread is still valid. If > it is not, select the first available. */ > thread_info *thread =3D find_thread_ptid (cs.general_thread); > if (thread =3D=3D NULL) > thread =3D get_first_thread (); > thread_id =3D thread->id; > } > > cs.general_thread =3D thread_id; > > The comment at Hg matches the intent of GDB for sending Hc-1. Indeed! > Change the set_thread () call in remote_target::start_remote_1 () to > > set_general_thread (any_thread_ptid); > > This results in GDB sending Hg0 and gdbserver preserving the currently > selected thread that is later returned in response to qC. > > CC: Thiago Jung Bauermann > --- > gdb/remote.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) Great! My only suggestion is to try to make the GDB comments more consistent: > diff --git a/gdb/remote.c b/gdb/remote.c > index 6208a90f94a..9b76578bd80 100644 > --- a/gdb/remote.c > +++ b/gdb/remote.c > @@ -5293,7 +5293,7 @@ remote_target::start_remote_1 (int from_tty, int ex= tended_p) > target_update_thread_list (); >=20=20 > /* Let the stub know that we want it to return the thread. */ This comment is a bit cryptic. What about something like: /* Let the stub know that we want it to return the thread id in the qC reply from the get_current_thread call below. */ > - set_continue_thread (minus_one_ptid); > + set_general_thread (any_thread_ptid); >=20=20 > if (thread_count (this) =3D=3D 0) > { Also, your explanation implies that the doc comment in remote_target::set_thread isn't quite right. What about changing it to something along the following lines? -/* If PTID is MAGIC_NULL_PTID, don't set any thread. If PTID is - MINUS_ONE_PTID, set the thread to -1, so the stub returns the - thread. If GEN is set, set the general thread, if not, then set - the step/continue thread. */ +/* If PTID is MAGIC_NULL_PTID or ANY_THREAD_PTID, set the thread to 0. + If PTID is MINUS_ONE_PTID, set the thread to -1. If GEN is set, set + the general thread, if not, then set the step/continue thread. If + the thread is 0 or -1 and GEN is set, the stub returns the thread in + the qC packet reply. */ void remote_target::set_thread (ptid_t ptid, int gen) { @@ -3267,6 +3268,7 @@ remote_target::set_thread (ptid_t ptid, int gen) =20 *buf++ =3D 'H'; *buf++ =3D gen ? 'g' : 'c'; + /* NB: gdbserver interprets 0 and -1 the same way in the H packet. */ if (ptid =3D=3D magic_null_ptid) xsnprintf (buf, endbuf - buf, "0"); else if (ptid =3D=3D any_thread_ptid) One final comment: I agree with your conclusions, but unfortunately I'm not sure of them. The doc comment in remote_target::set_thread gives me a bit of pause. Because of that I don't think I should add a Reviewed-by. Hopefully someone with more experience with the RSP and remote stubs can weigh in. --=20 Thiago