From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id 4cvbJ/RV2mrvWAwAWB0awg (envelope-from ) for ; Thu, 22 Oct 2026 14:29:08 -0400 Authentication-Results: simark.ca; dkim=pass (2048-bit key; secure) header.d=adacore.com header.i=@adacore.com header.a=rsa-sha256 header.s=google header.b=C5N8j9Ft; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 9E70A1E007; Thu, 22 Oct 2026 14:29:08 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-5.4 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham autolearn_force=no version=4.0.1 Received: from vm01.sourceware.org (vm01.sourceware.org [IPv6:2620:52:6:3111::32]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 7CAD81E007 for ; Thu, 22 Oct 2026 14:29:07 -0400 (EDT) Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 229144BA7980 for ; Thu, 22 Oct 2026 18:29:07 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 229144BA7980 Authentication-Results: sourceware.org; dkim=pass (2048-bit key, secure) header.d=adacore.com header.i=@adacore.com header.a=rsa-sha256 header.s=google header.b=C5N8j9Ft Received: from mail-ot1-x335.google.com (mail-ot1-x335.google.com [IPv6:2607:f8b0:4864:20::335]) by sourceware.org (Postfix) with ESMTPS id 571A74BA2E16 for ; Thu, 22 Oct 2026 18:28:23 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 571A74BA2E16 Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=adacore.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=adacore.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 571A74BA2E16 Authentication-Results: sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::335 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1792693703; cv=none; b=NIuv8/hSB7vXionQ3j+yaY0xnORw4EjWLdmCBHYk5yGB0JENggWDit1JQVy0q12Zo3C/5/QcEEdlWDGOvEHf/Nk4KqURSM56wcbTuRhmVFIcmb5BEEVc06g7sZ5iOkUXjVUdY/X+lWQrMxdt7MryZfNEJMnEAvztyTjwDNHPxlA= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1792693703; c=relaxed/simple; bh=Q8d2vXztxwlCNqaXyXhU2Q/p5R3abJGLAqUwvWVQEhs=; h=DKIM-Signature:From:Date:Subject:MIME-Version:Message-Id:To; b=QpXFPM+zrHhY5Gd3SvMM3V7jASt/VH9lsXsPyZo0ECKoId31DtfzKXgDA8M1hgW7lxomDakg+5g24kPaJyVVyyxC/Ab8BF6L8D81H9XuuI7J79ODu2dsoLZDtQFUa2IJMydcp7qYQk9TaYL3Er2gB0HHGAiwyOq0bJbQ6Ud7a40= ARC-Authentication-Results: i=1; sourceware.org; dkim=pass (2048-bit key, secure) header.d=adacore.com header.i=@adacore.com header.a=rsa-sha256 header.s=google header.b=C5N8j9Ft DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 571A74BA2E16 Received: by mail-ot1-x335.google.com with SMTP id 46e09a7af769-8256106635eso33227a34.0 for ; Thu, 22 Oct 2026 11:28:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; t=1792693702; x=1793298502; darn=sourceware.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=MPbXUWF3tHCFJwGV5uWnRM4z6ofLo/Mtd7cyLnxl4yk=; b=C5N8j9FtAQA+q1Fda427czspakhg9XALhjZZuJLOv1lXvXJdEY07duoz3ru4j0Yvev LdKSUiKjznceoWncpSBDQdYoRLEGaKp25KHSbNRd2Rtn3rd2CdqR7/11SQBfK5+bPfcc k1Vys/3FaPx1Myiucyr02wse190Hwm4F+pmCYJCAkPvPun9BQlgECgS//GAx7j7xP46D /wYodN/09W/P/5l2gm7s+aV6ecewZJBgtEf4CqGHcXGGm+GhobxzuHiWTNJsd7REu8Kn brEabocaG2Nc+fa3P/6cRp3S6zDjXKPdErJEszNitpLsvW30GRDcXjhlI5legdZYREFB cLwA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1792693702; x=1793298502; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=MPbXUWF3tHCFJwGV5uWnRM4z6ofLo/Mtd7cyLnxl4yk=; b=yKz5SSepxFQrCTgRqfwIR4kGWQA5BU3TrIVX8d2UAOpEgQx2nT881Ld+g97br56KUn qE8B+RcTvPqiE+EuvK1kch3zP33sxOoopQF1EfAd5+YDbhbIsCDuTKMVGUh4Cw+4L4PE fuDPZE6hctOc4HCGPh2gLIKVfPklqwPeEQZkn9o2eqmEgfsWqxWu/5Ck4AUMorkh/4rw NLrLpZzCDFqh20OPQaXuVwS/gf1WfKbAeX06k5B+90twcRYmrl3wjTvfOAaniigk/H09 Ecp+GFH9m+C9bZeMgwT90uG07b/LD3kL21ejpYhgrE+VfqCbXaYKkblNMpg+3kqQWupv kAsA== X-Gm-Message-State: AFq9FYLtFSa5KhIOHTpmiatNsUYlUYBnxu0Ib01p3O9K3lllleWevri9 bhFtHpT7JO+voyMi5Fc+55fo+1csPYD/BP6SxdmpYIC9JcCqlc4vEM70PqvvEU3MRwk6tw5wSka 9Kngb3A== X-Gm-Gg: AYBFou3LaiG0Mjt+zT69o01anxJ8L39RXmTMjyMwC5SX3ooDlR3rEmx2lN6o/jdl01o /oXp8kiKu9d/CVBXhXisFGKr9rzDWW0PkeJISWbM6xtRylZ2hczGSipSRF+OlfLdKymA+nbjWgS 97CVR9k6p6I/H2eW2H9vMhlDFcWX0JxRb6Lv2apsyGLj6yErkVp7tLI2N5dl58R9/yJY2YPj2pn ZjQBMkFiLuJk7b8bvPOa1NoIhgpbTwTBHu4dPXtRey+1nNccFZrbn7I1UIJFRMowQ446/yIgfUD Q995ELTeaDH3s1F+3M0hL0JHv9iSWDAT8lOjeoxugkcux7dWseEq8eKUleq2Q3/0W1kPgHz2P42 ziHkZrPzFOq4YYx7xztl81u/Bu5dGUHwnYh9r8pDVCLLTGjDtzcYEfaw31QCnqzRBYM2atW4EMH PFPKBI2bHZuFlfV0LqkIt3LLn8NhdaOXlFxxEFQo6vESMcJRk6ivSPjNPCS7aZ3KJltmXJufGdF KlfhfcLQHtPxLteGMkFDo//IuejQW5PivoDyQUUEWT1BI0wwCLfqa6NceGW0WL6RieW41knYNXA W2L5801E+1PdLQ== X-Received: by 2002:a05:6830:6d11:b0:7eb:9464:ac2e with SMTP id 46e09a7af769-84d07e077c8mr5353056a34.11.1792693702560; Thu, 22 Oct 2026 11:28:22 -0700 (PDT) Received: from [192.168.0.26] (97-122-110-129.hlrn.qwest.net. [97.122.110.129]) by smtp.gmail.com with ESMTPSA id 46e09a7af769-84f784f3c50sm419557a34.21.2026.10.22.11.28.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Oct 2026 11:28:22 -0700 (PDT) From: Tom Tromey Date: Thu, 22 Oct 2026 12:28:14 -0600 Subject: [PATCH RFC 4/6] Allow missing objfile handler to return a file MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20261022-android-apk-file-v1-4-8444bb5f832a@adacore.com> References: <20261022-android-apk-file-v1-0-8444bb5f832a@adacore.com> In-Reply-To: <20261022-android-apk-file-v1-0-8444bb5f832a@adacore.com> To: gdb-patches@sourceware.org Cc: Tom Tromey X-Mailer: b4 0.15.2 X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces~public-inbox=simark.ca@sourceware.org This patch changes the missing objfile handler code so that a handler can return a "file". To be pedantic, this returned object isn't a Python file-like object but instead a small shim; see missing_objfile.BFDFile. --- gdb/build-id.c | 4 +++- gdb/extension.c | 2 +- gdb/extension.h | 21 +++++++++++++++++++++ gdb/python/lib/gdb/__init__.py | 2 ++ gdb/python/lib/gdb/missing_objfile.py | 24 ++++++++++++++++++++++++ gdb/python/python.c | 28 ++++++++++++++++++---------- gdb/symfile-debug.c | 20 +++++++++++--------- 7 files changed, 80 insertions(+), 21 deletions(-) diff --git a/gdb/build-id.c b/gdb/build-id.c index 123d87e519c..550880d0d9c 100644 --- a/gdb/build-id.c +++ b/gdb/build-id.c @@ -403,7 +403,9 @@ find_objfile_by_build_id (program_space *pspace, ext_lang_missing_file_result ext_result = ext_lang_find_objfile_from_buildid (pspace, build_id, expected_filename); - if (!ext_result.filename ().empty ()) + if (ext_result.bfd () != nullptr) + return ext_result.bfd (); + else if (!ext_result.filename ().empty ()) { /* The extension identified the file for us. */ abfd = gdb_bfd_open (ext_result.filename ().c_str (), gnutarget); diff --git a/gdb/extension.c b/gdb/extension.c index de3b3eb69a5..a531d87fd0d 100644 --- a/gdb/extension.c +++ b/gdb/extension.c @@ -1103,7 +1103,7 @@ ext_lang_find_objfile_from_buildid (program_space *pspace, ext_lang_missing_file_result result = extlang->ops->find_objfile_from_buildid (extlang, pspace, build_id, filename); - if (!result.filename ().empty () || result.try_again ()) + if (result.valid ()) return result; } diff --git a/gdb/extension.h b/gdb/extension.h index 360c788a41e..4437169215b 100644 --- a/gdb/extension.h +++ b/gdb/extension.h @@ -24,6 +24,7 @@ #include "gdbsupport/array-view.h" #include #include "gdbtypes.h" +#include "gdb_bfd.h" struct breakpoint; struct command_line; @@ -385,6 +386,11 @@ struct ext_lang_missing_file_result : m_filename (std::move (filename)) { /* Nothing. */ } + /* Use BFD for the missing debug info. */ + ext_lang_missing_file_result (gdb_bfd_ref_ptr &&abfd) + : m_bfd (std::move (abfd)) + { /* Nothing. */ } + /* The filename where GDB can find the missing debuginfo. This is empty if the extension didn't suggest a file that can be used. */ const std::string & @@ -393,6 +399,13 @@ struct ext_lang_missing_file_result return m_filename; } + /* The BFD where GDB can find the missing debuginfo. This is empty + if the extension didn't open a file that can be used. */ + const gdb_bfd_ref_ptr &bfd () const + { + return m_bfd; + } + /* Returns true if GDB should look again for the debug information. */ const bool try_again () const @@ -400,10 +413,18 @@ struct ext_lang_missing_file_result return m_try_again; } + bool valid () const + { + return m_try_again || !m_filename.empty () || m_bfd != nullptr; + } + private: /* The filename where the missing debuginfo can now be found. */ std::string m_filename; + /* The BFD where the missing debuginfo can now be found. */ + gdb_bfd_ref_ptr m_bfd; + /* When true GDB will search again for the debuginfo using its standard techniques. When false GDB will not search again. */ bool m_try_again = false; diff --git a/gdb/python/lib/gdb/__init__.py b/gdb/python/lib/gdb/__init__.py index f16e0a66c5b..bc47585378c 100644 --- a/gdb/python/lib/gdb/__init__.py +++ b/gdb/python/lib/gdb/__init__.py @@ -402,6 +402,8 @@ def _handle_missing_objfile(pspace, buildid, filename): installed there then GDB will not find it. A string: This is the filename of a file containing the missing objfile. + A BFD: A wrapper for a file implementing the BFD protocol. + See gdb.missing_objfile.BFDFile. """ # Delay this as long as possible. diff --git a/gdb/python/lib/gdb/missing_objfile.py b/gdb/python/lib/gdb/missing_objfile.py index fe45a418c6d..f19f6395d4d 100644 --- a/gdb/python/lib/gdb/missing_objfile.py +++ b/gdb/python/lib/gdb/missing_objfile.py @@ -17,6 +17,8 @@ MissingObjfileHandler base class, and register_handler function. """ +import os + import gdb from gdb.missing_files import MissingFileHandler @@ -66,6 +68,28 @@ class MissingObjfileHandler(MissingFileHandler): raise NotImplementedError("MissingObjfileHandler.__call__()") +class BFDFile: + def __init__(self, fd, filename): + assert fd.seekable() + self._fd = fd + self._filename = filename + fd.seek(0, os.SEEK_END) + self._size = fd.tell() + + def filename(self): + return self._filename + + def size(self): + return self._size + + def read(self, offset, size): + self._fd.seek(offset) + return self._fd.read(size) + + def close(self): + self._fd.close() + + def register_handler(locus, handler, replace=False): """See gdb.missing_files.register_handler.""" gdb.missing_files.register_handler("objfile", locus, handler, replace) diff --git a/gdb/python/python.c b/gdb/python/python.c index 06ad0876527..3f7fdc6b186 100644 --- a/gdb/python/python.c +++ b/gdb/python/python.c @@ -2022,24 +2022,32 @@ gdbpy_find_objfile_from_buildid (const struct extension_language_defn *extlang, return ext_lang_missing_file_result (try_again); } - if (!gdbpy_is_string (pyo_execute_ret.get ())) + if (gdbpy_is_string (pyo_execute_ret.get ())) { - PyErr_SetString (PyExc_ValueError, - "return value from _find_objfile_by_buildid should " - "be None, a bool, or a str"); - gdbpy_print_stack (); - return {}; + gdb::unique_xmalloc_ptr filename + = python_string_to_host_string (pyo_execute_ret.get ()); + if (filename == nullptr) + { + gdbpy_print_stack (); + return {}; + } + + return ext_lang_missing_file_result (std::string (filename.get ())); } - gdb::unique_xmalloc_ptr filename - = python_string_to_host_string (pyo_execute_ret.get ()); - if (filename == nullptr) + gdb_bfd_ref_ptr the_bfd = open_bfd_from_python (std::move (pyo_execute_ret)); + if (the_bfd == nullptr) { + if (!PyErr_Occurred ()) + PyErr_SetString (PyExc_ValueError, + "return value from _find_objfile_by_buildid should " + "be None, a bool, a str, or a " + "gdb.missing_objfile.BFDFile-like object"); gdbpy_print_stack (); return {}; } - return ext_lang_missing_file_result (std::string (filename.get ())); + return ext_lang_missing_file_result (std::move (the_bfd)); } /* Compute the list of active python type printers and store them in diff --git a/gdb/symfile-debug.c b/gdb/symfile-debug.c index 2432a709ddf..61914c09a94 100644 --- a/gdb/symfile-debug.c +++ b/gdb/symfile-debug.c @@ -659,25 +659,27 @@ objfile::find_and_add_separate_symbol_file (symfile_add_flags symfile_flags) ext_lang_missing_file_result ext_result = ext_lang_handle_missing_debuginfo (this); - if (!ext_result.filename ().empty ()) + if (ext_result.bfd () != nullptr) + debug_bfd = ext_result.bfd (); + else if (!ext_result.filename ().empty ()) { /* Extension found a suitable debug file for us. */ debug_bfd = symfile_bfd_open_no_error (ext_result.filename ().c_str ()); - - if (debug_bfd != nullptr) - { - symbol_file_add_separate (debug_bfd, - ext_result.filename ().c_str (), - symfile_flags, this); - has_dwarf2 = true; - } } else if (ext_result.try_again ()) { max_attempts = 2; continue; } + + if (debug_bfd != nullptr) + { + symbol_file_add_separate (debug_bfd, + bfd_get_filename (debug_bfd.get ()), + symfile_flags, this); + has_dwarf2 = true; + } } /* If we still have not got a separate debug symbol file, then -- 2.56.0