From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id qdMjDObTw2k/2DgAWB0awg (envelope-from ) for ; Wed, 25 Mar 2026 08:24:06 -0400 Authentication-Results: simark.ca; dkim=pass (2048-bit key; unprotected) header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=EhKQXUSy; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 04E6B1E04F; Wed, 25 Mar 2026 08:24:06 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-3.4 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, DKIMWL_WL_HIGH,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 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 8F1A61E04F for ; Wed, 25 Mar 2026 08:24:04 -0400 (EDT) Received: from vm01.sourceware.org (localhost [127.0.0.1]) by sourceware.org (Postfix) with ESMTP id D0D034BAE7D0 for ; Wed, 25 Mar 2026 12:24:03 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D0D034BAE7D0 Authentication-Results: sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=EhKQXUSy Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.8]) by sourceware.org (Postfix) with ESMTPS id 95B384BA2E18 for ; Wed, 25 Mar 2026 12:23:34 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 95B384BA2E18 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=intel.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 95B384BA2E18 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=192.198.163.8 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1774441415; cv=none; b=tqj/NxXdB8k94cVtSkms8KhkRdPq1h3reju7IJISR1LG8WIstRMu/0Sr5UjkhuVACumciBXnLLAopEPbTG12Y5ZjTlMQE4Kv+CyP3IMAUhVczG9cZaX4JAO8+Chkftg3RdZYis8ulLi7Xfc5Jwu77Z5sE9YDeM9dsrDo9p+MzQM= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1774441415; c=relaxed/simple; bh=ZPM3IMEGBkK68E4jI+uNwjNcSOnDT9tLUNNVfmBBgZI=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=gLhkiKvrz9RlvLsHxk8Zar6Bp4Sdhzi6/LG25UcBDbbebl5SfCBeo6hBUoAV5KxYaGCfxWykIuLQ0busOQRtGCnG78HEjH+D6wtzSEsjeOrMl2CuWqcXDEw9hEfgcWQ7pyI2+4QVZES75BYClVUrNjycDX2icKeI7Rn4bK7FkIg= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 95B384BA2E18 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1774441415; x=1805977415; h=from:to:subject:date:message-id:mime-version: content-transfer-encoding; bh=ZPM3IMEGBkK68E4jI+uNwjNcSOnDT9tLUNNVfmBBgZI=; b=EhKQXUSyuygjqUS20seJ16KZdOJScNp2x+Y+x0ZH+2tC3OPKcxVfWgdy vAX0DtIZAT4qV+tkkoCuOwwxuzGVv4QSlhHY3jqfspw0lz8LdVyfc+AGB 4eGSLf+GvSKF3+0+Qn0e+HbnA8/Qb+CzWFRpQb1CNiQJkA1tQzDivIAPO Y69AaGh95GzxL7xTyex114z+uIrZz0LT6jmUlZu7eryoN8LbFzjL+Zi4f sAgG4iQmbqwAomBN5yByXXTWrxZeoWdcIYueXXr+VrgfyMhvAju/yAyhS jwjPPTsBGez1CSgQuqyzSAS5gbt487v1oojL3jrQEpgr3ntX/wZUG3v1E w==; X-CSE-ConnectionGUID: eHOpYMcwS3CuL/JCipLnjw== X-CSE-MsgGUID: hycIJ2gnQuiSIWwHSd+Gig== X-IronPort-AV: E=McAfee;i="6800,10657,11739"; a="93052588" X-IronPort-AV: E=Sophos;i="6.23,140,1770624000"; d="scan'208";a="93052588" Received: from orviesa008.jf.intel.com ([10.64.159.148]) by fmvoesa102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Mar 2026 05:23:33 -0700 X-CSE-ConnectionGUID: gu7WbW5tR3qeZ92imUMnuw== X-CSE-MsgGUID: uNZdrxIPRO2ZNEa5SZXCsQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.23,140,1770624000"; d="scan'208";a="224676907" Received: from dut1465dg2mrb.igk.intel.com (HELO localhost) ([10.211.180.13]) by orviesa008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Mar 2026 05:23:33 -0700 From: Klaus Gerlicher To: gdb-patches@sourceware.org Subject: [PATCH v2] gdb: remember previously selected thread per inferior Date: Wed, 25 Mar 2026 12:23:20 +0000 Message-Id: <20260325122321.315910-1-klaus.gerlicher@intel.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" 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 Hi, This is V2 of my patch to add thread memory when switching inferiors. Thanks for the feedback, @Andrew, @Pedro, addressing it here: Changes since V1: * made the feature switchable with 'set remember-threads-per-inferior [on|off]' * added full documentation (gdb.texinfo) * Added NEWS entry * Added test for disabled behavior (test_disabled_behavior) * default is ON (enabled by default) 1. Switchable Feature: I've made this controllable. The default is ON because I think most users would want this behavior but users who prefer the old "first available thread" behavior can easily disable it. Pedro's concern in the V1 thread was that not everyone might find this natural, so now everyone can choose. 2. Documentation: Added full texinfo documentation with examples showing both enabled and disabled modes. Also added NEWS entry as requested. 3. Observer arch: You asked why we need the manual call in infrun.c and can't rely solely on the observer. The user_selected_context_changed observer only fires for explicit user commands (thread, inferior, frame), not for event switches. Example that breaks w/o infrun.c saving: (gdb) set schedule-multiple on (gdb) thread 1.1 (gdb) continue # Breakpoint hits in inferior 2, thread 2.2 (automatic switch) # Observer does NOT fire (not a user command!) # Without infrun.c save: thread 2.2 never gets recorded (gdb) inferior 1 (gdb) inferior 2 # BUG: Would switch to thread 2.1 instead of 2.2 My test_implicit scenario explicitly tests this and fails without the infrun.c call. Alternative would be creating a new observer that fires for ALL context switches (user + automatic)? I've kept the default as ON rather than OFF. If you prefer defaulting to OFF, I can change it. Tested on x86_64. Thanks, Klaus Klaus Gerlicher (1): gdb: remember previously selected thread per inferior gdb/NEWS | 7 + gdb/doc/gdb.texinfo | 19 ++ gdb/gdbthread.h | 4 + gdb/inferior.c | 58 +++++- gdb/inferior.h | 14 ++ gdb/infrun.c | 6 +- gdb/testsuite/gdb.base/inferior-switch.c | 42 +++++ gdb/testsuite/gdb.base/inferior-switch.exp | 172 ++++++++++++++++++ .../gdb.mi/user-selected-context-sync.exp | 14 ++ gdb/thread.c | 8 + 10 files changed, 341 insertions(+), 3 deletions(-) create mode 100644 gdb/testsuite/gdb.base/inferior-switch.c create mode 100644 gdb/testsuite/gdb.base/inferior-switch.exp -- 2.34.1 Intel Deutschland GmbH Registered Address: Dornacher Strasse 1, 85622 Feldkirchen, Germany Tel: +49 89 991 430, www.intel.de Managing Directors: Harry Demas, Jeffrey Schneiderman, Yin Chong Sorrell Chairperson of the Supervisory Board: Nicole Lau Registered Seat: Munich Commercial Register: Amtsgericht Muenchen HRB 186928