#include "observer.h"
#include "annotate.h"
+#include "cli/cli-decode.h"
+
/* Definition of struct thread_info exported to gdbthread.h */
/* Prototypes for exported functions. */
static void restore_current_thread (ptid_t);
static void prune_threads (void);
+static int main_thread_running = 0;
+static int main_thread_executing = 0;
+
void
delete_step_resume_breakpoint (void *arg)
{
if (tp->step_resume_breakpoint)
tp->step_resume_breakpoint->disposition = disp_del_at_next_stop;
+ bpstat_clear (&tp->stop_bpstat);
+
/* FIXME: do I ever need to call the back-end to give it a
chance at this private data before deleting the thread? */
if (tp->private)
struct thread_info *tp, *tpnext;
highest_thread_num = 0;
+ main_thread_running = 0;
+ main_thread_executing = 0;
+
if (!thread_list)
return;
return add_thread_with_info (ptid, NULL);
}
-void
-delete_thread (ptid_t ptid)
+/* Delete thread PTID. If SILENT, don't notify the observer of this
+ exit. */
+static void
+delete_thread_1 (ptid_t ptid, int silent)
{
struct thread_info *tp, *tpprev;
else
thread_list = tp->next;
- observer_notify_thread_exit (tp);
+ if (!silent)
+ observer_notify_thread_exit (tp);
free_thread (tp);
}
+void
+delete_thread (ptid_t ptid)
+{
+ delete_thread_1 (ptid, 0 /* not silent */);
+}
+
+void
+delete_thread_silent (ptid_t ptid)
+{
+ delete_thread_1 (ptid, 1 /* silent */);
+}
+
static struct thread_info *
find_thread_id (int num)
{
int *stepping_through_solib_after_catch,
bpstat *stepping_through_solib_catchpoints,
int *current_line,
- struct symtab **current_symtab)
+ struct symtab **current_symtab,
+ struct continuation **continuations,
+ struct continuation **intermediate_continuations,
+ int *proceed_to_finish,
+ enum step_over_calls_kind *step_over_calls,
+ int *stop_step,
+ int *step_multi,
+ enum target_signal *stop_signal,
+ bpstat *stop_bpstat)
{
struct thread_info *tp;
tp->stepping_through_solib_catchpoints;
*current_line = tp->current_line;
*current_symtab = tp->current_symtab;
+
+ /* In all-stop mode, these are global state, while in non-stop mode,
+ they are per thread. */
+ if (non_stop)
+ {
+ *continuations = tp->continuations;
+ tp->continuations = NULL;
+ *intermediate_continuations = tp->intermediate_continuations;
+ tp->intermediate_continuations = NULL;
+ *proceed_to_finish = tp->proceed_to_finish;
+ *step_over_calls = tp->step_over_calls;
+ *stop_step = tp->stop_step;
+ *step_multi = tp->step_multi;
+ *stop_signal = tp->stop_signal;
+
+ /* Swap instead of copy, so we only have to update one of
+ them. */
+ *stop_bpstat = tp->stop_bpstat;
+ tp->stop_bpstat = 0;
+ }
}
/* Save infrun state for the thread PID. */
int stepping_through_solib_after_catch,
bpstat stepping_through_solib_catchpoints,
int current_line,
- struct symtab *current_symtab)
+ struct symtab *current_symtab,
+ struct continuation *continuations,
+ struct continuation *intermediate_continuations,
+ int proceed_to_finish,
+ enum step_over_calls_kind step_over_calls,
+ int stop_step,
+ int step_multi,
+ enum target_signal stop_signal,
+ bpstat stop_bpstat)
{
struct thread_info *tp;
tp->stepping_through_solib_catchpoints = stepping_through_solib_catchpoints;
tp->current_line = current_line;
tp->current_symtab = current_symtab;
+
+ /* In all-stop mode, these are global state, while in non-stop mode,
+ they are per thread. */
+ if (non_stop)
+ {
+ tp->continuations = continuations;
+ tp->intermediate_continuations = intermediate_continuations;
+ tp->proceed_to_finish = proceed_to_finish;
+ tp->step_over_calls = step_over_calls;
+ tp->stop_step = stop_step;
+ tp->step_multi = step_multi;
+ tp->stop_signal = stop_signal;
+ tp->stop_bpstat = stop_bpstat;
+ }
}
/* Return true if TP is an active thread. */
}
}
-static int main_thread_running = 0;
-
void
set_running (ptid_t ptid, int running)
{
{
struct thread_info *tp;
+ if (!target_has_execution)
+ return 0;
+
if (!thread_list)
return main_thread_running;
return tp->running_;
}
+int
+any_running (void)
+{
+ struct thread_info *tp;
+
+ if (!target_has_execution)
+ return 0;
+
+ if (!thread_list)
+ return main_thread_running;
+
+ for (tp = thread_list; tp; tp = tp->next)
+ if (tp->running_)
+ return 1;
+
+ return 0;
+}
+
+int
+is_executing (ptid_t ptid)
+{
+ struct thread_info *tp;
+
+ if (!target_has_execution)
+ return 0;
+
+ if (!thread_list)
+ return main_thread_executing;
+
+ tp = find_thread_pid (ptid);
+ gdb_assert (tp);
+ return tp->executing_;
+}
+
+void
+set_executing (ptid_t ptid, int executing)
+{
+ struct thread_info *tp;
+
+ if (!thread_list)
+ {
+ /* This target does not add the main thread to the thread list.
+ Use a global flag to indicate that the thread is
+ executing. */
+ main_thread_executing = executing;
+ return;
+ }
+
+ if (PIDGET (ptid) == -1)
+ {
+ for (tp = thread_list; tp; tp = tp->next)
+ tp->executing_ = executing;
+ }
+ else
+ {
+ tp = find_thread_pid (ptid);
+ gdb_assert (tp);
+ tp->executing_ = executing;
+ }
+}
+
/* Prints the list of threads and their details on UIOUT.
This is a version of 'info_thread_command' suitable for
use from MI.
int current_thread = -1;
/* Backup current thread and selected frame. */
- saved_frame_id = get_frame_id (get_selected_frame (NULL));
- old_chain = make_cleanup_restore_current_thread (inferior_ptid, saved_frame_id);
+ if (!is_running (inferior_ptid))
+ saved_frame_id = get_frame_id (get_selected_frame (NULL));
+ else
+ saved_frame_id = null_frame_id;
+ old_chain = make_cleanup_restore_current_thread (inferior_ptid, saved_frame_id);
make_cleanup_ui_out_list_begin_end (uiout, "threads");
prune_threads ();
ui_out_text (uiout, ")");
}
ui_out_text (uiout, " ");
- /* That switch put us at the top of the stack (leaf frame). */
- switch_to_thread (tp->ptid);
- print_stack_frame (get_selected_frame (NULL),
- /* For MI output, print frame level. */
- ui_out_is_mi_like_p (uiout),
- LOCATION);
+ if (tp->running_)
+ ui_out_text (uiout, "(running)\n");
+ else
+ {
+ /* The switch below puts us at the top of the stack (leaf
+ frame). */
+ switch_to_thread (tp->ptid);
+ print_stack_frame (get_selected_frame (NULL),
+ /* For MI output, print frame level. */
+ ui_out_is_mi_like_p (uiout),
+ LOCATION);
+ }
do_cleanups (chain2);
}
ui_out_field_int (uiout, "current-thread-id", current_thread);
}
+ if (is_running (inferior_ptid))
+ return;
+
/* If case we were not able to find the original frame, print the
new selected frame. */
if (frame_find_by_id (saved_frame_id) == NULL)
inferior_ptid = ptid;
reinit_frame_cache ();
registers_changed ();
- stop_pc = read_pc ();
+
+ if (!is_executing (ptid))
+ stop_pc = read_pc ();
+ else
+ stop_pc = ~(CORE_ADDR) 0;
}
static void
{
struct current_thread_cleanup *old = arg;
restore_current_thread (old->inferior_ptid);
- restore_selected_frame (old->selected_frame_id);
+
+ /* A command like 'thread apply all $exec_command&' may change the
+ running state of the originally selected thread, so we have to
+ recheck it here. */
+ if (!is_running (old->inferior_ptid))
+ restore_selected_frame (old->selected_frame_id);
xfree (old);
}
thread_apply_all_command (char *cmd, int from_tty)
{
struct thread_info *tp;
- struct cleanup *old_chain;
- struct cleanup *saved_cmd_cleanup_chain;
+ struct cleanup *old_chain = make_cleanup (null_cleanup, 0);
char *saved_cmd;
struct frame_id saved_frame_id;
ptid_t current_ptid;
error (_("Please specify a command following the thread ID list"));
current_ptid = inferior_ptid;
- saved_frame_id = get_frame_id (get_selected_frame (NULL));
- old_chain = make_cleanup_restore_current_thread (inferior_ptid, saved_frame_id);
+
+ if (!is_running (inferior_ptid))
+ saved_frame_id = get_frame_id (get_selected_frame (NULL));
+ else
+ saved_frame_id = null_frame_id;
+ make_cleanup_restore_current_thread (inferior_ptid, saved_frame_id);
/* It is safe to update the thread list now, before
traversing it for "thread apply all". MVS */
/* Save a copy of the command in case it is clobbered by
execute_command */
saved_cmd = xstrdup (cmd);
- saved_cmd_cleanup_chain = make_cleanup (xfree, (void *) saved_cmd);
+ make_cleanup (xfree, saved_cmd);
for (tp = thread_list; tp; tp = tp->next)
if (thread_alive (tp))
{
- switch_to_thread (tp->ptid);
+ if (non_stop)
+ context_switch_to (tp->ptid);
+ else
+ switch_to_thread (tp->ptid);
+
printf_filtered (_("\nThread %d (%s):\n"),
tp->num, target_tid_to_str (inferior_ptid));
execute_command (cmd, from_tty);
if (!ptid_equal (current_ptid, inferior_ptid))
thread_has_changed = 1;
- do_cleanups (saved_cmd_cleanup_chain);
do_cleanups (old_chain);
/* Print stack frame only if we changed thread. */
- if (thread_has_changed)
+ if (thread_has_changed && !is_running (inferior_ptid))
print_stack_frame (get_current_frame (), 1, SRC_LINE);
-
}
static void
error (_("Please specify a command following the thread ID list"));
current_ptid = inferior_ptid;
- saved_frame_id = get_frame_id (get_selected_frame (NULL));
+
+ if (!is_running (inferior_ptid))
+ saved_frame_id = get_frame_id (get_selected_frame (NULL));
+ else
+ saved_frame_id = null_frame_id;
old_chain = make_cleanup_restore_current_thread (inferior_ptid, saved_frame_id);
/* Save a copy of the command in case it is clobbered by
warning (_("Thread %d has terminated."), start);
else
{
- switch_to_thread (tp->ptid);
+ if (non_stop)
+ context_switch_to (tp->ptid);
+ else
+ switch_to_thread (tp->ptid);
printf_filtered (_("\nThread %d (%s):\n"), tp->num,
target_tid_to_str (inferior_ptid));
execute_command (cmd, from_tty);
if (!thread_alive (tp))
error (_("Thread ID %d has terminated."), num);
- switch_to_thread (tp->ptid);
+ if (non_stop)
+ context_switch_to (tp->ptid);
+ else
+ switch_to_thread (tp->ptid);
ui_out_text (uiout, "[Switching to thread ");
ui_out_field_int (uiout, "new-thread-id", pid_to_thread_id (inferior_ptid));
ui_out_text (uiout, target_tid_to_str (inferior_ptid));
ui_out_text (uiout, ")]");
- print_stack_frame (get_selected_frame (NULL), 1, SRC_AND_LOC);
+ if (!tp->running_)
+ print_stack_frame (get_selected_frame (NULL), 1, SRC_AND_LOC);
+ else
+ ui_out_text (uiout, "(running)\n");
+
return GDB_RC_OK;
}
_initialize_thread (void)
{
static struct cmd_list_element *thread_apply_list = NULL;
+ struct cmd_list_element *c;
- add_info ("threads", info_threads_command,
- _("IDs of currently known threads."));
+ c = add_info ("threads", info_threads_command,
+ _("IDs of currently known threads."));
+ set_cmd_async_ok (c);
- add_prefix_cmd ("thread", class_run, thread_command, _("\
+ c = add_prefix_cmd ("thread", class_run, thread_command, _("\
Use this command to switch between threads.\n\
The new thread ID must be currently known."),
- &thread_cmd_list, "thread ", 1, &cmdlist);
+ &thread_cmd_list, "thread ", 1, &cmdlist);
+ set_cmd_async_ok (c);
add_prefix_cmd ("apply", class_run, thread_apply_command,
_("Apply a command to a list of threads."),