Update find command help and search memory docs

Message ID CABEVAa00=iRWkgmr8+f01HDFKMqzeu80C9E2nRWVDvY2LhmseQ@mail.gmail.com
State New, archived
Headers

Commit Message

Dominik Czarnota Nov. 26, 2017, 3:44 p.m. UTC
  Hey,

This patch updates `find` command help and docs description to show
how to search for not null terminated strings when current language's
strings includes it.

It addresses an issue I have opened here:
https://sourceware.org/bugzilla/show_bug.cgi?id=21945 and so it can be
closed.

Thanks,
Dominik aka 'disconnect3d'


gdb/ChangeLog:

    PR gdb/21945
    * findcmd.c (_initialize_mem_search), gdb/doc/gdb.texinfo: Update
find command description.
    * doc/gdb.texinfo: Update search memory description and example.


 Convenience variable \"$numfound\" is set to the number of matches."),
  

Comments

Eli Zaretskii Nov. 26, 2017, 5:43 p.m. UTC | #1
> From: Dominik Czarnota <dominik.b.czarnota@gmail.com>
> Date: Sun, 26 Nov 2017 16:44:30 +0100
> 
> diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
> index 00451d243d..5b9946a9cf 100644
> --- a/gdb/doc/gdb.texinfo
> +++ b/gdb/doc/gdb.texinfo
> @@ -11920,6 +11920,8 @@ giant words (eight bytes)
>  All values are interpreted in the current language.
>  This means, for example, that if the current source language is C/C@t{++}
>  then searching for the string ``hello'' includes the trailing '\0'.
> +The null terminator can be removed from searching by using casts,
> +e.g.: @samp{{char[5]}"hello"}.
> 
>  If the value size is not specified, it is taken from the
>  value's type in the current language.
> @@ -11969,7 +11971,11 @@ you get during debugging:
>  (gdb) find &hello[0], +sizeof(hello), 'h', 'e', 'l', 'l', 'o'
>  0x8049567 <hello.1620>
>  0x804956d <hello.1620+6>
> -2 patterns found
> +2 patterns found.
> +(gdb) find &hello[0], +sizeof(hello), {char[5]}"hello"
> +0x8049567 <hello.1620>
> +0x804956d <hello.1620+6>
> +2 patterns found.
>  (gdb) find /b1 &hello[0], +sizeof(hello), 'h', 0x65, 'l'
>  0x8049567 <hello.1620>
>  1 pattern found

This part is OK.

> diff --git a/gdb/findcmd.c b/gdb/findcmd.c
> index b43fefc06d..ff6088eac1 100644
> --- a/gdb/findcmd.c
> +++ b/gdb/findcmd.c
> @@ -293,7 +293,9 @@ and if not specified the size is taken from the
> type of the expression\n\
>  in the current language.\n\
>  Note that this means for example that in the case of C-like languages\n\
>  a search for an untyped 0x42 will search for \"(int) 0x42\"\n\
> -which is typically four bytes.\n\
> +which is typically four bytes, and a search for a string \"hello\" will\n\
> +include the tralinig '\\0'. The null terminator can be removed from\n\
                             ^^
Two spaces here, please.

Thanks.
  

Patch

diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
index 00451d243d..5b9946a9cf 100644
--- a/gdb/doc/gdb.texinfo
+++ b/gdb/doc/gdb.texinfo
@@ -11920,6 +11920,8 @@  giant words (eight bytes)
 All values are interpreted in the current language.
 This means, for example, that if the current source language is C/C@t{++}
 then searching for the string ``hello'' includes the trailing '\0'.
+The null terminator can be removed from searching by using casts,
+e.g.: @samp{{char[5]}"hello"}.

 If the value size is not specified, it is taken from the
 value's type in the current language.
@@ -11969,7 +11971,11 @@  you get during debugging:
 (gdb) find &hello[0], +sizeof(hello), 'h', 'e', 'l', 'l', 'o'
 0x8049567 <hello.1620>
 0x804956d <hello.1620+6>
-2 patterns found
+2 patterns found.
+(gdb) find &hello[0], +sizeof(hello), {char[5]}"hello"
+0x8049567 <hello.1620>
+0x804956d <hello.1620+6>
+2 patterns found.
 (gdb) find /b1 &hello[0], +sizeof(hello), 'h', 0x65, 'l'
 0x8049567 <hello.1620>
 1 pattern found
diff --git a/gdb/findcmd.c b/gdb/findcmd.c
index b43fefc06d..ff6088eac1 100644
--- a/gdb/findcmd.c
+++ b/gdb/findcmd.c
@@ -293,7 +293,9 @@  and if not specified the size is taken from the
type of the expression\n\
 in the current language.\n\
 Note that this means for example that in the case of C-like languages\n\
 a search for an untyped 0x42 will search for \"(int) 0x42\"\n\
-which is typically four bytes.\n\
+which is typically four bytes, and a search for a string \"hello\" will\n\
+include the tralinig '\\0'. The null terminator can be removed from\n\
+searching by using casts, e.g.: {char[5]}\"hello\".\n\
 \n\
 The address of the last match is stored as the value of \"$_\".\n\