Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Markus Metzger <markus.t.metzger@intel.com>
To: gdb-patches@sourceware.org
Subject: [RFC PATCH 5/8] gdb, interp: repeat stop event when switching threads
Date: Thu,  1 Oct 2026 12:28:44 +0200	[thread overview]
Message-ID: <20261001102847.576880-6-markus.t.metzger@intel.com> (raw)
In-Reply-To: <20261001102847.576880-1-markus.t.metzger@intel.com>

When switching threads back and forth and inspecting the state of various
threads, one needs to note down the original stop reason or search for it
in the console log when switching back to the eventing thread.

GDB knows the stop reason, so why not print it again when switching back
to the thread?

We currently only print breakpoint stops.  When the stop reason is
printed, the location is printed as part of the stop reason without the
frame level, whereas otherwise, the frame level would be printed.

The MI interpreter printed

    thread-selected,id=<global thread number>

when either USER_SELECTED_THREAD or USER_SELECTED_FRAME is specified.  So
it would print this thread information when only USER_SELECTED_FRAME is
specified, which seems wrong to me.  This behavior is covered by
gdb.mi/user-selected-context-sync.exp, so I preserve it.

It also printed the stack frame without checking USER_SELECTED_FRAME if
the thread isn't running, which also seems wrong.
---
 gdb/cli/cli-interp.c | 29 ++++++++++++++++++++++++++---
 gdb/mi/mi-interp.c   | 42 ++++++++++++++++++++++++++++++++----------
 2 files changed, 58 insertions(+), 13 deletions(-)

diff --git a/gdb/cli/cli-interp.c b/gdb/cli/cli-interp.c
index 55892d2ce28..20b2ee906c3 100644
--- a/gdb/cli/cli-interp.c
+++ b/gdb/cli/cli-interp.c
@@ -166,9 +166,32 @@ cli_interp_base::on_user_selected_context_changed (user_selected_what selection)
   if (selection & USER_SELECTED_INFERIOR)
     print_selected_inferior (this->interp_ui_out ());
 
-  if (tp != nullptr
-      && ((selection & (USER_SELECTED_THREAD | USER_SELECTED_FRAME))))
-    print_selected_thread_frame (this->interp_ui_out (), selection);
+  if (tp == nullptr)
+    return;
+
+  bool print_stop = false;
+  if (selection & USER_SELECTED_THREAD)
+    {
+      print_selected_thread_frame (this->interp_ui_out (),
+				   USER_SELECTED_THREAD);
+
+      if (selection & USER_SELECTED_FRAME)
+	{
+	  /* Repeat any previous breakpoint stop notification.  */
+	  print_stop = (bpstat_what (tp->control.stop_bpstat).main_action
+			== BPSTAT_WHAT_STOP_NOISY);
+	  if (print_stop)
+	    print_stop_event (this->interp_ui_out ());
+	}
+    }
+
+  if (selection & USER_SELECTED_FRAME)
+    {
+      /* Printing the stop notification already prints the frame.  */
+      if (!print_stop)
+	print_selected_thread_frame (this->interp_ui_out (),
+				     USER_SELECTED_FRAME);
+    }
 }
 
 /* pre_command_loop implementation.  */
diff --git a/gdb/mi/mi-interp.c b/gdb/mi/mi-interp.c
index 207b1fc97ff..ccf66f7b58a 100644
--- a/gdb/mi/mi-interp.c
+++ b/gdb/mi/mi-interp.c
@@ -850,19 +850,41 @@ mi_interp::on_user_selected_context_changed (user_selected_what selection)
   if (selection & USER_SELECTED_INFERIOR)
     print_selected_inferior (this->cli_uiout);
 
-  if (tp != NULL
-      && (selection & (USER_SELECTED_THREAD | USER_SELECTED_FRAME)))
+  if (tp != NULL)
     {
-      print_selected_thread_frame (this->cli_uiout, selection);
-
-      gdb_printf (this->event_channel, "thread-selected,id=\"%d\"",
-		  tp->global_num);
+      if (selection & USER_SELECTED_THREAD)
+	{
+	  print_selected_thread_frame (this->cli_uiout,
+				       USER_SELECTED_THREAD);
+
+	  if (selection & USER_SELECTED_FRAME)
+	    {
+	      /* Repeat any previous breakpoint stop notification.  */
+	      if (bpstat_what (tp->control.stop_bpstat).main_action
+		  == BPSTAT_WHAT_STOP_NOISY)
+		print_stop_event (this->cli_uiout);
+	      else
+		print_selected_thread_frame (this->cli_uiout,
+					     USER_SELECTED_FRAME);
+	    }
+
+	  gdb_printf (this->event_channel, "thread-selected,id=\"%d\"",
+		      tp->global_num);
+	}
 
-      if (tp->state () != THREAD_RUNNING)
+      if (selection & USER_SELECTED_FRAME)
 	{
-	  if (has_stack_frames ())
-	    print_stack_frame_to_uiout (mi_uiout, get_selected_frame (),
-					1, SRC_AND_LOC, 1);
+	  if (!(selection & USER_SELECTED_THREAD))
+	    {
+	      print_selected_thread_frame (this->cli_uiout,
+					   USER_SELECTED_FRAME);
+
+	      gdb_printf (this->event_channel, "thread-selected,id=\"%d\"",
+			  tp->global_num);
+	    }
+
+	  print_selected_thread_frame (mi_uiout,
+				       USER_SELECTED_FRAME);
 	}
     }
 
-- 
2.53.0

________________________________________
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.


  parent reply	other threads:[~2026-10-01 10:31 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-01 10:28 [RFC PATCH 0/8] breakpoint handling Markus Metzger
2026-10-01 10:28 ` [RFC PATCH 1/8] gdb, infrun: do not discard a step-completed pending waitstatus Markus Metzger
2026-10-01 10:28 ` [RFC PATCH 2/8] gdb, infrun: track last waitstatus per thread Markus Metzger
2026-10-01 10:28 ` [RFC PATCH 3/8] gdb, infrun: simplify print_stop_location() Markus Metzger
2026-10-01 10:28 ` [RFC PATCH 4/8] gdb, thread: simplify print_selected_thread_frame() Markus Metzger
2026-10-01 10:28 ` Markus Metzger [this message]
2026-10-01 10:28 ` [RFC PATCH 6/8] gdb, infrun: handle stop event when selecting a thread Markus Metzger
2026-10-01 10:28 ` [RFC PATCH 7/8] gdb, infrun: inline init_thread_stepping_state() Markus Metzger
2026-10-01 10:28 ` [RFC PATCH 8/8] gdb, infrun: only step over breakpoints that were hit Markus Metzger

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261001102847.576880-6-markus.t.metzger@intel.com \
    --to=markus.t.metzger@intel.com \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox