Disabling warnings for certain operations
Matheus Branco Borella via Gdb <[email protected]>
| Newsgroups | gmane.comp.gdb.devel |
|---|---|
| Message-ID | <CAOJgb+WhMFDeU2gE7wvbnC37XQFH1U9aVutRdARXeriDwUCb6A@mail.gmail.com> |
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?