Add possibility to disable showing search memory access warnings

Message ID CABEVAa3J2mh1_b3tkmd-dV31QMKfz+yWEPdDdvO7m4OYaPzmSA@mail.gmail.com
State New, archived
Headers

Commit Message

Dominik Czarnota Nov. 28, 2017, 12:53 a.m. UTC
  I have changed the parameter name to `search-memory-warnings`
as the previous name might have been not so obvious what happens
when this is on or off (and actually the `show` command worked badly on that).

I am going to add docs and tests and send full patch with those.
Below you can see the current version.


gdb/ChangeLog:

    * target.c: Add search_memory_warnings boolean parameter.



2017-11-27 0:00 GMT+01:00 Dominik Czarnota <dominik.b.czarnota@gmail.com>:
> Hey,
>
> This patches adds a `disable-search-warnings` parameter that can be
> set to make memory searching not displaying warnings like:
> `Unable to access X bytes of target memory at Y, halting search.`
>
> As far as I know this is used by `find` command and Python API's
> `inferior.search_memory` method. The latter is used in GDB plugins
> like pwndbg (https://github.com/pwndbg/pwndbg) where we have
> a `search` command that lets one search all memory for given values.
>
> By the way, is there some kind of code linter for Gdb? What's the best
> way to stay within the same coding convention gdb uses?
> It seems to me that some code mixes tabs with spaces, is that
> some relict of the past? Should new code use one or another?
> If so, which one?
>
> Thanks,
> disconnect3d
>
>
> gdb/ChangeLog:
>
>     * target.c: Add disable_search_warnings boolean parameter.
>
>
> diff --git a/gdb/target.c b/gdb/target.c
> index 3bfc8b5aef..a79e1ce5ac 100644
> --- a/gdb/target.c
> +++ b/gdb/target.c
> @@ -162,6 +162,18 @@ int may_insert_fast_tracepoints = 1;
>
>  int may_stop = 1;
>
> +
> +/* Whether not to show search memory access warnings.  */
> +
> +int disable_search_warnings = 0;
> +
> +static void
> +show_disable_search_warnings (struct ui_file *file, int from_tty,
> +  struct cmd_list_element *c, const char *value)
> +{
> +  fprintf_filtered (file, _("Search memory access warnings are %s.\n"), value);
> +}
> +
>  /* Non-zero if we want to see trace of target level stuff.  */
>
>  static unsigned int targetdebug = 0;
> @@ -2345,9 +2357,10 @@ simple_search_memory (struct target_ops *ops,
>     search_buf.data (), start_addr, search_buf_size)
>        != search_buf_size)
>      {
> -      warning (_("Unable to access %s bytes of target "
> - "memory at %s, halting search."),
> -       pulongest (search_buf_size), hex_string (start_addr));
> +      if (!disable_search_warnings)
> +        warning (_("Unable to access %s bytes of target "
> +                  "memory at %s, halting search."),
> +                pulongest (search_buf_size), hex_string (start_addr));
>        return -1;
>      }
>
> @@ -2400,10 +2413,10 @@ simple_search_memory (struct target_ops *ops,
>     &search_buf[keep_len], read_addr,
>     nr_to_read) != nr_to_read)
>      {
> -      warning (_("Unable to access %s bytes of target "
> - "memory at %s, halting search."),
> -       plongest (nr_to_read),
> -       hex_string (read_addr));
> +      if (!disable_search_warnings)
> +        warning (_("Unable to access %s bytes of target "
> +                  "memory at %s, halting search."),
> +                pulongest (nr_to_read), hex_string (read_addr));
>        return -1;
>      }
>
> @@ -4084,6 +4097,17 @@ verbose."),
>       show_targetdebug,
>       &setdebuglist, &showdebuglist);
>
> +  add_setshow_boolean_cmd ("disable-search-warnings", class_support,
> +   &disable_search_warnings, _("\
> +Set mode for disabling search memory warnings."), _("\
> +Show mode for disabling search memory warnings."), _("\
> +When this mode is on, both find command and Python API's \n\
> +inferior.search_memory function won't warn about being \n\
> +unable to access target memory. "),
> +   NULL,
> +   show_disable_search_warnings,
> +   &setlist, &showlist);
> +
>    add_setshow_boolean_cmd ("trust-readonly-sections", class_support,
>     &trust_readonly, _("\
>  Set mode for reading from readonly sections."), _("\
  

Patch

diff --git a/gdb/target.c b/gdb/target.c
index 3bfc8b5aef..5bb1ac608d 100644
--- a/gdb/target.c
+++ b/gdb/target.c
@@ -162,6 +162,18 @@  int may_insert_fast_tracepoints = 1;

 int may_stop = 1;

+
+/* Whether not to show search memory access warnings.  */
+
+int search_memory_warnings = 1;
+
+static void
+show_search_memory_warnings (struct ui_file *file, int from_tty,
+  struct cmd_list_element *c, const char *value)
+{
+  fprintf_filtered (file, _("Search warnings are %s.\n"), value);
+}
+
 /* Non-zero if we want to see trace of target level stuff.  */

 static unsigned int targetdebug = 0;
@@ -2345,9 +2357,10 @@  simple_search_memory (struct target_ops *ops,
    search_buf.data (), start_addr, search_buf_size)
       != search_buf_size)
     {
-      warning (_("Unable to access %s bytes of target "
- "memory at %s, halting search."),
-       pulongest (search_buf_size), hex_string (start_addr));
+      if (search_memory_warnings)
+        warning (_("Unable to access %s bytes of target "
+                  "memory at %s, halting search."),
+                pulongest (search_buf_size), hex_string (start_addr));
       return -1;
     }

@@ -2400,10 +2413,10 @@  simple_search_memory (struct target_ops *ops,
    &search_buf[keep_len], read_addr,
    nr_to_read) != nr_to_read)
     {
-      warning (_("Unable to access %s bytes of target "
- "memory at %s, halting search."),
-       plongest (nr_to_read),
-       hex_string (read_addr));
+      if (search_memory_warnings)
+        warning (_("Unable to access %s bytes of target "
+                  "memory at %s, halting search."),
+                pulongest (nr_to_read), hex_string (read_addr));
       return -1;
     }

@@ -4084,6 +4097,17 @@  verbose."),
      show_targetdebug,
      &setdebuglist, &showdebuglist);

+  add_setshow_boolean_cmd ("search-memory-warnings", class_support,
+   &search_memory_warnings, _("\
+Set mode for printing search memory warnings."), _("\
+Show mode for printing search memory warnings."), _("\
+When this mode is on, both find command and Python API's\n\
+inferior.search_memory function may print warnings about\n\
+being unable to access target memory."),
+   NULL,
+   show_search_memory_warnings,
+   &setlist, &showlist);
+
   add_setshow_boolean_cmd ("trust-readonly-sections", class_support,
    &trust_readonly, _("\
 Set mode for reading from readonly sections."), _("\