/* Multi-process/thread control for GDB, the GNU debugger.
- Copyright 1986, 1987, 1988, 1993, 1994, 1995, 1996, 1997, 1998,
- 1999, 2000, 2001, 2002, 2003, 2004 Free Software Foundation, Inc.
+ Copyright (C) 1986, 1987, 1988, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
+ 2000, 2001, 2002, 2003, 2004, 2007 Free Software Foundation, Inc.
Contributed by Lynx Real-Time Systems, Inc. Los Gatos, CA.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place - Suite 330,
- Boston, MA 02111-1307, USA. */
+ Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA. */
#include "defs.h"
#include "symtab.h"
#include "value.h"
#include "target.h"
#include "gdbthread.h"
+#include "exceptions.h"
#include "command.h"
#include "gdbcmd.h"
#include "regcache.h"
static void restore_current_thread (ptid_t);
static void switch_to_thread (ptid_t ptid);
static void prune_threads (void);
+static struct cleanup *make_cleanup_restore_current_thread (ptid_t,
+ struct frame_id);
void
delete_step_resume_breakpoint (void *arg)
/* Official gdblib interface function to get a list of thread ids and
the total number. */
enum gdb_rc
-gdb_list_thread_ids (struct ui_out *uiout)
+gdb_list_thread_ids (struct ui_out *uiout, char **error_message)
{
- return catch_exceptions (uiout, do_captured_list_thread_ids, NULL,
- NULL, RETURN_MASK_ALL);
+ return catch_exceptions_with_msg (uiout, do_captured_list_thread_ids, NULL,
+ error_message, RETURN_MASK_ALL);
}
/* Load infrun state for the thread PID. */
int *another_trap,
int *stepping_through_solib_after_catch,
bpstat *stepping_through_solib_catchpoints,
- int *stepping_through_sigtramp,
int *current_line,
struct symtab **current_symtab)
{
tp->stepping_through_solib_after_catch;
*stepping_through_solib_catchpoints =
tp->stepping_through_solib_catchpoints;
- *stepping_through_sigtramp = tp->stepping_through_sigtramp;
*current_line = tp->current_line;
*current_symtab = tp->current_symtab;
}
int another_trap,
int stepping_through_solib_after_catch,
bpstat stepping_through_solib_catchpoints,
- int stepping_through_sigtramp,
int current_line,
struct symtab *current_symtab)
{
tp->another_trap = another_trap;
tp->stepping_through_solib_after_catch = stepping_through_solib_after_catch;
tp->stepping_through_solib_catchpoints = stepping_through_solib_catchpoints;
- tp->stepping_through_sigtramp = stepping_through_sigtramp;
tp->current_line = current_line;
tp->current_symtab = current_symtab;
}
struct thread_info *tp;
ptid_t current_ptid;
struct frame_info *cur_frame;
- struct frame_id saved_frame_id = get_frame_id (get_selected_frame ());
+ struct cleanup *old_chain;
+ struct frame_id saved_frame_id;
char *extra_info;
+ /* 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);
+
prune_threads ();
target_find_new_threads ();
current_ptid = inferior_ptid;
if (extra_info)
printf_filtered (" (%s)", extra_info);
puts_filtered (" ");
-
+ /* That switch put us at the top of the stack (leaf frame). */
switch_to_thread (tp->ptid);
- print_stack_frame (get_selected_frame (), 0, LOCATION);
+ print_stack_frame (get_selected_frame (NULL), 0, LOCATION);
}
- switch_to_thread (current_ptid);
+ /* Restores the current thread and the frame selected before
+ the "info threads" command. */
+ do_cleanups (old_chain);
- /* Restores the frame set by the user before the "info threads"
- command. We have finished the info-threads display by switching
- back to the current thread. That switch has put us at the top of
- the stack (leaf frame). */
- cur_frame = frame_find_by_id (saved_frame_id);
- if (cur_frame == NULL)
- {
- /* Ooops, can't restore, tell user where we are. */
- warning ("Couldn't restore frame in current thread, at frame 0");
- print_stack_frame (get_selected_frame (), 0, LOCATION);
- }
- else
+ /* 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)
{
- select_frame (cur_frame);
- /* re-show current frame. */
- show_stack_frame (cur_frame);
+ warning (_("Couldn't restore frame in current thread, at frame 0"));
+ print_stack_frame (get_selected_frame (NULL), 0, LOCATION);
}
}
if (!ptid_equal (ptid, inferior_ptid))
{
switch_to_thread (ptid);
- print_stack_frame (get_current_frame (), 1, SRC_LINE);
+ }
+}
+
+static void
+restore_selected_frame (struct frame_id a_frame_id)
+{
+ struct frame_info *selected_frame_info = NULL;
+
+ if (frame_id_eq (a_frame_id, null_frame_id))
+ return;
+
+ if ((selected_frame_info = frame_find_by_id (a_frame_id)) != NULL)
+ {
+ select_frame (selected_frame_info);
}
}
struct current_thread_cleanup
{
ptid_t inferior_ptid;
+ struct frame_id selected_frame_id;
};
static void
{
struct current_thread_cleanup *old = arg;
restore_current_thread (old->inferior_ptid);
+ restore_selected_frame (old->selected_frame_id);
xfree (old);
}
static struct cleanup *
-make_cleanup_restore_current_thread (ptid_t inferior_ptid)
+make_cleanup_restore_current_thread (ptid_t inferior_ptid,
+ struct frame_id a_frame_id)
{
struct current_thread_cleanup *old
= xmalloc (sizeof (struct current_thread_cleanup));
old->inferior_ptid = inferior_ptid;
+ old->selected_frame_id = a_frame_id;
return make_cleanup (do_restore_current_thread_cleanup, old);
}
struct cleanup *old_chain;
struct cleanup *saved_cmd_cleanup_chain;
char *saved_cmd;
+ struct frame_id saved_frame_id;
+ ptid_t current_ptid;
+ int thread_has_changed = 0;
if (cmd == NULL || *cmd == '\000')
- error ("Please specify a command following the thread ID list");
-
- old_chain = make_cleanup_restore_current_thread (inferior_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);
/* It is safe to update the thread list now, before
traversing it for "thread apply all". MVS */
if (thread_alive (tp))
{
switch_to_thread (tp->ptid);
- printf_filtered ("\nThread %d (%s):\n",
+ printf_filtered (_("\nThread %d (%s):\n"),
tp->num, target_tid_to_str (inferior_ptid));
execute_command (cmd, from_tty);
strcpy (cmd, saved_cmd); /* Restore exact command used previously */
}
+ 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)
+ print_stack_frame (get_current_frame (), 1, SRC_LINE);
+
}
static void
struct cleanup *old_chain;
struct cleanup *saved_cmd_cleanup_chain;
char *saved_cmd;
+ struct frame_id saved_frame_id;
+ ptid_t current_ptid;
+ int thread_has_changed = 0;
if (tidlist == NULL || *tidlist == '\000')
- error ("Please specify a thread ID list");
+ error (_("Please specify a thread ID list"));
for (cmd = tidlist; *cmd != '\000' && !isalpha (*cmd); cmd++);
if (*cmd == '\000')
- error ("Please specify a command following the thread ID list");
+ error (_("Please specify a command following the thread ID list"));
- old_chain = make_cleanup_restore_current_thread (inferior_ptid);
+ 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);
/* Save a copy of the command in case it is clobbered by
execute_command */
start = strtol (tidlist, &p, 10);
if (p == tidlist)
- error ("Error parsing %s", tidlist);
+ error (_("Error parsing %s"), tidlist);
tidlist = p;
while (*tidlist == ' ' || *tidlist == '\t')
tidlist++; /* Skip the - */
end = strtol (tidlist, &p, 10);
if (p == tidlist)
- error ("Error parsing %s", tidlist);
+ error (_("Error parsing %s"), tidlist);
tidlist = p;
while (*tidlist == ' ' || *tidlist == '\t')
tp = find_thread_id (start);
if (!tp)
- warning ("Unknown thread %d.", start);
+ warning (_("Unknown thread %d."), start);
else if (!thread_alive (tp))
- warning ("Thread %d has terminated.", start);
+ warning (_("Thread %d has terminated."), start);
else
{
switch_to_thread (tp->ptid);
- printf_filtered ("\nThread %d (%s):\n", tp->num,
+ printf_filtered (_("\nThread %d (%s):\n"), tp->num,
target_tid_to_str (inferior_ptid));
execute_command (cmd, from_tty);
strcpy (cmd, saved_cmd); /* Restore exact command used previously */
}
}
+ 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)
+ print_stack_frame (get_current_frame (), 1, SRC_LINE);
}
/* Switch to the specified thread. Will dispatch off to thread_apply_command
{
/* Don't generate an error, just say which thread is current. */
if (target_has_stack)
- printf_filtered ("[Current thread is %d (%s)]\n",
+ printf_filtered (_("[Current thread is %d (%s)]\n"),
pid_to_thread_id (inferior_ptid),
target_tid_to_str (inferior_ptid));
else
- error ("No stack.");
+ error (_("No stack."));
return;
}
- gdb_thread_select (uiout, tidstr);
+ gdb_thread_select (uiout, tidstr, NULL);
}
static int
tp = find_thread_id (num);
if (!tp)
- error ("Thread ID %d not known.", num);
+ error (_("Thread ID %d not known."), num);
if (!thread_alive (tp))
- error ("Thread ID %d has terminated.\n", num);
+ error (_("Thread ID %d has terminated."), num);
switch_to_thread (tp->ptid);
ui_out_text (uiout, target_tid_to_str (inferior_ptid));
ui_out_text (uiout, ")]");
- print_stack_frame (get_selected_frame (), 1, SRC_AND_LOC);
+ print_stack_frame (get_selected_frame (NULL), 1, SRC_AND_LOC);
return GDB_RC_OK;
}
enum gdb_rc
-gdb_thread_select (struct ui_out *uiout, char *tidstr)
+gdb_thread_select (struct ui_out *uiout, char *tidstr, char **error_message)
{
- return catch_exceptions (uiout, do_captured_thread_select, tidstr,
- NULL, RETURN_MASK_ALL);
+ return catch_exceptions_with_msg (uiout, do_captured_thread_select, tidstr,
+ error_message, RETURN_MASK_ALL);
}
/* Commands with a prefix of `thread'. */
static struct cmd_list_element *thread_apply_list = NULL;
add_info ("threads", info_threads_command,
- "IDs of currently known threads.");
+ _("IDs of currently known threads."));
- 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);
+ 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);
add_prefix_cmd ("apply", class_run, thread_apply_command,
- "Apply a command to a list of threads.",
- &thread_apply_list, "apply ", 1, &thread_cmd_list);
+ _("Apply a command to a list of threads."),
+ &thread_apply_list, "thread apply ", 1, &thread_cmd_list);
add_cmd ("all", class_run, thread_apply_all_command,
- "Apply a command to all threads.", &thread_apply_list);
+ _("Apply a command to all threads."), &thread_apply_list);
if (!xdb_commands)
add_com_alias ("t", "thread", class_run, 1);