[RFC,5/8] gdb, interp: repeat stop event when switching threads
Checks
Commit Message
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(-)
@@ -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. */
@@ -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);
}
}