From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id 9pDhMwIPoGqFCjcAWB0awg (envelope-from ) for ; Tue, 08 Sep 2026 09:34:58 -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=eaNnVMEi; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id C4EA01E091; Tue, 08 Sep 2026 09:34:58 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-6.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 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 D736D1E091 for ; Tue, 08 Sep 2026 09:34:57 -0400 (EDT) Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 705874BA79A9 for ; Tue, 8 Sep 2026 13:34:57 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 705874BA79A9 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=eaNnVMEi Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.10]) by sourceware.org (Postfix) with ESMTPS id 10E9F4BA2E23 for ; Tue, 8 Sep 2026 13:34:32 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 10E9F4BA2E23 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 10E9F4BA2E23 Authentication-Results: sourceware.org; arc=none smtp.remote-ip=198.175.65.10 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1788874473; cv=none; b=uQYvTa/1VO/XHC+Ewa6o2Fx6C1MNknLT1KjhYUPPMHhPLKtm1TdODCPI1ocQJF2ZF0LB4u0fpDSuu52WuE8ySyKZxulZC7aF8ybnTSbz4xeWia8jl8AbTkywjK3Fz27Ls0EZXod1pVtdj9150MTT0bSZZTu0jwp9J+h+ym8DyXg= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1788874473; c=relaxed/simple; bh=h8ivW+5JmyIOc+2ej0IepD0YDLKKBvhPLwmY5ySrjfk=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=noAGvft150bs1bTF0hWERtuPKfxrBFe/q+upg6pR6xBPXBPD9UpuyeNrOEkXgybZDVexwmY2eg2ZKX48HC0gaR/3FUO1+Il0NRez4DkbMSNNEDFgGods8cFMhPgZwW2Ja/UEqXodAXQ7FIaaPOzMIA5hZdRWrtQb/uG8gp01aT8= ARC-Authentication-Results: i=1; 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=eaNnVMEi DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 10E9F4BA2E23 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1788874473; x=1820410473; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=h8ivW+5JmyIOc+2ej0IepD0YDLKKBvhPLwmY5ySrjfk=; b=eaNnVMEitibXZgl227Jx437C3zM54FwYwyr4OG5BbuQQRAU73jjJqByR pTfGW13im8DmSWAH9n7KfymZSdf7DDFIGJFKa0CxRAMYpzscERv1lRcMM WIjOIf5rYeCLhKSM8gjsiIBQ3Xa5B36DUVzXvGJQUWnqV6vLSM1PoWhCU INh6tPh0aglW+ZcvCQzAOXORvvUoNqQmT74y01FzySXUSsXAh1I6PadIk Jgk6I+oFtfWW0rf27+73TAXQMsfLfJF9blceqwOxN67/8+vzAweQnpOt+ 990H56hHk6hg6evPjkIQUNM2Q4P9kOMlDYrluJyZyyXDQGFcR6IwwAEt4 g==; X-CSE-ConnectionGUID: lSNdQ5McRMmoVaug7DuuRQ== X-CSE-MsgGUID: ELrCp+dKTPyV++8GQfzuZg== X-IronPort-AV: E=McAfee;i="6800,10657,11899"; a="106647278" X-IronPort-AV: E=Sophos;i="6.25,269,1779174000"; d="scan'208";a="106647278" Received: from fmviesa001.fm.intel.com ([10.60.135.141]) by orvoesa102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Sep 2026 06:34:32 -0700 X-CSE-ConnectionGUID: J6dkoeUSRRy1mehyvn4/2g== X-CSE-MsgGUID: fACVxr2LRLeYU3G8zvbZ+A== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.25,269,1779174000"; d="scan'208";a="295923664" Received: from dut1583dg2frd.igk.intel.com (HELO localhost) ([10.211.179.243]) by smtpauth.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Sep 2026 06:34:30 -0700 From: Klaus Gerlicher To: gdb-patches@sourceware.org Cc: aburgess@redhat.com, pedro@palves.net Subject: [PATCH v3 0/1] gdb: remember previously selected thread per inferior Date: Tue, 8 Sep 2026 13:34:25 +0000 Message-Id: <20260908133426.444197-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 From: "Klaus Gerlicher" Hi, This is V3 of the patch to remember the selected thread when switching between inferiors. Thanks for the feedback, @Andrew. Addressing it here: Changes since V2: * Changed default from ON to OFF (backward compatible) * Added code comments explaining dual mechanism (observer + direct call) * Updated documentation to reflect "disabled by default" 1. Default is now OFF: Following Andrew's recommendation and Pedro's earlier concerns about changing existing behavior, I've changed the default to OFF. This maintains backward compatibility - GDB's behavior is unchanged unless user explicitly enables this feature. 2. Observer and direct call: Andrew 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. I've added comments in both locations explaining this. Example that breaks without infrun.c saving: (gdb) set schedule-multiple on (gdb) set remember-threads-per-inferior 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 # Would switch to thread 2.1 instead of 2.2 The test_implicit scenario in inferior-switch.exp explicitly tests this and fails without the infrun.c call. 3. Backward Compatibility: With default OFF, existing GDB users see no behavior change. Users who want the restore behavior can enable it with: (gdb) set remember-threads-per-inferior on I think this is close to what Andrew had attempted a few years back. Thanks for pointing out the old series. Pedro back then had doubts about this but I assume having it switched OFF per default would help potentially. Tested on x86_64. Thanks, Klaus Klaus Gerlicher (1): gdb: remember previously selected thread per inferior gdb/NEWS | 8 + gdb/doc/gdb.texinfo | 20 ++ gdb/gdbthread.h | 4 + gdb/inferior.c | 65 ++++++- gdb/inferior.h | 14 ++ gdb/infrun.c | 12 +- 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, 356 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) 99143-0 www.intel.de Managing Directors: Candice Moore, Jeffrey Schneiderman, Ramachandran Sitaraman Chairperson of the Supervisory Board: Sonja Pierer Registered Seat: Munich Commercial Register B: Amtsgericht Munich HRB 186928 This e-mail and any attachments may contain confidential material for the sole use of the intended recipient(s). Any review or distribution by others is strictly prohibited. If you are not the intended recipient, please contact the sender and delete all copies.