This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Add possibility to disable showing search memory access warnings


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."), _("\


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]