From: Tom Tromey <tromey@adacore.com>
To: gdb-patches@sourceware.org
Cc: Tom Tromey <tromey@adacore.com>
Subject: [PATCH RFC 6/6] Add gdb.handler.android module
Date: Thu, 22 Oct 2026 12:28:16 -0600 [thread overview]
Message-ID: <20261022-android-apk-file-v1-6-8444bb5f832a@adacore.com> (raw)
In-Reply-To: <20261022-android-apk-file-v1-0-8444bb5f832a@adacore.com>
This adds gdb.handler.android and arranges for it to be automatically
loaded. This new module provides a missing objfile handler that knows
how to extract a .so from an Android APK file.
---
gdb/data-directory/Makefile.in | 2 ++
gdb/python/lib/gdb/__init__.py | 2 +-
gdb/python/lib/gdb/handler/__init__.py | 14 +++++++++++
gdb/python/lib/gdb/handler/android.py | 43 ++++++++++++++++++++++++++++++++++
4 files changed, 60 insertions(+), 1 deletion(-)
diff --git a/gdb/data-directory/Makefile.in b/gdb/data-directory/Makefile.in
index 7257da9cd11..3c272efb982 100644
--- a/gdb/data-directory/Makefile.in
+++ b/gdb/data-directory/Makefile.in
@@ -124,6 +124,8 @@ PYTHON_FILE_LIST = \
gdb/function/as_string.py \
gdb/function/caller_is.py \
gdb/function/strfns.py \
+ gdb/handler/__init__.py \
+ gdb/handler/android.py \
gdb/printer/__init__.py
@HAVE_PYTHON_TRUE@PYTHON_FILES = $(PYTHON_FILE_LIST)
diff --git a/gdb/python/lib/gdb/__init__.py b/gdb/python/lib/gdb/__init__.py
index bc47585378c..2f2bbb98569 100644
--- a/gdb/python/lib/gdb/__init__.py
+++ b/gdb/python/lib/gdb/__init__.py
@@ -152,7 +152,7 @@ PYTHONDIR = os.path.dirname(os.path.dirname(__file__))
# Packages to auto-load.
-packages = ["function", "command", "printer"]
+packages = ["function", "command", "printer", "handler"]
# pkgutil.iter_modules is not available prior to Python 2.6. Instead,
# manually iterate the list, collating the Python files in each module
diff --git a/gdb/python/lib/gdb/handler/__init__.py b/gdb/python/lib/gdb/handler/__init__.py
new file mode 100644
index 00000000000..d28abe3fc3f
--- /dev/null
+++ b/gdb/python/lib/gdb/handler/__init__.py
@@ -0,0 +1,14 @@
+# Copyright (C) 2026 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
diff --git a/gdb/python/lib/gdb/handler/android.py b/gdb/python/lib/gdb/handler/android.py
new file mode 100644
index 00000000000..2febf851dd5
--- /dev/null
+++ b/gdb/python/lib/gdb/handler/android.py
@@ -0,0 +1,43 @@
+# Copyright (C) 2026 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+# Missing objfile handler for Android.
+
+import gdb
+import gdb.missing_objfile
+
+
+class _AndroidHandler(gdb.missing_objfile.MissingObjfileHandler):
+ buildid_required = False
+
+ def __call__(self, pspace, buildid, filename):
+ elts = filename.split(".apk!/", maxsplit=1)
+ if len(elts) != 2:
+ return None
+ initial, member = elts
+ apk_fd = gdb.TargetFile(initial + ".apk")
+
+ import zipfile
+
+ apk_file = zipfile.ZipFile(apk_fd)
+ info = apk_file.getinfo(member)
+ member_fd = apk_file.open(info)
+
+ # Use the full filename here so the user can see what is going
+ # on.
+ return gdb.missing_objfile.BFDFile(member_fd, filename)
+
+
+gdb.missing_objfile.register_handler(None, _AndroidHandler("Android"))
--
2.56.0
prev parent reply other threads:[~2026-10-22 18:30 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 ` [PATCH RFC 3/6] Allow missing build-id when finding an objfile Tom Tromey
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 ` Tom Tromey [this message]
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-6-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