aboutsummaryrefslogtreecommitdiff
path: root/gdb/thread.c
diff options
context:
space:
mode:
Diffstat (limited to 'gdb/thread.c')
-rw-r--r--gdb/thread.c86
1 files changed, 64 insertions, 22 deletions
diff --git a/gdb/thread.c b/gdb/thread.c
index a66a2b5..13449a8 100644
--- a/gdb/thread.c
+++ b/gdb/thread.c
@@ -1923,7 +1923,7 @@ thread_apply_command (char *tidlist, int from_tty)
void
thread_command (char *tidstr, int from_tty)
{
- if (!tidstr)
+ if (tidstr == NULL)
{
if (ptid_equal (inferior_ptid, null_ptid))
error (_("No thread selected"));
@@ -1943,10 +1943,31 @@ thread_command (char *tidstr, int from_tty)
}
else
error (_("No stack."));
- return;
}
+ else
+ {
+ ptid_t previous_ptid = inferior_ptid;
+ enum gdb_rc result;
+
+ result = gdb_thread_select (current_uiout, tidstr, NULL);
+
+ /* If thread switch did not succeed don't notify or print. */
+ if (result == GDB_RC_FAIL)
+ return;
- gdb_thread_select (current_uiout, tidstr, NULL);
+ /* Print if the thread has not changed, otherwise an event will be sent. */
+ if (ptid_equal (inferior_ptid, previous_ptid))
+ {
+ print_selected_thread_frame (current_uiout,
+ USER_SELECTED_THREAD
+ | USER_SELECTED_FRAME);
+ }
+ else
+ {
+ observer_notify_user_selected_context_changed (USER_SELECTED_THREAD
+ | USER_SELECTED_FRAME);
+ }
+ }
}
/* Implementation of `thread name'. */
@@ -2058,32 +2079,53 @@ do_captured_thread_select (struct ui_out *uiout, void *tidstr_v)
annotate_thread_changed ();
- if (ui_out_is_mi_like_p (uiout))
- ui_out_field_int (uiout, "new-thread-id", inferior_thread ()->global_num);
- else
+ /* Since the current thread may have changed, see if there is any
+ exited thread we can now delete. */
+ prune_threads ();
+
+ return GDB_RC_OK;
+}
+
+/* Print thread and frame switch command response. */
+
+void
+print_selected_thread_frame (struct ui_out *uiout,
+ user_selected_what selection)
+{
+ struct thread_info *tp = inferior_thread ();
+ struct inferior *inf = current_inferior ();
+
+ if (selection & USER_SELECTED_THREAD)
{
- ui_out_text (uiout, "[Switching to thread ");
- ui_out_field_string (uiout, "new-thread-id", print_thread_id (tp));
- ui_out_text (uiout, " (");
- ui_out_text (uiout, target_pid_to_str (inferior_ptid));
- ui_out_text (uiout, ")]");
+ if (ui_out_is_mi_like_p (uiout))
+ {
+ ui_out_field_int (uiout, "new-thread-id",
+ inferior_thread ()->global_num);
+ }
+ else
+ {
+ ui_out_text (uiout, "[Switching to thread ");
+ ui_out_field_string (uiout, "new-thread-id", print_thread_id (tp));
+ ui_out_text (uiout, " (");
+ ui_out_text (uiout, target_pid_to_str (inferior_ptid));
+ ui_out_text (uiout, ")]");
+ }
}
- /* Note that we can't reach this with an exited thread, due to the
- thread_alive check above. */
if (tp->state == THREAD_RUNNING)
- ui_out_text (uiout, "(running)\n");
- else
{
- ui_out_text (uiout, "\n");
- print_stack_frame (get_selected_frame (NULL), 1, SRC_AND_LOC, 1);
+ if (selection & USER_SELECTED_THREAD)
+ ui_out_text (uiout, "(running)\n");
}
+ else if (selection & USER_SELECTED_FRAME)
+ {
+ if (selection & USER_SELECTED_THREAD)
+ ui_out_text (uiout, "\n");
- /* Since the current thread may have changed, see if there is any
- exited thread we can now delete. */
- prune_threads ();
-
- return GDB_RC_OK;
+ if (has_stack_frames ())
+ print_stack_frame_to_uiout (uiout, get_selected_frame (NULL),
+ 1, SRC_AND_LOC, 1);
+ }
}
enum gdb_rc