aboutsummaryrefslogtreecommitdiff
path: root/gdb/inferior.c
diff options
context:
space:
mode:
authorPedro Alves <palves@redhat.com>2016-10-13 01:54:07 +0100
committerPedro Alves <palves@redhat.com>2016-10-13 01:54:07 +0100
commitbfd282882d534cd4f48e2fc29d4ce0923c52352b (patch)
tree9709dac8ade7a9592772de9a6c4bb7d5b542c826 /gdb/inferior.c
parentb44fae2f56b0edbecff68c597f7b5718ca3f9f90 (diff)
downloadgdb-bfd282882d534cd4f48e2fc29d4ce0923c52352b.zip
gdb-bfd282882d534cd4f48e2fc29d4ce0923c52352b.tar.gz
gdb-bfd282882d534cd4f48e2fc29d4ce0923c52352b.tar.bz2
Convert tid_range_parser and get_number_or_range to classes
This converts tid_range_parser and get_number_or_range to be classes. The various tid_range_parser_* and get_number_or_range_* functions become methods on the respective classes. Then it updates the users to follow. The rationale for the change is that this provides better encapsulation. For example, this forced me to think of a better interface between tid_range_parser and get_number_or_range, since the former peeked into the latter's internals a bit too much. That ended up resulting mostly in these two not-just-straight-1-1 changes: void -tid_range_parser_skip (struct tid_range_parser *parser) +tid_range_parser::skip_range () { ... - tid_range_parser_init (parser, parser->range_parser.end_ptr, - parser->default_inferior); + m_range_parser.skip_range (); + init (m_range_parser.string (), m_default_inferior); } and: /* If we successfully parsed a thread number or finished parsing a thread range, switch back to assuming the next TID is inferior-qualified. */ - if (parser->range_parser.end_ptr == NULL - || parser->range_parser.string == parser->range_parser.end_ptr) + if (!m_range_parser.in_range ()) { For the same reason (encapsulation), this moves the enum tid_range_state definition to within the tid_parser class's scope, since that is private implementation detail. While at it, switch to use "bool" for booleans. gdb/ChangeLog: 2016-10-13 Pedro Alves <palves@redhat.com> Tom Tromey <tom@tromey.com> * tid-parse.h (tid_range_parser): New class. (enum tid_range_state): Move into tid_range_parser's scope. Remove TID_RANGE_ prefix from all values. (tid_range_parser_get_tid, tid_range_parser_get_tid_range) (tid_range_parser_star_range, tid_range_parser_finished) (tid_range_parser_skip, tid_range_parser_qualified): Don't declare. (tid_is_in_list): Update comment. * tid-parse.c (tid_range_parser::tid_range_parser): New. (init, finished, get_string, skip, tid_is_qualified) (get_tid_or_range, get_tid_range, get_tid, star_range): Rename; turn into methods. (tid_is_in_list): Adjust. * cli/cli-utils.h (number_or_range_parser): New class. (init_number_or_range, get_number_or_range) (number_range_setup_range): Don't declare. * cli/cli-utils.c (number_or_range_parser::number_or_range_parser): New. (init_number_or_range, get_number_or_range) (number_range_setup_range): Rename; turn into methods. (number_is_in_list): Adjust. * breakpoint.c (map_breakpoint_numbers): Adjust. Use bool. (trace_pass_command, get_tracepoint_by_number): Adjust. * breakpoint.h (get_tracepoint_by_number): Adjust. * inferior.c (detach_inferior_command, kill_inferior_command) (remove_inferior_command): Adjust. * linespec.c (decode_line_2): Adjust. * memattr.c (mem_enable_command, mem_disable_command) (mem_delete_command): Adjust. * printcmd.c (map_display_numbers): Adjust. * reverse.c (delete_bookmark_command, bookmarks_info): Adjust. * thread.c (thread_apply_command): Adjust.
Diffstat (limited to 'gdb/inferior.c')
-rw-r--r--gdb/inferior.c32
1 files changed, 12 insertions, 20 deletions
diff --git a/gdb/inferior.c b/gdb/inferior.c
index 277b988..1602483 100644
--- a/gdb/inferior.c
+++ b/gdb/inferior.c
@@ -651,17 +651,15 @@ print_inferior (struct ui_out *uiout, char *requested_inferiors)
static void
detach_inferior_command (char *args, int from_tty)
{
- int num, pid;
struct thread_info *tp;
- struct get_number_or_range_state state;
if (!args || !*args)
error (_("Requires argument (inferior id(s) to detach)"));
- init_number_or_range (&state, args);
- while (!state.finished)
+ number_or_range_parser parser (args);
+ while (!parser.finished ())
{
- num = get_number_or_range (&state);
+ int num = parser.get_number ();
if (!valid_gdb_inferior_id (num))
{
@@ -669,7 +667,7 @@ detach_inferior_command (char *args, int from_tty)
continue;
}
- pid = gdb_inferior_id_to_pid (num);
+ int pid = gdb_inferior_id_to_pid (num);
if (pid == 0)
{
warning (_("Inferior ID %d is not running."), num);
@@ -692,17 +690,15 @@ detach_inferior_command (char *args, int from_tty)
static void
kill_inferior_command (char *args, int from_tty)
{
- int num, pid;
struct thread_info *tp;
- struct get_number_or_range_state state;
if (!args || !*args)
error (_("Requires argument (inferior id(s) to kill)"));
- init_number_or_range (&state, args);
- while (!state.finished)
+ number_or_range_parser parser (args);
+ while (!parser.finished ())
{
- num = get_number_or_range (&state);
+ int num = parser.get_number ();
if (!valid_gdb_inferior_id (num))
{
@@ -710,7 +706,7 @@ kill_inferior_command (char *args, int from_tty)
continue;
}
- pid = gdb_inferior_id_to_pid (num);
+ int pid = gdb_inferior_id_to_pid (num);
if (pid == 0)
{
warning (_("Inferior ID %d is not running."), num);
@@ -788,18 +784,14 @@ info_inferiors_command (char *args, int from_tty)
static void
remove_inferior_command (char *args, int from_tty)
{
- int num;
- struct inferior *inf;
- struct get_number_or_range_state state;
-
if (args == NULL || *args == '\0')
error (_("Requires an argument (inferior id(s) to remove)"));
- init_number_or_range (&state, args);
- while (!state.finished)
+ number_or_range_parser parser (args);
+ while (!parser.finished ())
{
- num = get_number_or_range (&state);
- inf = find_inferior_id (num);
+ int num = parser.get_number ();
+ struct inferior *inf = find_inferior_id (num);
if (inf == NULL)
{