#include "symtab.h"
#include "frame.h"
#include "inferior.h"
-#include "environ.h"
+#include "common/environ.h"
#include "value.h"
#include "target.h"
#include "gdbthread.h"
#include <algorithm>
#include "common/gdb_optional.h"
#include "inline-frame.h"
+#include "stack.h"
/* Definition of struct thread_info exported to gdbthread.h. */
{
if (thr->thread_fsm != NULL)
{
- thread_fsm_clean_up (thr->thread_fsm, thr);
- thread_fsm_delete (thr->thread_fsm);
+ thr->thread_fsm->clean_up (thr);
+ delete thr->thread_fsm;
thr->thread_fsm = NULL;
}
}
result->priv.reset (priv);
if (print_thread_events)
- printf_unfiltered (_("[New %s]\n"), target_pid_to_str (ptid));
+ printf_unfiltered (_("[New %s]\n"), target_pid_to_str (ptid).c_str ());
annotate_new_thread ();
return result;
step_over_chain_remove (&step_over_queue_head, tp);
}
-/* Delete thread TP. If SILENT, don't notify the observer of this
- exit. */
+/* Delete the thread referenced by THR. If SILENT, don't notifyi
+ the observer of this exit.
+
+ THR must not be NULL or a failed assertion will be raised. */
static void
delete_thread_1 (thread_info *thr, bool silent)
{
- struct thread_info *tp, *tpprev;
+ gdb_assert (thr != nullptr);
- tpprev = NULL;
+ struct thread_info *tp, *tpprev = NULL;
for (tp = thr->inf->thread_list; tp; tpprev = tp, tp = tp->next)
if (tp == thr)
/* See gdbthread.h. */
struct thread_info *
-find_thread_by_handle (struct value *thread_handle, struct inferior *inf)
+find_thread_by_handle (gdb::array_view<const gdb_byte> handle,
+ struct inferior *inf)
{
- return target_thread_handle_to_thread_info
- (value_contents_all (thread_handle),
- TYPE_LENGTH (value_type (thread_handle)),
- inf);
+ return target_thread_handle_to_thread_info (handle.data (),
+ handle.size (),
+ inf);
}
/*
static std::string
thread_target_id_str (thread_info *tp)
{
- const char *target_id = target_pid_to_str (tp->ptid);
+ std::string target_id = target_pid_to_str (tp->ptid);
const char *extra_info = target_extra_thread_info (tp);
const char *name = tp->name != nullptr ? tp->name : target_thread_name (tp);
if (extra_info != nullptr && name != nullptr)
- return string_printf ("%s \"%s\" (%s)", target_id, name, extra_info);
+ return string_printf ("%s \"%s\" (%s)", target_id.c_str (), name,
+ extra_info);
else if (extra_info != nullptr)
- return string_printf ("%s (%s)", target_id, extra_info);
+ return string_printf ("%s (%s)", target_id.c_str (), extra_info);
else if (name != nullptr)
- return string_printf ("%s \"%s\"", target_id, name);
+ return string_printf ("%s \"%s\"", target_id.c_str (), name);
else
return target_id;
}
/* See gdbthread.h. */
void
-print_thread_info (struct ui_out *uiout, char *requested_threads, int pid)
+print_thread_info (struct ui_out *uiout, const char *requested_threads,
+ int pid)
{
print_thread_info_1 (uiout, requested_threads, 1, pid, 0);
}
const qcs_flags &flags)
{
switch_to_thread (thr);
- TRY
+ try
{
- std::string cmd_result = execute_command_to_string (cmd, from_tty);
+ std::string cmd_result = execute_command_to_string
+ (cmd, from_tty, gdb_stdout->term_out ());
if (!flags.silent || cmd_result.length () > 0)
{
if (!flags.quiet)
printf_filtered (_("\nThread %s (%s):\n"),
print_thread_id (thr),
- target_pid_to_str (inferior_ptid));
+ target_pid_to_str (inferior_ptid).c_str ());
printf_filtered ("%s", cmd_result.c_str ());
}
}
- CATCH (ex, RETURN_MASK_ERROR)
+ catch (const gdb_exception_error &ex)
{
if (!flags.silent)
{
if (!flags.quiet)
printf_filtered (_("\nThread %s (%s):\n"),
print_thread_id (thr),
- target_pid_to_str (inferior_ptid));
+ target_pid_to_str (inferior_ptid).c_str ());
if (flags.cont)
- printf_filtered ("%s\n", ex.message);
+ printf_filtered ("%s\n", ex.what ());
else
- throw_exception (ex);
+ throw;
}
}
- END_CATCH;
}
/* Apply a GDB command to a list of threads. List syntax is a whitespace
{
qcs_flags flags;
const char *cmd = NULL;
- const char *cmd_or_flags;
tid_range_parser parser;
if (tidlist == NULL || *tidlist == '\000')
int inf_num, thr_start, thr_end;
if (!parser.get_tid_range (&inf_num, &thr_start, &thr_end))
- {
- cmd = parser.cur_tok ();
- break;
- }
+ break;
}
- cmd_or_flags = cmd;
- while (cmd != NULL && parse_flags_qcs ("thread apply", &cmd, &flags))
+ cmd = parser.cur_tok ();
+
+ while (parse_flags_qcs ("thread apply", &cmd, &flags))
;
- if (cmd == NULL)
+ if (*cmd == '\0')
error (_("Please specify a command following the thread ID list"));
- if (tidlist == cmd || !isalpha (cmd[0]))
+ if (tidlist == cmd || isdigit (cmd[0]))
invalid_thread_id_error (cmd);
scoped_restore_current_thread restore_thread;
parser.init (tidlist, current_inferior ()->num);
- while (!parser.finished () && parser.cur_tok () < cmd_or_flags)
+ while (!parser.finished ())
{
struct thread_info *tp = NULL;
struct inferior *inf;
tfaas_command (const char *cmd, int from_tty)
{
std::string expanded
- = std::string ("thread apply all -s frame apply all -s ") + cmd;
+ = std::string ("thread apply all -s -- frame apply all -s ") + cmd;
execute_command (expanded.c_str (), from_tty);
}
if (tp->state == THREAD_EXITED)
printf_filtered (_("[Current thread is %s (%s) (exited)]\n"),
print_thread_id (tp),
- target_pid_to_str (inferior_ptid));
+ target_pid_to_str (inferior_ptid).c_str ());
else
printf_filtered (_("[Current thread is %s (%s)]\n"),
print_thread_id (tp),
- target_pid_to_str (inferior_ptid));
+ target_pid_to_str (inferior_ptid).c_str ());
}
else
error (_("No stack."));
match++;
}
- tmp = target_pid_to_str (tp->ptid);
- if (tmp != NULL && re_exec (tmp))
+ std::string name = target_pid_to_str (tp->ptid);
+ if (!name.empty () && re_exec (name.c_str ()))
{
printf_filtered (_("Thread %s has target id '%s'\n"),
- print_thread_id (tp), tmp);
+ print_thread_id (tp), name.c_str ());
match++;
}
uiout->text ("[Switching to thread ");
uiout->field_string ("new-thread-id", print_thread_id (tp));
uiout->text (" (");
- uiout->text (target_pid_to_str (inferior_ptid));
+ uiout->text (target_pid_to_str (inferior_ptid).c_str ());
uiout->text (")]");
}
}
_initialize_thread (void)
{
static struct cmd_list_element *thread_apply_list = NULL;
+ cmd_list_element *c;
add_info ("threads", info_threads_command,
_("Display currently known threads.\n\
Usage: taas COMMAND\n\
shortcut for 'thread apply all -s COMMAND'"));
- add_com ("tfaas", class_run, tfaas_command, _("\
+ c = add_com ("tfaas", class_run, tfaas_command, _("\
Apply a command to all frames of all threads (ignoring errors and empty output).\n\
-Usage: tfaas COMMAND\n\
-shortcut for 'thread apply all -s frame apply all -s COMMAND'"));
+Usage: tfaas [OPTION]... COMMAND\n\
+shortcut for 'thread apply all -s -- frame apply all -s [OPTION]... COMMAND'\n\
+See \"help frame apply all\" for available options."));
+ set_cmd_completer_handle_brkchars (c, frame_apply_all_cmd_completer);
add_cmd ("name", class_run, thread_name_command,
_("Set the current thread's name.\n\