public inbox for gdb@sourceware.org
 help / color / mirror / Atom feed
From: Matheus Branco Borella <dark.ryu.550@gmail.com>
To: gdb@sourceware.org
Subject: Disabling warnings for certain operations
Date: Wed, 19 Jul 2023 20:54:00 -0300	[thread overview]
Message-ID: <CAOJgb+WhMFDeU2gE7wvbnC37XQFH1U9aVutRdARXeriDwUCb6A@mail.gmail.com> (raw)

When a call to `target_search_memory` is made, GDB will print a
warning that the memory could not be read if `simple_search_memory` is
used by the target in the current inferior. While this behavior is
perfectly sensible from the point of view of a user triggering the
call from the GDB command line directly, that same call is also
triggered by calling `gdb.Inferior.search_memory` from Python, meaning
the warning in that case will be printed even if the user has no
direct involvement with the call.

This becomes a usability problem when Python routines like Pwndbg's
search command have to scan over memory and end up hitting ranges that
`target_search_memory` fails to read, and, while the search routine
itself can gracefully handle that case, a string of warnings gets
printed, regardless. Here is an example:
```
pwndbg> search aasdqw
Searching for value: 'aasdqw'
warning: Unable to access 16000 bytes of target memory at
0x7ffff7147d05, halting search.
warning: Unable to access 16005 bytes of target memory at
0x7ffff7348000, halting search.
warning: Unable to access 16005 bytes of target memory at
0x7ffff75b9000, halting search.
warning: Unable to access 16000 bytes of target memory at
0x7ffff79a8d05, halting search.
warning: Unable to access 16005 bytes of target memory at
0x7ffff7bd0000, halting search.
```

As a workaround, I've hacked around GDB a bit, and added an option in
`target.c` (set through `set print-default-memory-search-warnings
off`) to suppress the warning message when `simple_search_memory` is
called from `default_search_memory`. Ideally, I'd like to submit some
form of achieving this as a patch, but the current solution feels
hacky and rough.

Is there a better way to do this? Or some way to query whether a range
can be read ahead of time so that calling `gdb.Inferior.search_memory`
may be skipped for those ranges, avoiding the path that would trigger
the warning altogether?

             reply	other threads:[~2023-07-19 23:54 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-07-19 23:54 Matheus Branco Borella [this message]
2023-07-23 19:54 ` Tom Tromey

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAOJgb+WhMFDeU2gE7wvbnC37XQFH1U9aVutRdARXeriDwUCb6A@mail.gmail.com \
    --to=dark.ryu.550@gmail.com \
    --cc=gdb@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).