diff options
author | Pedro Alves <palves@redhat.com> | 2016-01-15 21:46:22 +0000 |
---|---|---|
committer | Pedro Alves <palves@redhat.com> | 2016-01-15 21:46:22 +0000 |
commit | 3f5b7598805c8253c43c989a540a2408c8b685ad (patch) | |
tree | 74f71dc4893338da7d523e24e80a635aa48ce2cc /gdb/tid-parse.c | |
parent | 9c03a84f6cc54af01d4fe655f6e0a0aa13d8ef74 (diff) | |
download | binutils-gdb-3f5b7598805c8253c43c989a540a2408c8b685ad.tar.gz |
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.
Diffstat (limited to 'gdb/tid-parse.c')
-rw-r--r-- | gdb/tid-parse.c | 35 |
1 files changed, 29 insertions, 6 deletions
diff --git a/gdb/tid-parse.c b/gdb/tid-parse.c index 21b872d39d3..45b7ff56dc2 100644 --- a/gdb/tid-parse.c +++ b/gdb/tid-parse.c @@ -31,6 +31,23 @@ invalid_thread_id_error (const char *string) error (_("Invalid thread ID: %s"), string); } +/* Wrapper for get_number_trailer that throws an error if we get back + a negative number. We'll see a negative value if the number is + stored in a negative convenience variable (e.g., $minus_one = -1). + STRING is the parser string to be used in the error message if we + do get back a negative number. */ + +static int +get_positive_number_trailer (const char **pp, int trailer, const char *string) +{ + int num; + + num = get_number_trailer (pp, trailer); + if (num < 0) + error (_("negative value: %s"), string); + return num; +} + /* See tid-parse.h. */ struct thread_info * @@ -51,7 +68,7 @@ parse_thread_id (const char *tidstr, const char **end) int inf_num; p1 = number; - inf_num = get_number_trailer (&p1, '.'); + inf_num = get_positive_number_trailer (&p1, '.', number); if (inf_num == 0) invalid_thread_id_error (number); @@ -69,7 +86,7 @@ parse_thread_id (const char *tidstr, const char **end) p1 = number; } - thr_num = get_number_const (&p1); + thr_num = get_positive_number_trailer (&p1, 0, number); if (thr_num == 0) invalid_thread_id_error (number); @@ -183,15 +200,16 @@ get_tid_or_range (struct tid_range_parser *parser, int *inf_num, /* Parse number to the left of the dot. */ p = parser->string; - parser->inf_num = get_number_trailer (&p, '.'); + parser->inf_num + = get_positive_number_trailer (&p, '.', parser->string); if (parser->inf_num == 0) - invalid_thread_id_error (parser->string); + return 0; parser->qualified = 1; p = dot + 1; if (isspace (*p)) - invalid_thread_id_error (parser->string); + return 0; } else { @@ -206,8 +224,13 @@ get_tid_or_range (struct tid_range_parser *parser, int *inf_num, *inf_num = parser->inf_num; *thr_start = get_number_or_range (&parser->range_parser); + if (*thr_start < 0) + error (_("negative value: %s"), parser->string); if (*thr_start == 0) - invalid_thread_id_error (parser->string); + { + parser->state = TID_RANGE_STATE_INFERIOR; + return 0; + } /* If we successfully parsed a thread number or finished parsing a thread range, switch back to assuming the next TID is |