From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id KAZSFBHE+GltBBMAWB0awg (envelope-from ) for ; Mon, 04 May 2026 12:06:41 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=simark.ca; s=mail; t=1777910801; bh=pcNSsEhWGvXEDe1GEBVFccoEJQYM0zyLyCH9wWIWyPo=; h=Date:Subject:To:References:From:In-Reply-To:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=P9PMyCBwiHBeqgE+taN/Nc38xe6BORPCpgFhWfdDKwGYLsc4LiN7fbx2p1BeGkmBU rx83FFalKHzN5lkzlGUltQ+7dFr39+hYXxrX6igVMThFcZoe4UGPMxFdaOqfDP2zgH HKvXx6tW+4Bz4BrE1mhRrUyB0iCkh5Bj9Of1L7r0= Received: by simark.ca (Postfix, from userid 112) id 38D561E0BA; Mon, 04 May 2026 12:06:41 -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 Authentication-Results: simark.ca; dkim=pass (1024-bit key; unprotected) header.d=simark.ca header.i=@simark.ca header.a=rsa-sha256 header.s=mail header.b=QkoRN2ZX; dkim-atps=neutral Received: from vm01.sourceware.org (vm01.sourceware.org [38.145.34.32]) (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 999471E067 for ; Mon, 04 May 2026 12:06:40 -0400 (EDT) Received: from vm01.sourceware.org (localhost [127.0.0.1]) by sourceware.org (Postfix) with ESMTP id 38A844BABF12 for ; Mon, 4 May 2026 16:06:40 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 38A844BABF12 Authentication-Results: sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=simark.ca header.i=@simark.ca header.a=rsa-sha256 header.s=mail header.b=QkoRN2ZX Received: from simark.ca (simark.ca [158.69.221.121]) by sourceware.org (Postfix) with ESMTPS id 8D5944BA903F for ; Mon, 4 May 2026 16:06:15 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 8D5944BA903F Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=simark.ca Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=simark.ca ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 8D5944BA903F Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=158.69.221.121 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1777910775; cv=none; b=kbuHoXTzgSMuLYAbX3rgag5e9lhyL9OHRLZ2zNBZiXSjxFuBxHevwuhFo6ZbUWryMM7s7TGbfQPLQdcY/XaaEvWRGB6C/rAjxvKg/TFzdpO8QmEWwyXBkS9SeYSmmE9wkT8mVCtRzrUZwbZMTY4/WMU+Q87PmhWpNfivmAo8jDo= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1777910775; c=relaxed/simple; bh=pcNSsEhWGvXEDe1GEBVFccoEJQYM0zyLyCH9wWIWyPo=; h=DKIM-Signature:Message-ID:Date:MIME-Version:Subject:To:From; b=XoQ2S8hHpO7bCNrhQO8Q/jfipnUE6hP4pukuGimdpL74FWM8t3rn+d8izQ+YGkajQ9JADWZjGKGWqqonlTeLssjZ4TdOs8/231so+z3y2uaWq+11v8UpLw+srLJv7MOvKopuovm8slZjIDPDpMy9iCSBr/64G3TNcjxdhCtG660= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8D5944BA903F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=simark.ca; s=mail; t=1777910773; bh=pcNSsEhWGvXEDe1GEBVFccoEJQYM0zyLyCH9wWIWyPo=; h=Date:Subject:To:References:From:In-Reply-To:From; b=QkoRN2ZX2tKt/3tu6/uqgOOAiWxQXf2YrGSttWOJcGj+RZhQMmrJLFmapiCUJQS0t 4lrUg+3dmGPubupTQxoO8pqejgzQLkS40e0ubEvCmTtO96A/JMkAhReyFT8DSyvJXf WGIjsGRdt/o7eeajBagLzGtjS1QsRbPlBeq5ncK4= Received: by simark.ca (Postfix) id 164EA1E067; Mon, 04 May 2026 12:06:13 -0400 (EDT) Message-ID: <4e284db3-0061-4245-bf0d-7a14a7afe073@simark.ca> Date: Mon, 4 May 2026 12:06:12 -0400 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] gdb: use correct target in notify_thread_exited() To: Markus Metzger , gdb-patches@sourceware.org References: <20260504071636.1571615-1-markus.t.metzger@intel.com> <20260504071636.1571615-6-markus.t.metzger@intel.com> Content-Language: fr From: Simon Marchi In-Reply-To: <20260504071636.1571615-6-markus.t.metzger@intel.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit 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 On 5/4/26 3:16 AM, Markus Metzger wrote: > clean_up_just_stopped_threads_fsms() may call notify_thread_exited() in > the context of a thread from a different target. In my case: > > at .../gdb/thread.c:404 > exit_code=std::optional [no contained value], silent=false) > at .../gdb/thread.c:436 > exit_code=std::optional [no contained value], silent=false) > at .../gdb/thread.c:733 > at .../gdb/thread.c:763 > at .../gdb/infrun.c:4548 > at .../gdb/infrun.c:4786 This is missing the function names, so not very useful. > > Instead of relying on global state, use the exited thread's inferior's > target, which is exactly the target we want. > --- > gdb/thread.c | 6 ++++-- > 1 file changed, 4 insertions(+), 2 deletions(-) > > diff --git a/gdb/thread.c b/gdb/thread.c > index 74124596b28..5c3b60b2aa7 100644 > --- a/gdb/thread.c > +++ b/gdb/thread.c > @@ -203,14 +203,16 @@ notify_thread_exited (thread_info *t, std::optional exit_code, > { > if (!silent && print_thread_events) > { > + struct target_ops *target = t->inf->top_target (); > + > if (exit_code.has_value ()) > gdb_printf (_("[%s (id %s) exited with code %s]\n"), > - target_pid_to_str (t->ptid).c_str (), > + target->pid_to_str (t->ptid).c_str (), > print_thread_id (t), > pulongest (*exit_code)); > else > gdb_printf (_("[%s (id %s) exited]\n"), > - target_pid_to_str (t->ptid).c_str (), > + target->pid_to_str (t->ptid).c_str (), > print_thread_id (t)); This is unfortunately not correct, because target calls (annoyingly IMO) use the target stack of the current inferior to find the target beneath. If you are having to do this change, it means that this function is called for a thread of inferior A, while inferior B is the current one. What will happen is that you'll start with the top target of inferior A, but if that target calls "target_ops::beneath()" to delegate to the target beneath, that will jump to a target of inferior B. If the pid_to_str operation is handled by the top target of inferior A, it will work, but not in the general case. As of today, the only fix for that would be to temporarily switch inferior. I once made a prototype [1] of passing down the target stack explicitly to all target functions. It would be quite invasive, but I don't see any other solution if we want to lift that "target calls care about current inferior" limitation. Simon [1] https://review.lttng.org/c/binutils-gdb/+/5627