This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
[rfa] Use get_number_or_range for "info inferiors"
- From: Michael Snyder <msnyder at vmware dot com>
- To: "gdb-patches at sourceware dot org" <gdb-patches at sourceware dot org>, "tromey at redhat dot com" <tromey at redhat dot com>, Pedro Alves <pedro at codesourcery dot com>
- Date: Thu, 24 Feb 2011 15:51:12 -0800
- Subject: [rfa] Use get_number_or_range for "info inferiors"
Slickify command, and add a test.
2011-02-24 Michael Snyder <msnyder@vmware.com>
* inferior.c (print_inferior): Accept a string instead of an int
for requested_inferiors, and use get_number_or_range to parse it.
(info_inferiors_command): Pass args string to print_inferior.
(initialize_inferiors): Change help string for info inferiors.
* inferior.h (print_inferior): Export prototype change.
2011-02-24 Michael Snyder <msnyder@vmware.com>
* gdb.multi/base.exp: Add tests for info inferiors with args.
Index: inferior.c
===================================================================
RCS file: /cvs/src/src/gdb/inferior.c,v
retrieving revision 1.23
diff -u -p -u -p -r1.23 inferior.c
--- inferior.c 9 Jan 2011 03:08:56 -0000 1.23
+++ inferior.c 24 Feb 2011 23:46:41 -0000
@@ -30,6 +30,7 @@
#include "gdbcore.h"
#include "symfile.h"
#include "environ.h"
+#include "cli/cli-utils.h"
void _initialize_inferiors (void);
@@ -536,7 +537,7 @@ number_of_inferiors (void)
If REQUESTED_INFERIOR is not -1, it's the GDB id of the inferior that
should be printed. Otherwise, all inferiors are printed. */
void
-print_inferior (struct ui_out *uiout, int requested_inferior)
+print_inferior (struct ui_out *uiout, char *requested_inferiors)
{
struct inferior *inf;
struct cleanup *old_chain;
@@ -545,7 +546,7 @@ print_inferior (struct ui_out *uiout, in
/* Compute number of inferiors we will print. */
for (inf = inferior_list; inf; inf = inf->next)
{
- if (requested_inferior != -1 && inf->num != requested_inferior)
+ if (!number_is_in_list (requested_inferiors, inf->num))
continue;
++inf_count;
@@ -569,7 +570,7 @@ print_inferior (struct ui_out *uiout, in
{
struct cleanup *chain2;
- if (requested_inferior != -1 && inf->num != requested_inferior)
+ if (!number_is_in_list (requested_inferiors, inf->num))
continue;
chain2 = make_cleanup_ui_out_tuple_begin_end (uiout, NULL);
@@ -726,16 +727,7 @@ inferior_command (char *args, int from_t
static void
info_inferiors_command (char *args, int from_tty)
{
- int requested = -1;
-
- if (args && *args)
- {
- requested = parse_and_eval_long (args);
- if (!valid_gdb_inferior_id (requested))
- error (_("Inferior ID %d not known."), requested);
- }
-
- print_inferior (uiout, requested);
+ print_inferior (uiout, args);
}
/* remove-inferior ID */
@@ -1048,8 +1040,8 @@ initialize_inferiors (void)
current_inferior_->pspace = current_program_space;
current_inferior_->aspace = current_program_space->aspace;
- add_info ("inferiors", info_inferiors_command,
- _("IDs of currently known inferiors."));
+ add_info ("inferiors", info_inferiors_command,
+ _("IDs of specified inferiors (all inferiors if no argument)."));
add_com ("add-inferior", no_class, add_inferior_command, _("\
Add a new inferior.\n\
Index: inferior.h
===================================================================
RCS file: /cvs/src/src/gdb/inferior.h,v
retrieving revision 1.150
diff -u -p -u -p -r1.150 inferior.h
--- inferior.h 16 Feb 2011 14:54:42 -0000 1.150
+++ inferior.h 24 Feb 2011 23:46:41 -0000
@@ -620,7 +620,7 @@ extern struct inferior *iterate_over_inf
If REQUESTED_INFERIOR is not -1, it's the GDB id of the inferior
that should be printed. Otherwise, all inferiors are printed. */
-extern void print_inferior (struct ui_out *uiout, int requested_inferior);
+extern void print_inferior (struct ui_out *uiout, char *requested_inferiors);
/* Returns true if the inferior list is not empty. */
extern int have_inferiors (void);
Index: testsuite/gdb.multi/base.exp
===================================================================
RCS file: /cvs/src/src/gdb/testsuite/gdb.multi/base.exp,v
retrieving revision 1.7
diff -u -p -u -p -r1.7 base.exp
--- testsuite/gdb.multi/base.exp 1 Jan 2011 15:33:48 -0000 1.7
+++ testsuite/gdb.multi/base.exp 24 Feb 2011 23:46:42 -0000
@@ -61,6 +61,60 @@ gdb_test "add-inferior -exec ${binfile3}
gdb_test "info inferiors" \
"Executable.*${exec3}.*${exec2}.*${exec1}.*"
+# Test info inferiors with args
+
+set see1 0
+set see2 0
+set see3 0
+
+gdb_test_multiple "info inferior 2 3" "info inferior 2 3" {
+ -re ". 3 \[^\r\n\]*${exec3}" {
+ set see3 1
+ exp_continue
+ }
+ -re ". 2 \[^\r\n\]*${exec2}" {
+ set see2 1
+ exp_continue
+ }
+ -re ". 1 \[^\r\n\]*${exec1}" {
+ set see1 1
+ exp_continue
+ }
+ -re "$gdb_prompt $" {
+ if { !$see1 && $see2 && $see3 } then {
+ pass "info inferior 2 3"
+ } else {
+ fail "info inferior 2 3"
+ }
+ }
+}
+
+set see1 0
+set see2 0
+set see3 0
+
+gdb_test_multiple "info inferior 1-2" "info inferior 1-2" {
+ -re ". 3 \[^\r\n\]*${exec3}" {
+ set see3 1
+ exp_continue
+ }
+ -re ". 2 \[^\r\n\]*${exec2}" {
+ set see2 1
+ exp_continue
+ }
+ -re ". 1 \[^\r\n\]*${exec1}" {
+ set see1 1
+ exp_continue
+ }
+ -re "$gdb_prompt $" {
+ if { $see1 && $see2 && !$see3 } then {
+ pass "info inferior 1-2"
+ } else {
+ fail "info inferior 1-2"
+ }
+ }
+}
+
# Test that we have multiple symbol tables.
gdb_test "inferior 1" ".*" "switch to inferior 1"