From: Tom Tromey <tromey@adacore.com>
To: gdb-patches@sourceware.org
Cc: Tom Tromey <tromey@adacore.com>
Subject: [PATCH RFC 3/6] Allow missing build-id when finding an objfile
Date: Thu, 22 Oct 2026 12:28:13 -0600 [thread overview]
Message-ID: <20261022-android-apk-file-v1-3-8444bb5f832a@adacore.com> (raw)
In-Reply-To: <20261022-android-apk-file-v1-0-8444bb5f832a@adacore.com>
Currently the "missing objfile" code requires a build-id.
However, in my situation, the build-id is not known. But, aside from
this small detail, the missing objfile code looked close to what I
wanted to implement.
This patch extends the API to allow the build-id to be missing. In
this case, None is passed to Python.
However, because this is an API change, MissingObjfileHandler is also
extended to record whether the build-id is required. And, by default
it is required, so that existing handlers won't be called in this new
situation.
---
gdb/python/lib/gdb/__init__.py | 17 +++++++++++++----
gdb/python/lib/gdb/missing_objfile.py | 4 ++++
gdb/python/python.c | 17 +++++++++++------
3 files changed, 28 insertions(+), 10 deletions(-)
diff --git a/gdb/python/lib/gdb/__init__.py b/gdb/python/lib/gdb/__init__.py
index 1a4aefcd802..f16e0a66c5b 100644
--- a/gdb/python/lib/gdb/__init__.py
+++ b/gdb/python/lib/gdb/__init__.py
@@ -382,7 +382,8 @@ def _handle_missing_objfile(pspace, buildid, filename):
pspace: A gdb.Progspace for which the missing objfile handlers
should be run. This is the program space in which an
objfile was found to be missing.
- buildid: A string containing the build-id we're looking for.
+ buildid: A string containing the build-id we're looking for,
+ or None if the buildid is not known.
filename: The filename of the file GDB tried to find but
couldn't. This is not where the file should be
placed if found, in fact, this file might already
@@ -403,9 +404,17 @@ def _handle_missing_objfile(pspace, buildid, filename):
missing objfile.
"""
- return _handle_missing_files(
- pspace, "objfile", lambda h: h(pspace, buildid, filename)
- )
+ # Delay this as long as possible.
+ from gdb.missing_objfile import MissingObjfileHandler
+
+ def maybe_call_handler(handler):
+ if buildid is not None or (
+ isinstance(handler, MissingObjfileHandler) and not handler.buildid_required
+ ):
+ return handler(pspace, buildid, filename)
+ return None
+
+ return _handle_missing_files(pspace, "objfile", maybe_call_handler)
class ParameterPrefix:
diff --git a/gdb/python/lib/gdb/missing_objfile.py b/gdb/python/lib/gdb/missing_objfile.py
index 45661d0f415..fe45a418c6d 100644
--- a/gdb/python/lib/gdb/missing_objfile.py
+++ b/gdb/python/lib/gdb/missing_objfile.py
@@ -30,8 +30,12 @@ class MissingObjfileHandler(MissingFileHandler):
Attributes:
name: Read-only attribute, the name of this handler.
enabled: When true this handler is enabled.
+ buildid_required: When False, this handler can accept a
+ request with buildid=None.
"""
+ buildid_required = True
+
def __call__(self, buildid, filename):
"""Handle a missing objfile when GDB can knows the build-id.
diff --git a/gdb/python/python.c b/gdb/python/python.c
index 5a9c876c197..06ad0876527 100644
--- a/gdb/python/python.c
+++ b/gdb/python/python.c
@@ -1950,7 +1950,6 @@ gdbpy_find_objfile_from_buildid (const struct extension_language_defn *extlang,
const char *missing_filename)
{
gdb_assert (pspace != nullptr);
- gdb_assert (build_id != nullptr);
gdb_assert (missing_filename != nullptr);
/* Early exit if Python is not initialised. */
@@ -1960,12 +1959,18 @@ gdbpy_find_objfile_from_buildid (const struct extension_language_defn *extlang,
gdbpy_enter enter_py;
/* Convert BUILD_ID into a Python object. */
- std::string hex_form = bin2hex (build_id->data, build_id->size);
- gdbpy_ref<> pyo_buildid = host_string_to_python_string (hex_form.c_str ());
- if (pyo_buildid == nullptr)
+ gdbpy_ref<> pyo_buildid;
+ if (build_id == nullptr)
+ pyo_buildid = gdbpy_ref<>::new_reference (Py_None);
+ else
{
- gdbpy_print_stack ();
- return {};
+ std::string hex_form = bin2hex (build_id->data, build_id->size);
+ pyo_buildid = host_string_to_python_string (hex_form.c_str ());
+ if (pyo_buildid == nullptr)
+ {
+ gdbpy_print_stack ();
+ return {};
+ }
}
/* Convert MISSING_FILENAME to a Python object. */
--
2.56.0
next prev parent reply other threads:[~2026-10-22 18:28 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-22 18:28 [PATCH RFC 0/6] Handle Android APK files Tom Tromey
2026-10-22 18:28 ` [PATCH RFC 1/6] Add py-file.c Tom Tromey
2026-10-22 18:28 ` [PATCH RFC 2/6] Add py-iovec.c Tom Tromey
2026-10-22 18:28 ` Tom Tromey [this message]
2026-10-22 18:28 ` [PATCH RFC 4/6] Allow missing objfile handler to return a file Tom Tromey
2026-10-22 18:28 ` [PATCH RFC 5/6] Call ext_lang_find_objfile_from_buildid from solib_bfd_fopen Tom Tromey
2026-10-22 18:28 ` [PATCH RFC 6/6] Add gdb.handler.android module 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=20261022-android-apk-file-v1-3-8444bb5f832a@adacore.com \
--to=tromey@adacore.com \
--cc=gdb-patches@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