Fix "thread apply $conv_var" and misc other related problems

This fixes a few bugs in "thread apply".

While this works:

 (gdb) thread apply 1 p 1234

 Thread 1 (Thread 0x7ffff7fc1740 (LWP 14048)):
 $1 = 1234

This doesn't:

 (gdb) thread apply $thr p 1234

 Thread 1 (Thread 0x7ffff7fc1740 (LWP 12039)):
 Invalid thread ID: p 1234
 (gdb)

~~~~

Also, while this works:
 (gdb) thread apply 1
 Please specify a command following the thread ID list

This doesn't:
 (gdb) thread apply $thr
 Thread 1 (Thread 0x7ffff7fc1740 (LWP 12039)):
 [Current thread is 1 (Thread 0x7ffff7fc1740 (LWP 12039))]
 (gdb)

~~~~

And, while this works:
 (gdb) thread apply
 Please specify a thread ID list

This obviously bogus invocation is just silent:
 (gdb) thread apply bt
 (gdb)

gdb/ChangeLog:
2016-01-15  Pedro Alves  <palves@redhat.com>

	* thread.c (thread_apply_command): Use the tid range parser to
	advance past the thread ID list.
	* tid-parse.c (get_positive_number_trailer): New function.
	(parse_thread_id): Use it.
	(get_tid_or_range): Use it.  Return 0 instead of throwing invalid
	thread ID error.
	(get_tid_or_range): Detect negative values.  Return 0 instead of
	throwing invalid thread ID error.

gdb/testsuite/ChangeLog:
2016-01-15  Pedro Alves  <palves@redhat.com>

	* gdb.multi/tids.exp (thr_apply_info_thr_error): Remove "p 1234"
	command from "thread apply" invocation.
	(thr_apply_info_thr_invalid): Default the expected output to the
	input tid list.
	(top level): Add tests that use convenience variables.  Add tests
	for "thread apply" with a valid TID list, but missing the command.
This commit is contained in:
Pedro Alves
2016-01-15 21:46:22 +00:00
parent 9c03a84f6c
commit 3f5b759880
5 changed files with 163 additions and 20 deletions

View File

@@ -1818,7 +1818,7 @@ thread_apply_all_command (char *cmd, int from_tty)
static void
thread_apply_command (char *tidlist, int from_tty)
{
char *cmd;
char *cmd = NULL;
struct cleanup *old_chain;
char *saved_cmd;
struct tid_range_parser parser;
@@ -1826,11 +1826,25 @@ thread_apply_command (char *tidlist, int from_tty)
if (tidlist == NULL || *tidlist == '\000')
error (_("Please specify a thread ID list"));
for (cmd = tidlist; *cmd != '\000' && !isalpha (*cmd); cmd++);
tid_range_parser_init (&parser, tidlist, current_inferior ()->num);
while (!tid_range_parser_finished (&parser))
{
int inf_num, thr_start, thr_end;
if (*cmd == '\000')
if (!tid_range_parser_get_tid_range (&parser,
&inf_num, &thr_start, &thr_end))
{
cmd = (char *) tid_range_parser_string (&parser);
break;
}
}
if (cmd == NULL)
error (_("Please specify a command following the thread ID list"));
if (tidlist == cmd || !isalpha (cmd[0]))
invalid_thread_id_error (cmd);
/* Save a copy of the command in case it is clobbered by
execute_command. */
saved_cmd = xstrdup (cmd);