From aea5b2797c9c4e3a33c9a9ebd14614165486c293 Mon Sep 17 00:00:00 2001 From: Michael Snyder Date: Mon, 21 Feb 2011 23:40:47 +0000 Subject: [PATCH] 2011-02-21 Michael Snyder * gdbthread.h (print_thread_info): Change prototype. * thread.c (print_thread_info): Accept char* instead of int for requested_threads argument. Use new function number_is_in_list to determine which threads to list. (info_threads_command): Pass char* to print_thread_info. * cli/cli-utils.c (number_is_in_list): New function. * cli/cli-utils.h (number_is_in_list): Export. * mi/mi-main.c (mi_cmd_thread_info): Pass char* to print_thread_info. (print_one_inferior): Ditto. (mi_cmd_list_thread_groups): Ditto. 2011-02-21 Michael Snyder * gdb.threads/thread-find.exp: Update patterns for changes in output of "info threads" command. --- gdb/ChangeLog | 14 +++++++ gdb/cli/cli-utils.c | 21 ++++++++++ gdb/cli/cli-utils.h | 10 +++++ gdb/gdbthread.h | 2 +- gdb/mi/mi-main.c | 11 ++---- gdb/testsuite/ChangeLog | 5 +++ gdb/testsuite/gdb.threads/thread-find.exp | 48 +++++++++++------------ gdb/thread.c | 36 ++++++----------- 8 files changed, 89 insertions(+), 58 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index bd4667e402..c768945bf4 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,17 @@ +2011-02-21 Michael Snyder + + * gdbthread.h (print_thread_info): Change prototype. + * thread.c (print_thread_info): Accept char* instead of int for + requested_threads argument. Use new function number_is_in_list + to determine which threads to list. + (info_threads_command): Pass char* to print_thread_info. + * cli/cli-utils.c (number_is_in_list): New function. + * cli/cli-utils.h (number_is_in_list): Export. + * mi/mi-main.c (mi_cmd_thread_info): Pass char* to + print_thread_info. + (print_one_inferior): Ditto. + (mi_cmd_list_thread_groups): Ditto. + 2011-02-21 Jan Kratochvil * common/Makefile.in (CFLAGS): New. diff --git a/gdb/cli/cli-utils.c b/gdb/cli/cli-utils.c index 0c98ca9eb0..8a7e5d40d3 100644 --- a/gdb/cli/cli-utils.c +++ b/gdb/cli/cli-utils.c @@ -161,6 +161,27 @@ get_number_or_range (char **pp) return last_retval; } +/* Accept a number and a string-form list of numbers such as is + accepted by get_number_or_range. Return TRUE if the number is + in the list. + + By definition, an empty list includes all numbers. This is to + be interpreted as typing a command such as "delete break" with + no arguments. */ + +int +number_is_in_list (char *list, int number) +{ + if (list == NULL || *list == '\0') + return 1; + + while (list != NULL && *list != '\0') + if (get_number_or_range (&list) == number) + return 1; + + return 0; +} + /* See documentation in cli-utils.h. */ char * diff --git a/gdb/cli/cli-utils.h b/gdb/cli/cli-utils.h index e79b82ec58..6158999860 100644 --- a/gdb/cli/cli-utils.h +++ b/gdb/cli/cli-utils.h @@ -45,6 +45,16 @@ extern int get_number (char **); extern int get_number_or_range (char **); +/* Accept a number and a string-form list of numbers such as is + accepted by get_number_or_range. Return TRUE if the number is + in the list. + + By definition, an empty list includes all numbers. This is to + be interpreted as typing a command such as "delete break" with + no arguments. */ + +extern int number_is_in_list (char *list, int number); + /* Skip leading whitespace characters in INP, returning an updated pointer. If INP is NULL, return NULL. */ diff --git a/gdb/gdbthread.h b/gdb/gdbthread.h index ddb7b0f66c..43db95a771 100644 --- a/gdb/gdbthread.h +++ b/gdb/gdbthread.h @@ -377,7 +377,7 @@ extern struct cmd_list_element *thread_cmd_list; `set print thread-events'. */ extern int print_thread_events; -extern void print_thread_info (struct ui_out *uiout, int thread, +extern void print_thread_info (struct ui_out *uiout, char *threads, int pid); extern struct cleanup *make_cleanup_restore_current_thread (void); diff --git a/gdb/mi/mi-main.c b/gdb/mi/mi-main.c index 1f1b7129b7..6ffe207138 100644 --- a/gdb/mi/mi-main.c +++ b/gdb/mi/mi-main.c @@ -503,15 +503,10 @@ mi_cmd_thread_list_ids (char *command, char **argv, int argc) void mi_cmd_thread_info (char *command, char **argv, int argc) { - int thread = -1; - if (argc != 0 && argc != 1) error ("Invalid MI command"); - if (argc == 1) - thread = atoi (argv[0]); - - print_thread_info (uiout, thread, -1); + print_thread_info (uiout, argv[0], -1); } struct collect_cores_data @@ -607,7 +602,7 @@ print_one_inferior (struct inferior *inferior, void *xdata) } if (top_data->recurse) - print_thread_info (uiout, -1, inferior->pid); + print_thread_info (uiout, NULL, inferior->pid); do_cleanups (back_to); } @@ -872,7 +867,7 @@ mi_cmd_list_thread_groups (char *command, char **argv, int argc) if (!inf) error ("Non-existent thread group id '%d'", id); - print_thread_info (uiout, -1, inf->pid); + print_thread_info (uiout, NULL, inf->pid); } else { diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog index b498f4b37b..f6387bd6bf 100644 --- a/gdb/testsuite/ChangeLog +++ b/gdb/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2011-02-21 Michael Snyder + + * gdb.threads/thread-find.exp: Update patterns for changes in + output of "info threads" command. + 2011-02-21 Matthew Gretton-Dann Ulrich Weigand diff --git a/gdb/testsuite/gdb.threads/thread-find.exp b/gdb/testsuite/gdb.threads/thread-find.exp index e01b792bbb..1d8d3162e4 100644 --- a/gdb/testsuite/gdb.threads/thread-find.exp +++ b/gdb/testsuite/gdb.threads/thread-find.exp @@ -303,28 +303,28 @@ set see5 0 set see6 0 gdb_test_multiple "info threads 2 4 6" "info threads 2 4 6" { - -re ". 1 \[^\r\n\]*\"threadname_1\" \[^\r\n\]*" { - set see1 1 - exp_continue - } - -re ". 2 \[^\r\n\]*\"threadname_2\" \[^\r\n\]*" { - set see2 1 + -re ". 6 \[^\r\n\]*\"threadname_6\" \[^\r\n\]*" { + set see6 1 exp_continue } - -re ". 3 \[^\r\n\]*\"threadname_3\" \[^\r\n\]*" { - set see3 1 + -re ". 5 \[^\r\n\]*\"threadname_5\" \[^\r\n\]*" { + set see5 1 exp_continue } -re ". 4 \[^\r\n\]*\"threadname_4\" \[^\r\n\]*" { set see4 1 exp_continue } - -re ". 5 \[^\r\n\]*\"threadname_5\" \[^\r\n\]*" { - set see5 1 + -re ". 3 \[^\r\n\]*\"threadname_3\" \[^\r\n\]*" { + set see3 1 exp_continue } - -re ". 6 \[^\r\n\]*\"threadname_6\" \[^\r\n\]*" { - set see6 1 + -re ". 2 \[^\r\n\]*\"threadname_2\" \[^\r\n\]*" { + set see2 1 + exp_continue + } + -re ". 1 \[^\r\n\]*\"threadname_1\" \[^\r\n\]*" { + set see1 1 exp_continue } -re "$gdb_prompt $" { @@ -348,28 +348,28 @@ set see5 0 set see6 0 gdb_test_multiple "info threads 3-5" "info threads 3-5" { - -re ". 1 .*\"threadname_1\" \[^\r\n\]*" { - set see1 1 - exp_continue - } - -re ". 2 .*\"threadname_2\" \[^\r\n\]*" { - set see2 1 + -re ". 6 .*\"threadname_6\" \[^\r\n\]*" { + set see6 1 exp_continue } - -re ". 3 .*\"threadname_3\" \[^\r\n\]*" { - set see3 1 + -re ". 5 .*\"threadname_5\" \[^\r\n\]*" { + set see5 1 exp_continue } -re ". 4 .*\"threadname_4\" \[^\r\n\]*" { set see4 1 exp_continue } - -re ". 5 .*\"threadname_5\" \[^\r\n\]*" { - set see5 1 + -re ". 3 .*\"threadname_3\" \[^\r\n\]*" { + set see3 1 exp_continue } - -re ". 6 .*\"threadname_6\" \[^\r\n\]*" { - set see6 1 + -re ". 2 .*\"threadname_2\" \[^\r\n\]*" { + set see2 1 + exp_continue + } + -re ". 1 .*\"threadname_1\" \[^\r\n\]*" { + set see1 1 exp_continue } -re "$gdb_prompt $" { diff --git a/gdb/thread.c b/gdb/thread.c index a8d7adfe0b..7d8f6da353 100644 --- a/gdb/thread.c +++ b/gdb/thread.c @@ -44,6 +44,7 @@ #include "annotate.h" #include "cli/cli-decode.h" #include "gdb_regex.h" +#include "cli/cli-utils.h" /* Definition of struct thread_info exported to gdbthread.h. */ @@ -755,7 +756,7 @@ finish_thread_state_cleanup (void *arg) } /* Prints the list of threads and their details on UIOUT. - This is a version of 'info_thread_command' suitable for + This is a version of 'info_threads_command' suitable for use from MI. If REQUESTED_THREAD is not -1, it's the GDB id of the thread that should be printed. Otherwise, all threads are @@ -766,7 +767,7 @@ finish_thread_state_cleanup (void *arg) is printed if it belongs to the specified process. Otherwise, an error is raised. */ void -print_thread_info (struct ui_out *uiout, int requested_thread, int pid) +print_thread_info (struct ui_out *uiout, char *requested_threads, int pid) { struct thread_info *tp; ptid_t current_ptid; @@ -791,7 +792,7 @@ print_thread_info (struct ui_out *uiout, int requested_thread, int pid) for (tp = thread_list; tp; tp = tp->next) { - if (requested_thread != -1 && tp->num != requested_thread) + if (!number_is_in_list (requested_threads, tp->num)) continue; if (pid != -1 && PIDGET (tp->ptid) != pid) @@ -805,10 +806,11 @@ print_thread_info (struct ui_out *uiout, int requested_thread, int pid) if (n_threads == 0) { - if (requested_thread == -1) + if (requested_threads == NULL || *requested_threads == '\0') ui_out_message (uiout, 0, _("No threads.\n")); else - ui_out_message (uiout, 0, _("No thread %d.\n"), requested_thread); + ui_out_message (uiout, 0, _("No threads match '%s'.\n"), + requested_threads); do_cleanups (old_chain); return; } @@ -827,12 +829,12 @@ print_thread_info (struct ui_out *uiout, int requested_thread, int pid) struct cleanup *chain2; int core; - if (requested_thread != -1 && tp->num != requested_thread) + if (!number_is_in_list (requested_threads, tp->num)) continue; if (pid != -1 && PIDGET (tp->ptid) != pid) { - if (requested_thread != -1) + if (requested_threads != NULL && *requested_threads != '\0') error (_("Requested thread not found in requested process")); continue; } @@ -935,7 +937,7 @@ print_thread_info (struct ui_out *uiout, int requested_thread, int pid) the "info threads" command. */ do_cleanups (old_chain); - if (pid == -1 && requested_thread == -1) + if (pid == -1 && requested_threads == NULL) { gdb_assert (current_thread != -1 || !thread_list @@ -966,23 +968,7 @@ No selected thread. See `help thread'.\n"); static void info_threads_command (char *arg, int from_tty) { - int tid = -1; - - if (arg == NULL || *arg == '\0') - { - print_thread_info (uiout, -1, -1); - return; - } - - while (arg != NULL && *arg != '\0') - { - tid = get_number_or_range (&arg); - - if (tid <= 0) - error (_("invalid thread id %d"), tid); - - print_thread_info (uiout, tid, -1); - } + print_thread_info (uiout, arg, -1); } /* Switch from one thread to another. */ -- 2.34.1