Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* [PATCH v2] gdb: remember previously selected thread per inferior
@ 2026-03-25 12:23 Klaus Gerlicher
  2026-03-25 12:23 ` [PATCH v2 1/1] " Klaus Gerlicher
  2026-04-28  9:26 ` [PATCH v2] " Gerlicher, Klaus
  0 siblings, 2 replies; 4+ messages in thread
From: Klaus Gerlicher @ 2026-03-25 12:23 UTC (permalink / raw)
  To: gdb-patches

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


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

end of thread, other threads:[~2026-04-28  9:27 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-03-25 12:23 [PATCH v2] gdb: remember previously selected thread per inferior Klaus Gerlicher
2026-03-25 12:23 ` [PATCH v2 1/1] " Klaus Gerlicher
2026-03-25 14:34   ` Eli Zaretskii
2026-04-28  9:26 ` [PATCH v2] " Gerlicher, Klaus

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