The search_memory() method on the gdb.Inferior objects disregards the particular inferior and always searches the memory of the current inferior instead. The error is here: ``` static PyObject * infpy_search_memory (PyObject *self, PyObject *args, PyObject *kw) { ... found = target_search_memory (start_addr, length, buffer, pattern_size, &found_addr); ``` (Can also be seen on https://github.com/bminor/binutils-gdb/blob/a89e364b45a93acd20f48abd787ef5cb7c07f683/gdb/python/py-inferior.c#L659). Instead of calling target_search_memory(...args) the GDB should call self->...<some field referencing inferior>...->top_target()->search_memory(...args) This can be triggered from Python API via `gdb.selected_inferior().search_memory(...)` but I haven't created a reproducer that would tell if this is really a problem or not. However, the fact that there is a "selected inferior" suggests that there could be. Thanks to my friend Arusekk who spotted this bug.
Relevant documentation: https://sourceware.org/gdb/onlinedocs/gdb/Inferiors-Connections-and-Programs.html
Python bug.
I think this affects reading and writing memory as well.
I have a patch.
https://sourceware.org/pipermail/gdb-patches/2023-July/200719.html
The master branch has been updated by Tom Tromey <tromey@sourceware.org>: https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=75ec09829780f8d00d8515e07101a29272a22303 commit 75ec09829780f8d00d8515e07101a29272a22303 Author: Tom Tromey <tromey@adacore.com> Date: Thu Jul 6 11:33:47 2023 -0600 Use correct inferior in Inferior.read_memory et al A user noticed that Inferior.read_memory and a few other Python APIs will always use the currently selected inferior, not the one passed to the call. This patch fixes the bug by arranging to switch to the inferior. I found this same issue in several APIs, so this fixes them all. I also added a few missing calls to INFPY_REQUIRE_VALID to these methods. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30615 Approved-By: Pedro Alves <pedro@palves.net>
Fixed.