aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gdb/ChangeLog8
-rw-r--r--gdb/NEWS6
-rw-r--r--gdb/doc/ChangeLog5
-rw-r--r--gdb/doc/gdb.texinfo16
-rw-r--r--gdb/inferior.c58
-rw-r--r--gdb/testsuite/ChangeLog5
-rw-r--r--gdb/testsuite/gdb.base/inferior-noarg.c22
-rw-r--r--gdb/testsuite/gdb.base/inferior-noarg.exp36
8 files changed, 135 insertions, 21 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 739b39e..209834a 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,11 @@
+2021-02-02 Lancelot SIX <lsix@lancelotsix.com>
+
+ * NEWS (Changed commands): Add entry for the behavior change of
+ the inferior command.
+ * inferior.c (inferior_command): When no argument is given to the
+ inferior command, display info about the currently selected
+ inferior.
+
2021-02-02 Simon Marchi <simon.marchi@efficios.com>
* dwarf2/read.c (read_loclist_index, read_rnglist_index): Return
diff --git a/gdb/NEWS b/gdb/NEWS
index d2ed288..d4c7657 100644
--- a/gdb/NEWS
+++ b/gdb/NEWS
@@ -80,6 +80,12 @@ set style version background COLOR
set style version intensity VALUE
Control the styling of GDB's version number text.
+inferior [ID]
+ When the ID parameter is omitted, then this command prints information
+ about the current inferior. When the ID parameter is present, the
+ behavior of the command is unchanged and have the inferior ID become
+ the current inferior.
+
*** Changes in GDB 10
* There are new feature names for ARC targets: "org.gnu.gdb.arc.core"
diff --git a/gdb/doc/ChangeLog b/gdb/doc/ChangeLog
index 2d6517d..7b21966 100644
--- a/gdb/doc/ChangeLog
+++ b/gdb/doc/ChangeLog
@@ -1,3 +1,8 @@
+2021-02-02 Lancelot SIX <lsix@lancelotsix.com>
+
+ * gdb.texinfo (Inferiors Connections and Programs): Document the
+ inferior command when used without argument.
+
2021-01-27 Tom Tromey <tromey@adacore.com>
* gdb.texinfo (Auto-loading extensions): Remove extraneous space.
diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
index 84243a7..174fd6d 100644
--- a/gdb/doc/gdb.texinfo
+++ b/gdb/doc/gdb.texinfo
@@ -3118,6 +3118,22 @@ For example,
2 process 2307 2 (extended-remote host:10000) hello
@end smallexample
+To get informations about the current inferior, use @code{inferior}:
+
+@table @code
+@kindex inferior
+@item inferior
+Shows information about the current inferior.
+
+For example,
+@end table
+@c end table here to get a little more width for example
+
+@smallexample
+(@value{GDBP}) inferior
+[Current inferior is 1 [process 3401] (helloworld)]
+@end smallexample
+
To find out what open target connections exist at any moment, use
@w{@code{info connections}}:
diff --git a/gdb/inferior.c b/gdb/inferior.c
index 3ff0512..49f869a 100644
--- a/gdb/inferior.c
+++ b/gdb/inferior.c
@@ -635,34 +635,50 @@ inferior_command (const char *args, int from_tty)
struct inferior *inf;
int num;
- num = parse_and_eval_long (args);
-
- inf = find_inferior_id (num);
- if (inf == NULL)
- error (_("Inferior ID %d not known."), num);
-
- if (inf->pid != 0)
+ if (args == nullptr)
{
- if (inf != current_inferior ())
- {
- thread_info *tp = any_thread_of_inferior (inf);
- if (tp == NULL)
- error (_("Inferior has no threads."));
+ inf = current_inferior ();
+ gdb_assert (inf != nullptr);
+ const char *filename = inf->pspace->exec_filename.get ();
- switch_to_thread (tp);
- }
+ if (filename == nullptr)
+ filename = _("<noexec>");
- gdb::observers::user_selected_context_changed.notify
- (USER_SELECTED_INFERIOR
- | USER_SELECTED_THREAD
- | USER_SELECTED_FRAME);
+ printf_filtered (_("[Current inferior is %d [%s] (%s)]\n"),
+ inf->num, inferior_pid_to_str (inf->pid).c_str (),
+ filename);
}
else
{
- switch_to_inferior_no_thread (inf);
+ num = parse_and_eval_long (args);
+
+ inf = find_inferior_id (num);
+ if (inf == NULL)
+ error (_("Inferior ID %d not known."), num);
+
+ if (inf->pid != 0)
+ {
+ if (inf != current_inferior ())
+ {
+ thread_info *tp = any_thread_of_inferior (inf);
+ if (tp == NULL)
+ error (_("Inferior has no threads."));
- gdb::observers::user_selected_context_changed.notify
- (USER_SELECTED_INFERIOR);
+ switch_to_thread (tp);
+ }
+
+ gdb::observers::user_selected_context_changed.notify
+ (USER_SELECTED_INFERIOR
+ | USER_SELECTED_THREAD
+ | USER_SELECTED_FRAME);
+ }
+ else
+ {
+ switch_to_inferior_no_thread (inf);
+
+ gdb::observers::user_selected_context_changed.notify
+ (USER_SELECTED_INFERIOR);
+ }
}
}
diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog
index f03b2db..5731d0e 100644
--- a/gdb/testsuite/ChangeLog
+++ b/gdb/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+2021-02-02 Lancelot SIX <lsix@lancelotsix.com>
+
+ * gdb.base/inferior-noarg.c: New test.
+ * gdb.base/inferior-noarg.exp: New test.
+
2021-02-02 Simon Marchi <simon.marchi@polymtl.ca>
* gdb.base/scope.exp: Use proc_with_prefix.
diff --git a/gdb/testsuite/gdb.base/inferior-noarg.c b/gdb/testsuite/gdb.base/inferior-noarg.c
new file mode 100644
index 0000000..bfe52c0
--- /dev/null
+++ b/gdb/testsuite/gdb.base/inferior-noarg.c
@@ -0,0 +1,22 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+ Copyright 2021 Free Software Foundation, Inc.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+int
+main (void)
+{
+ return 0;
+}
diff --git a/gdb/testsuite/gdb.base/inferior-noarg.exp b/gdb/testsuite/gdb.base/inferior-noarg.exp
new file mode 100644
index 0000000..65d23fe
--- /dev/null
+++ b/gdb/testsuite/gdb.base/inferior-noarg.exp
@@ -0,0 +1,36 @@
+# Copyright 2021 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+# This test case checks that the 'inferior' command, when given no
+# argument, displays information about the inferior currently active.
+
+standard_testfile
+
+if { [prepare_for_testing "failed to prepare" \
+ ${testfile} ${srcfile}] } {
+ return
+}
+
+gdb_test "inferior" "\[Current inferior is 1 \[<null>\] (.*)\]" "inferior not running"
+
+if { ![runto_main] } {
+ untested "could not run to main"
+ return
+}
+
+gdb_test "inferior" {\[Current inferior is 1 \[.*\] (.*)\]} "inferior running"
+gdb_test "clone-inferior" "Added inferior 2.*" "create new inferior"
+gdb_test "inferior 2" "\[Switching to inferior 2 \[<null>\] (.*)]" "change inferior"
+gdb_test "inferior" "\[Current inferior is 2 \[<null>\] (.*)\]" "show new inferior"