From patchwork Wed Aug 16 04:42:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aaron Merey X-Patchwork-Id: 74186 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id BB17D3857732 for ; Wed, 16 Aug 2023 04:43:53 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org BB17D3857732 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1692161033; bh=KknCWywSMVNTFW3j1KL43si/EvaAvq3lyq9Y4SiPqNw=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=SFdW5jOep1djawf7qBSX4Cue6xHJRZ6JnRq37ZzIVhWIJSozpZRY402upTRtyYQvP egaleO6SXwenRrIwt6dUlNaMecwcZ9wWQZnJfouWre3JO6SefUEABnroo6GYXZPLdd 2D/Xmse1+TetBj7ilwkiSAE1OhcBNT3ivKXeDPAA= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id 79C893856DC6 for ; Wed, 16 Aug 2023 04:43:27 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 79C893856DC6 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-527-p1K3Dgg3NHKR8GL1zV05xA-1; Wed, 16 Aug 2023 00:43:25 -0400 X-MC-Unique: p1K3Dgg3NHKR8GL1zV05xA-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 0B91C8DC660 for ; Wed, 16 Aug 2023 04:43:25 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.22.8.113]) by smtp.corp.redhat.com (Postfix) with ESMTP id B03072026D4B; Wed, 16 Aug 2023 04:43:24 +0000 (UTC) To: gdb-patches@sourceware.org Cc: aburgess@redhat.com, Aaron Merey Subject: [PATCH 2/7 v3] gdb/debuginfod: Add debuginfod_section_query Date: Wed, 16 Aug 2023 00:42:53 -0400 Message-ID: <20230816044259.2675531-3-amerey@redhat.com> In-Reply-To: <20230816044259.2675531-1-amerey@redhat.com> References: <20230816044259.2675531-1-amerey@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.4 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-11.3 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Aaron Merey via Gdb-patches From: Aaron Merey Reply-To: Aaron Merey Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" v2: https://sourceware.org/pipermail/gdb-patches/2023-June/199985.html v3 has config/debuginfod.m4 changes moved into a separate patch. Commit message: Add new function debuginfod_section_query. This function queries debuginfod servers for an individual ELF/DWARF section associated with a given build-id. --- gdb/debuginfod-support.c | 60 ++++++++++++++++++++++++++++++++++++++++ gdb/debuginfod-support.h | 24 ++++++++++++++++ 2 files changed, 84 insertions(+) diff --git a/gdb/debuginfod-support.c b/gdb/debuginfod-support.c index a41a4c95785..33bb9d9b7bc 100644 --- a/gdb/debuginfod-support.c +++ b/gdb/debuginfod-support.c @@ -80,6 +80,15 @@ debuginfod_exec_query (const unsigned char *build_id, return scoped_fd (-ENOSYS); } +scoped_fd +debuginfod_section_query (const unsigned char *build_id, + int build_id_len, + const char *filename, + const char *section_name, + gdb::unique_xmalloc_ptr *destname) +{ + return scoped_fd (-ENOSYS); +} #define NO_IMPL _("Support for debuginfod is not compiled into GDB.") #else @@ -412,6 +421,57 @@ debuginfod_exec_query (const unsigned char *build_id, return fd; } + +/* See debuginfod-support.h */ + +scoped_fd +debuginfod_section_query (const unsigned char *build_id, + int build_id_len, + const char *filename, + const char *section_name, + gdb::unique_xmalloc_ptr *destname) +{ +#if !defined (HAVE_LIBDEBUGINFOD_FIND_SECTION) + return scoped_fd (-ENOSYS); +#else + + if (!debuginfod_is_enabled ()) + return scoped_fd (-ENOSYS); + + debuginfod_client *c = get_debuginfod_client (); + + if (c == nullptr) + return scoped_fd (-ENOMEM); + + char *dname = nullptr; + std::string desc = std::string ("section ") + section_name + " for"; + scoped_fd fd; + gdb::optional term_state; + + { + user_data data (desc.c_str (), filename); + debuginfod_set_user_data (c, &data); + if (target_supports_terminal_ours ()) + { + term_state.emplace (); + target_terminal::ours (); + } + + fd = scoped_fd (debuginfod_find_section (c, build_id, build_id_len, + section_name, &dname)); + debuginfod_set_user_data (c, nullptr); + } + + print_outcome (fd.get (), desc.c_str (), filename); + gdb_assert (destname != nullptr); + + if (fd.get () >= 0) + destname->reset (dname); + + return fd; +#endif /* HAVE_LIBDEBUGINFOD_FIND_SECTION */ +} + #endif /* Set callback for "set debuginfod enabled". */ diff --git a/gdb/debuginfod-support.h b/gdb/debuginfod-support.h index 633600a79da..9701e3b4685 100644 --- a/gdb/debuginfod-support.h +++ b/gdb/debuginfod-support.h @@ -81,4 +81,28 @@ extern scoped_fd debuginfod_exec_query (const unsigned char *build_id, const char *filename, gdb::unique_xmalloc_ptr *destname); + +/* Query debuginfod servers for the binary contents of a ELF/DWARF section + from a file matching BUILD_ID. BUILD_ID can be given as a binary blob + or a null-terminated string. If given as a binary blob, BUILD_ID_LEN + should be the number of bytes. If given as a null-terminated string, + BUILD_ID_LEN should be 0. + + FILENAME should be the name or path associated with the file matching + BUILD_ID. It is used for printing messages to the user. + + SECTION_NAME should be the name of an ELF/DWARF section. + + If the file is successfully retrieved, return a file descriptor and store + the file's local path in DESTNAME. If unsuccessful, print an error message + and return a negative errno. If GDB is not built with debuginfod or + libdebuginfod does not support section queries, this function returns + -ENOSYS. */ + +extern scoped_fd debuginfod_section_query (const unsigned char *build_id, + int build_id_len, + const char *filename, + const char *section_name, + gdb::unique_xmalloc_ptr + *destname); #endif /* DEBUGINFOD_SUPPORT_H */