From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id +Eo2BC2n8GFmCwAAWB0awg (envelope-from ) for ; Tue, 25 Jan 2022 20:43:09 -0500 Received: by simark.ca (Postfix, from userid 112) id 0F0B71F3B6; Tue, 25 Jan 2022 20:43:09 -0500 (EST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-3.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.2 Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 070431EA69 for ; Tue, 25 Jan 2022 20:43:08 -0500 (EST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 8B6F2385380A for ; Wed, 26 Jan 2022 01:43:07 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8B6F2385380A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1643161387; bh=izEJzeyxHBmsxefPFbxdY4M+bGNG3goK1TMysVRubSk=; h=References:In-Reply-To:Date:Subject:To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=xLj14TeV3FwICTOTNk7mQEbksdBH/6V4CPbR3UCfZJ6mvCAc4S/ucggvL7weDoFK/ UkUFjMErA07duAICq+XgIkPy3CKXBDaCTekc17zjIeVu0b99Fe/MGDm9oE8WpqYV6/ dKtHYgbGkY2DCIJWk/cFSd7glCF/5v/QTPp6DyE8= Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id 85C2F3858C60 for ; Wed, 26 Jan 2022 01:42:48 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 85C2F3858C60 Received: from mail-qv1-f71.google.com (mail-qv1-f71.google.com [209.85.219.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-164-JpoZqJBVO9ikr49XH2d1Dw-1; Tue, 25 Jan 2022 20:42:46 -0500 X-MC-Unique: JpoZqJBVO9ikr49XH2d1Dw-1 Received: by mail-qv1-f71.google.com with SMTP id iw14-20020a0562140f2e00b004204be8b6baso19447126qvb.3 for ; Tue, 25 Jan 2022 17:42:46 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=izEJzeyxHBmsxefPFbxdY4M+bGNG3goK1TMysVRubSk=; b=4vQ66wOeXutLHuR6j/74U9AU9mpN7KZjwrz1PU6BWOowgijLTli/4wnXPL5TQsvhRl M8ODtgraThnn9R1Bm5mDDVthAw8LpfbGi0SyV5ePEKTKfmYbKCRg8RmDnChQmg59svJ2 7z8R/gVKmzWhDDJPbifOHysmeU8Cz/f/91sLrkc9SxVL8Lmq/TXX1kAJbK0WY1FA5QsN cKT8T8aKm11BlTUyi14hFu8Fht1sN0qEFTnzs8sGdIm7XEhuCQYCiNOVymYHSRpQSx/P T1YXyhNmBrUCK/FPttaAGGAha31JomfQPk50VwD3J37QvmpdZGc+HMEri1Q0gt/sCUo8 YDgw== X-Gm-Message-State: AOAM533C996mwlF2Io0rRenjqxmSSNEy/MGpTF5DzUMb1Fwos/K3Xb+v BV/fRG2E8Id8iJxFGA9YDsqm4AjhqUgBiav1KEg5VpUnsFHOTlIiYogFhT/ZhtPhxGd9eH3F2VZ jVoVTX9FiatAL50z3DYo/hiRT3IVo9tugzzXD X-Received: by 2002:a37:a3d6:: with SMTP id m205mr11094395qke.112.1643161365736; Tue, 25 Jan 2022 17:42:45 -0800 (PST) X-Google-Smtp-Source: ABdhPJwMY3nRZW5MYDwsbbdqKRlG2OIJjGDQCdPXswztZ4UahmoKZeLqTk8LxA3Z3sTwo2CeF0i1E5j5wO5KqcivuYw= X-Received: by 2002:a37:a3d6:: with SMTP id m205mr11094387qke.112.1643161365494; Tue, 25 Jan 2022 17:42:45 -0800 (PST) MIME-Version: 1.0 References: <500888d1-2d7d-5f55-2940-95ed5d962961@polymtl.ca> <20211117032807.719538-1-amerey@redhat.com> In-Reply-To: <20211117032807.719538-1-amerey@redhat.com> Date: Tue, 25 Jan 2022 20:42:34 -0500 Message-ID: Subject: Re: [PATCH 3/3] PR gdb/27570: missing support for debuginfod in core_target::build_file_mappings To: Aaron Merey X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="UTF-8" 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: , From: Aaron Merey via Gdb-patches Reply-To: Aaron Merey Cc: gdb-patches@sourceware.org, Tom Tromey , lsix@lancelotsix.com Errors-To: gdb-patches-bounces+public-inbox=simark.ca@sourceware.org Sender: "Gdb-patches" Ping Thanks, Aaron On Tue, Nov 16, 2021 at 10:28 PM Aaron Merey via Gdb-patches wrote: > > Hi Simon, > > I've fixed the issues you pointed out. The revised patch is below. > > Thanks, > Aaron > > From 357ffcc705057b4ed324cc39c2f5159693491fbe Mon Sep 17 00:00:00 2001 > From: Aaron Merey > Date: Tue, 16 Nov 2021 19:45:44 -0500 > Subject: [PATCH 3/3] PR gdb/27570: missing support for debuginfod in > core_target::build_file_mappings > > Add debuginfod support to core_target::build_file_mappings and > locate_exec_from_corefile_build_id to enable the downloading of > missing executables and shared libraries referenced in core files. > > Also add debuginfod support to solib_map_sections so that previously > downloaded shared libraries can be retrieved from the debuginfod > cache. > > When core file shared libraries are found locally, verify that > their build-ids match the corresponding build-ids found in the > core file. If there is a mismatch, attempt to query debuginfod > for the correct build and print a warning if unsuccessful: > > warning: Build-id of /lib64/libc.so.6 does not match core file. > > Also unset the DEBUGINFOD_URLS environment variable in gcore.in > to disable debuginfod when gcore invokes gdb. Debuginfo is not > needed for core file generation so debuginfod queries will slow > down gcore unnecessarily. > --- > gdb/corelow.c | 27 ++++++++++++ > gdb/debuginfod-support.c | 44 +++++++++++++++++++ > gdb/debuginfod-support.h | 17 +++++++ > gdb/gcore.in | 3 ++ > gdb/solib.c | 34 ++++++++++++++ > .../gdb.debuginfod/fetch_src_and_symbols.exp | 22 ++++++++++ > 6 files changed, 147 insertions(+) > > diff --git a/gdb/corelow.c b/gdb/corelow.c > index d1256a9e99b..8141f815e39 100644 > --- a/gdb/corelow.c > +++ b/gdb/corelow.c > @@ -46,6 +46,8 @@ > #include "gdbsupport/filestuff.h" > #include "build-id.h" > #include "gdbsupport/pathstuff.h" > +#include "gdbsupport/scoped_fd.h" > +#include "debuginfod-support.h" > #include > #include > #include "gdbcmd.h" > @@ -229,6 +231,11 @@ core_target::build_file_mappings () > canonical) pathname will be provided. */ > gdb::unique_xmalloc_ptr expanded_fname > = exec_file_find (filename, NULL); > + > + if (expanded_fname == nullptr && build_id != nullptr) > + debuginfod_exec_query (build_id->data, build_id->size, > + filename, &expanded_fname); > + > if (expanded_fname == nullptr) > { > m_core_unavailable_mappings.emplace_back (start, end - start); > @@ -410,6 +417,26 @@ locate_exec_from_corefile_build_id (bfd *abfd, int from_tty) > gdb_bfd_ref_ptr execbfd > = build_id_to_exec_bfd (build_id->size, build_id->data); > > + if (execbfd == nullptr) > + { > + /* Attempt to query debuginfod for the executable. */ > + gdb::unique_xmalloc_ptr execpath; > + scoped_fd fd = debuginfod_exec_query (build_id->data, build_id->size, > + abfd->filename, &execpath); > + > + if (fd.get () >= 0) > + { > + execbfd = gdb_bfd_open (execpath.get (), gnutarget); > + > + if (execbfd == nullptr) > + warning (_("File \"%s\" from debuginfod cannot be opened as bfd"), > + execpath.get ()); > + else if (!build_id_verify (execbfd.get (), build_id->size, > + build_id->data)) > + execbfd.reset (nullptr); > + } > + } > + > if (execbfd != nullptr) > { > exec_file_attach (bfd_get_filename (execbfd.get ()), from_tty); > diff --git a/gdb/debuginfod-support.c b/gdb/debuginfod-support.c > index 2e1837da949..c4c593148b6 100644 > --- a/gdb/debuginfod-support.c > +++ b/gdb/debuginfod-support.c > @@ -68,6 +68,15 @@ debuginfod_debuginfo_query (const unsigned char *build_id, > return scoped_fd (-ENOSYS); > } > > +scoped_fd > +debuginfod_exec_query (const unsigned char *build_id, > + int build_id_len, > + const char *filename, > + gdb::unique_xmalloc_ptr *destname) > +{ > + return scoped_fd (-ENOSYS); > +} > + > #define NO_IMPL _("Support for debuginfod is not compiled into GDB.") > > #else > @@ -256,6 +265,41 @@ debuginfod_debuginfo_query (const unsigned char *build_id, > > return fd; > } > + > +/* See debuginfod-support.h */ > + > +scoped_fd > +debuginfod_exec_query (const unsigned char *build_id, > + int build_id_len, > + const char *filename, > + gdb::unique_xmalloc_ptr *destname) > +{ > + if (!debuginfod_is_enabled ()) > + return scoped_fd (-ENOSYS); > + > + debuginfod_client *c = get_debuginfod_client (); > + > + if (c == nullptr) > + return scoped_fd (-ENOMEM); > + > + char *dname = nullptr; > + user_data data ("executable for", filename); > + > + debuginfod_set_user_data (c, &data); > + scoped_fd fd (debuginfod_find_executable (c, build_id, build_id_len, &dname)); > + debuginfod_set_user_data (c, nullptr); > + > + if (debuginfod_verbose > 0 && fd.get () < 0 && fd.get () != -ENOENT) > + printf_filtered (_("Download failed: %s. " \ > + "Continuing without executable for %ps.\n"), > + safe_strerror (-fd.get ()), > + styled_string (file_name_style.style (), filename)); > + > + if (fd.get () >= 0) > + destname->reset (dname); > + > + return fd; > +} > #endif > > /* Set callback for "set debuginfod enabled". */ > diff --git a/gdb/debuginfod-support.h b/gdb/debuginfod-support.h > index 5e5aab56e74..7815a2f6ede 100644 > --- a/gdb/debuginfod-support.h > +++ b/gdb/debuginfod-support.h > @@ -61,4 +61,21 @@ debuginfod_debuginfo_query (const unsigned char *build_id, > const char *filename, > gdb::unique_xmalloc_ptr *destname); > > +/* Query debuginfod servers for an executable file with 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 executable. > + It is used for printing messages to the user. > + > + If the file is successfully retrieved, its path on the local machine > + is stored in DESTNAME. If GDB is not built with debuginfod, this > + function returns -ENOSYS. */ > + > +extern scoped_fd debuginfod_exec_query (const unsigned char *build_id, > + int build_id_len, > + const char *filename, > + gdb::unique_xmalloc_ptr > + *destname); > #endif /* DEBUGINFOD_SUPPORT_H */ > diff --git a/gdb/gcore.in b/gdb/gcore.in > index 24354a79e27..25b24c3cd3d 100644 > --- a/gdb/gcore.in > +++ b/gdb/gcore.in > @@ -89,6 +89,9 @@ if [ ! -f "$binary_path/@GDB_TRANSFORM_NAME@" ]; then > exit 1 > fi > > +# Prevent unnecessary debuginfod queries during core file generation. > +unset DEBUGINFOD_URLS > + > # Initialise return code. > rc=0 > > diff --git a/gdb/solib.c b/gdb/solib.c > index c0beea19d7b..87a3fc0c462 100644 > --- a/gdb/solib.c > +++ b/gdb/solib.c > @@ -49,6 +49,8 @@ > #include "filesystem.h" > #include "gdb_bfd.h" > #include "gdbsupport/filestuff.h" > +#include "gdbsupport/scoped_fd.h" > +#include "debuginfod-support.h" > #include "source.h" > #include "cli/cli-style.h" > > @@ -539,6 +541,38 @@ solib_map_sections (struct so_list *so) > > gdb::unique_xmalloc_ptr filename (tilde_expand (so->so_name)); > gdb_bfd_ref_ptr abfd (ops->bfd_open (filename.get ())); > + const char *build_id_hexstr = > + current_program_space->get_cbfd_soname_build_id (so->so_name); > + > + /* If we already know the build-id of this solib from a core file, > + verify it matches abfd's build-id. If there is a mismatch or > + the solib wasn't found, attempt to query debuginfod for > + the correct solib. */ > + if (build_id_hexstr != nullptr) > + { > + bool mismatch = false; > + > + if (abfd != nullptr && abfd->build_id != nullptr) > + { > + std::string build_id = build_id_to_string (abfd->build_id); > + > + if (build_id != build_id_hexstr) > + mismatch = true; > + } > + > + if (abfd == nullptr || mismatch) > + { > + scoped_fd fd = debuginfod_exec_query ((const unsigned char*) > + build_id_hexstr, > + 0, so->so_name, &filename); > + > + if (fd.get () >= 0) > + abfd = ops->bfd_open (filename.get ()); > + else if (mismatch) > + warning (_("Build-id of %ps does not match core file."), > + styled_string (file_name_style.style (), filename.get ())); > + } > + } > > if (abfd == NULL) > return 0; > diff --git a/gdb/testsuite/gdb.debuginfod/fetch_src_and_symbols.exp b/gdb/testsuite/gdb.debuginfod/fetch_src_and_symbols.exp > index 757bd201b17..cfe2ae7f7da 100644 > --- a/gdb/testsuite/gdb.debuginfod/fetch_src_and_symbols.exp > +++ b/gdb/testsuite/gdb.debuginfod/fetch_src_and_symbols.exp > @@ -63,6 +63,11 @@ if { [gdb_compile "$sourcetmp" "$binfile" executable {debug}] != "" } { > return -1 > } > > +if { [gdb_compile "$sourcetmp" "${binfile}2" executable {debug}] != "" } { > + fail "compile" > + return -1 > +} > + > # Write some assembly that just has a .gnu_debugaltlink section. > # Copied from testsuite/gdb.dwarf2/dwzbuildid.exp. > proc write_just_debugaltlink {filename dwzname buildid} { > @@ -114,6 +119,8 @@ proc write_dwarf_file {filename buildid {value 99}} { > } > } > > +set corefile [standard_output_file "corefile"] > + > proc no_url { } { > global binfile outputdir debugdir > > @@ -167,6 +174,16 @@ proc no_url { } { > gdb_test "file ${binfile}_alt.o" \ > ".*could not find '.gnu_debugaltlink'.*" \ > "file [file tail ${binfile}_alt.o]" > + > + # Generate a core file and test that gdb cannot find the executable > + clean_restart ${binfile}2 > + gdb_test "start" "Temporary breakpoint.*" > + gdb_test "generate-core-file $::corefile" "Saved corefile $::corefile" \ > + "file [file tail $::corefile] gen" > + file rename -force ${binfile}2 $debugdir > + > + clean_restart > + gdb_test "core $::corefile" ".*in ?? ().*" "file [file tail $::corefile]" > } > > proc local_url { } { > @@ -234,6 +251,11 @@ proc local_url { } { > gdb_test "br main" "Breakpoint 1 at.*file.*" > gdb_test "l" ".*This program is distributed in the hope.*" > > + # gdb should now find the executable file > + clean_restart > + gdb_test "core $::corefile" ".*return 0.*" "file [file tail $::corefile]" \ > + "Enable debuginfod?.*" "y" > + > # gdb should now find the debugaltlink file > clean_restart > gdb_test "file ${binfile}_alt.o" \ > -- > 2.31.1 >