From b9a3f8429b012b753e30a4222bd8e4cbba019fad Mon Sep 17 00:00:00 2001 From: Pedro Alves Date: Thu, 13 Jun 2019 00:06:52 +0100 Subject: Fix TID parser bug I noticed this inconsistency in the error messages below: (gdb) print --1 Left operand of assignment is not an lvalue. (gdb) thread apply 1 print --1 Thread 1 (Thread 0x7ffff7fb6740 (LWP 17805)): inverted range The "inverted range" error happens because get_number_trailer returns 0 to indicate error, but number_or_range_parser::get_number is not checking for that. I tried detected the error there, but that doesn't work because number_of_range_parser is used in places that _do_ want to legitimately handle 0. IMO we should fix get_number_trailer's interface or use something else when we want to parse 0 too. I've decided to fix it in a different way, similarly to how number_or_range_parser::finished was changed in commit 529c08b25ec7 ("Add helper functions parse_flags and parse_flags_qcs"). Seems like a good change, even if we tweaked number_or_range_parser::get_number, as it simplifies thread_apply_command and makes them consistent with number_or_range_parser::finished(). We now get the same error message in both cases: (gdb) print --1 Left operand of assignment is not an lvalue. (gdb) thread apply 1 print --1 Thread 1 (Thread 0x7ffff7fb6740 (LWP 17805)): Left operand of assignment is not an lvalue. gdb/ChangeLog: 2019-06-13 Pedro Alves * thread.c (thread_apply_command): Adjust TID parsing. * tid-parse.c (tid_range_parser::finished): Ensure parsing end is detected before end of string. (tid_is_in_list): Error out if LIST is invalid. gdb/testsuite/ChangeLog: 2019-06-13 Pedro Alves * gdb.multi/tids.exp: Adjust expected output. Add "thread apply 1 foo --1" test. --- gdb/tid-parse.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'gdb/tid-parse.c') diff --git a/gdb/tid-parse.c b/gdb/tid-parse.c index 828362e..07d7d2c 100644 --- a/gdb/tid-parse.c +++ b/gdb/tid-parse.c @@ -139,7 +139,13 @@ tid_range_parser::finished () const switch (m_state) { case STATE_INFERIOR: - return *m_cur_tok == '\0'; + /* Parsing is finished when at end of string or null string, + or we are not in a range and not in front of an integer, negative + integer, convenience var or negative convenience var. */ + return (*m_cur_tok == '\0' + || !(isdigit (*m_cur_tok) + || *m_cur_tok == '$' + || *m_cur_tok == '*')); case STATE_THREAD_RANGE: case STATE_STAR_RANGE: return m_range_parser.finished (); @@ -311,6 +317,8 @@ tid_is_in_list (const char *list, int default_inferior, return 1; tid_range_parser parser (list, default_inferior); + if (parser.finished ()) + invalid_thread_id_error (parser.cur_tok ()); while (!parser.finished ()) { int tmp_inf, tmp_thr_start, tmp_thr_end; -- cgit v1.1