]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
gdb: update doc for the $_ variable and search commands
authorTankut Baris Aktemur <tankut.baris.aktemur@intel.com>
Thu, 5 Mar 2026 15:07:53 +0000 (16:07 +0100)
committerTankut Baris Aktemur <tankut.baris.aktemur@intel.com>
Thu, 5 Mar 2026 15:08:10 +0000 (16:08 +0100)
I noticed that forward-search and reverse-search commands set the $_
convenience variable.  This is mentioned in the help menu (see below)
but is not stated in the documentation.  Add related text to the doc.

  (gdb) help search
  forward-search, fo, search
  Search for regular expression (see regex(3)) from last line listed.
  The matching line number is also stored as the value of "$_".
  (gdb) help rev
  reverse-search, rev
  Search backward for regular expression (see regex(3)) from last line listed.
  The matching line number is also stored as the value of "$_".
  (gdb)

Reviewed-By: Eli Zaretskii <eliz@gnu.org>
Reviewed-By: Keith Seitz <keiths@redhat.com>
Approved-By: Tom Tromey <tom@tromey.com>
gdb/doc/gdb.texinfo

index c74c58c1d4a8df3046522edb8544c0e6a0252455..3cba156cf898fe1b40dcb731b1a5e667eed3dc01 100644 (file)
@@ -9990,20 +9990,23 @@ regular expression.
 @kindex search
 @kindex forward-search
 @kindex fo @r{(@code{forward-search})}
+@cindex @code{$_} and commands that search source files
 @item forward-search @var{regexp}
 @itemx search @var{regexp}
 The command @samp{forward-search @var{regexp}} checks each line,
 starting with the one following the last line listed, for a match for
-@var{regexp}.  It lists the line that is found.  You can use the
-synonym @samp{search @var{regexp}} or abbreviate the command name as
-@code{fo}.
+@var{regexp}.  It lists the line that is found and saves it in the
+convenience variable @code{$_} (@pxref{Convenience Vars, ,Convenience
+Variables}).  You can use the synonym @samp{search @var{regexp}}
+or abbreviate the command name as @code{fo}.
 
 @kindex reverse-search
 @item reverse-search @var{regexp}
 The command @samp{reverse-search @var{regexp}} checks each line, starting
 with the one before the last line listed and going backward, for a match
-for @var{regexp}.  It lists the line that is found.  You can abbreviate
-this command as @code{rev}.
+for @var{regexp}.  It lists the line that is found and saves it in the
+convenience variable @code{$_} (@pxref{Convenience Vars, ,Convenience
+Variables}).  You can abbreviate this command as @code{rev}.
 @end table
 
 @node Source Path
@@ -13112,6 +13115,11 @@ and @code{info breakpoint}.  The type of @code{$_} is @code{void *}
 except when set by the @code{x} command, in which case it is a pointer
 to the type of @code{$__}.
 
+The @code{forward-search} and @code{reverse-search} commands
+(@pxref{Search, ,Searching Source Files}) set the @code{$_} variable
+to the line number that is found as a result of the search.  In that
+case the type of @code{$_} becomes @code{int}.
+
 @vindex $__@r{, convenience variable}
 @item $__
 The variable @code{$__} is automatically set by the @code{x} command