Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* [PATCH v3 0/1] gdb: remember previously selected thread per inferior
@ 2026-09-08 13:34 Klaus Gerlicher
  2026-09-08 13:34 ` [PATCH v3 1/1] " Klaus Gerlicher
  0 siblings, 1 reply; 3+ messages in thread
From: Klaus Gerlicher @ 2026-09-08 13:34 UTC (permalink / raw)
  To: gdb-patches; +Cc: aburgess, pedro

From: "Klaus Gerlicher" <klaus.gerlicher@intel.com>

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.


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-09-08 20:01 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-09-08 13:34 [PATCH v3 0/1] gdb: remember previously selected thread per inferior Klaus Gerlicher
2026-09-08 13:34 ` [PATCH v3 1/1] " Klaus Gerlicher
2026-09-08 20:01   ` Kevin Buettner

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox