Add a new $_inferior convenience variable
authorPedro Alves <palves@redhat.com>
Wed, 13 Jan 2016 10:56:05 +0000 (10:56 +0000)
committerPedro Alves <palves@redhat.com>
Wed, 13 Jan 2016 10:56:05 +0000 (10:56 +0000)
Like $_thread, but holds the current inferior number.

gdb/ChangeLog:
2016-01-13  Pedro Alves  <palves@redhat.com>

* NEWS: Mention $_inferior.
* inferior.c (inferior_id_make_value): New.
(inferior_funcs): New.
(_initialize_inferior): Create $_inferior variable.

gdb/testsuite/ChangeLog:
2016-01-13  Pedro Alves  <palves@redhat.com>

* gdb.base/default.exp: Expect $_inferior as well.
* gdb.multi/base.exp: Test $_inferior.

gdb/doc/ChangeLog:
2016-01-13  Pedro Alves  <palves@redhat.com>

* gdb.texinfo (Inferiors and Programs): Document the $_inferior
convenience variable.
(Convenience Vars): Likewise.

gdb/ChangeLog
gdb/NEWS
gdb/doc/ChangeLog
gdb/doc/gdb.texinfo
gdb/inferior.c
gdb/testsuite/ChangeLog
gdb/testsuite/gdb.base/default.exp
gdb/testsuite/gdb.multi/base.exp

index ceb8c1812172c5474b75a9b9a99219a7f8b0d2ca..1e6f9227fa7810ddcf0106670a10a1bb859b21d3 100644 (file)
@@ -1,3 +1,10 @@
+2016-01-13  Pedro Alves  <palves@redhat.com>
+
+       * NEWS: Mention $_inferior.
+       * inferior.c (inferior_id_make_value): New.
+       (inferior_funcs): New.
+       (_initialize_inferior): Create $_inferior variable.
+
 2016-01-13  Pedro Alves  <palves@redhat.com>
 
        PR breakpoints/19388
index 85642fb96de4efe24c1f57ae27421d1b97277063..c22ac54565d9b9380261b2aebe5bc7a0312139a1 100644 (file)
--- a/gdb/NEWS
+++ b/gdb/NEWS
@@ -3,6 +3,9 @@
 
 *** Changes since GDB 7.10
 
+* The new convenience variable $_inferior holds the number of the
+  current inferior.
+
 * Record btrace now supports non-stop mode.
 
 * Support for tracepoints on aarch64-linux was added in GDBserver.
index b4ea0ee36123b78a94051577ac77583f37762fb9..b51e8df587b9802fdbe8ee50f1e53d69e637f619 100644 (file)
@@ -1,3 +1,9 @@
+2016-01-13  Pedro Alves  <palves@redhat.com>
+
+       * gdb.texinfo (Inferiors and Programs): Document the $_inferior
+       convenience variable.
+       (Convenience Vars): Likewise.
+
 2016-01-12  Josh Stone  <jistone@redhat.com>
            Philippe Waroquiers  <philippe.waroquiers@skynet.be>
 
index 35065e03c094f7eb5da8b95e10112cbb17e57613..d4452a96db96cb4b07af6461335f331e42061e42 100644 (file)
@@ -2658,6 +2658,12 @@ Make inferior number @var{infno} the current inferior.  The argument
 in the first field of the @samp{info inferiors} display.
 @end table
 
+@vindex $_inferior@r{, convenience variable}
+The debugger convenience variable @samp{$_inferior} contains the
+number of the current inferior.  You may find this useful in writing
+breakpoint conditional expressions, command scripts, and so forth.
+@xref{Convenience Vars,, Convenience Variables}, for general
+information on convenience variables.
 
 You can get multiple executables into a debugging session via the
 @code{add-inferior} and @w{@code{clone-inferior}} commands.  On some
@@ -10382,6 +10388,10 @@ gdbserver that supports the @code{qGetTIBAddr} request.
 @xref{General Query Packets}.
 This variable contains the address of the thread information block.
 
+@item $_inferior
+The number of the current inferior.  @xref{Inferiors and
+Programs, ,Debugging Multiple Inferiors and Programs}.
+
 @end table
 
 @node Convenience Funs
index e71104d6e90c5e9efe472d7e0905203a2e55fa19..8f9ac3358b2b52b43723a90de1ce292297a4edf0 100644 (file)
@@ -1008,6 +1008,26 @@ show_print_inferior_events (struct ui_file *file, int from_tty,
   fprintf_filtered (file, _("Printing of inferior events is %s.\n"), value);
 }
 
+/* Return a new value for the selected inferior's id.  */
+
+static struct value *
+inferior_id_make_value (struct gdbarch *gdbarch, struct internalvar *var,
+                       void *ignore)
+{
+  struct inferior *inf = current_inferior ();
+
+  return value_from_longest (builtin_type (gdbarch)->builtin_int, inf->num);
+}
+
+/* Implementation of `$_inferior' variable.  */
+
+static const struct internalvar_funcs inferior_funcs =
+{
+  inferior_id_make_value,
+  NULL,
+  NULL
+};
+
 \f
 
 void
@@ -1071,4 +1091,5 @@ Show printing of inferior events (e.g., inferior start and exit)."), NULL,
          show_print_inferior_events,
          &setprintlist, &showprintlist);
 
+  create_internalvar_type_lazy ("_inferior", &inferior_funcs, NULL);
 }
index a27a6a5a8236a3ec4b10e17875be94d44ee562ab..5d773ca4fc0c7f3e1db2c6a39adb0bf798ea380d 100644 (file)
@@ -1,3 +1,8 @@
+2016-01-13  Pedro Alves  <palves@redhat.com>
+
+       * gdb.base/default.exp: Expect $_inferior as well.
+       * gdb.multi/base.exp: Test $_inferior.
+
 2016-01-13  Pedro Alves  <palves@redhat.com>
 
        PR breakpoints/19388
index 90bf27d8c7291c3802ef4bc1a80c6eb0c8199036..fec2cded525214c046f9c73580728ebf9778d884 100644 (file)
@@ -587,6 +587,7 @@ set show_conv_list \
        {$_sdata = void} \
        {$_siginfo = void} \
        {$_thread = 0} \
+       {$_inferior = 1} \
        {$_exception = <error: No frame selected>} \
        {$_probe_argc = <error: No frame selected>} \
        {$_probe_arg0 = <error: No frame selected>} \
index 6f0bc63b71c0f20feee6bd8c7c6c244a730cf934..1aa907daba780347a15fb6205b5b0fe2acc1b30c 100644 (file)
@@ -44,12 +44,16 @@ if { [build_executable ${testfile}.exp ${exec3} "${srcfile3}" {debug}] == -1 } {
 
 clean_restart ${exec1}
 
+gdb_test {print $_inferior} " = 1"
+
 # Add an empty inferior, switch to it, and load a main executable into
 # it.
 gdb_test "add-inferior" "Added inferior 2.*" "add empty inferior 2"
 gdb_test "inferior 2" "Switching to inferior 2.*" "switch to inferior 2"
 gdb_test "file ${binfile2}" ".*" "load ${exec2} file in inferior 2"
 
+gdb_test {print $_inferior} " = 2" "print \$_inferior after switching"
+
 # Add a new inferior and load a main executable into it in one
 # command.
 gdb_test "add-inferior -exec ${binfile3}" \
This page took 0.050677 seconds and 4 git commands to generate.