public inbox for gdb@sourceware.org
 help / color / mirror / Atom feed
* Disabling warnings for certain operations
@ 2023-07-19 23:54 Matheus Branco Borella
  2023-07-23 19:54 ` Tom Tromey
  0 siblings, 1 reply; 2+ messages in thread
From: Matheus Branco Borella @ 2023-07-19 23:54 UTC (permalink / raw)
  To: gdb

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?

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Disabling warnings for certain operations
  2023-07-19 23:54 Disabling warnings for certain operations Matheus Branco Borella
@ 2023-07-23 19:54 ` Tom Tromey
  0 siblings, 0 replies; 2+ messages in thread
From: Tom Tromey @ 2023-07-23 19:54 UTC (permalink / raw)
  To: Matheus Branco Borella via Gdb; +Cc: Matheus Branco Borella

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

TBH I'd expect reading inaccessible memory to throw a Python exception.

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

I wonder if "info proc mappings" could be used somehow, or extended to
provide some Python API.

Anyway I think doing something here would be great -- the real question
is just which approach is both useful and doable.

Tom

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-07-23 19:54 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-07-19 23:54 Disabling warnings for certain operations Matheus Branco Borella
2023-07-23 19:54 ` Tom Tromey

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).