From patchwork Wed Oct 18 10:53:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Burgess X-Patchwork-Id: 78083 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 75CD8387545E for ; Wed, 18 Oct 2023 10:54:00 +0000 (GMT) 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.133.124]) by sourceware.org (Postfix) with ESMTPS id AC95F3870C35 for ; Wed, 18 Oct 2023 10:53:44 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org AC95F3870C35 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org AC95F3870C35 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697626426; cv=none; b=GtwMQxQ3PQdUR07OqRbeCBxvTBzNS0TWVWzwHrgZ5MYw/w33fWK73DjzE3tGXQIaZyY1mIrG/LATPUN+em8ByGckntlMO+EnydNxGl861gc4Gifv9mUe3Nuxd9JB7XDNN6VqAkWe3d0zWI4gXDlSy5Yp0fhfTbjRCuW+c6Wo8Pw= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697626426; c=relaxed/simple; bh=7THTah0Dz9/lxzU4Pop07MkMjWt55gHH2yboe6SDs2g=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=KL8gwZbDgOKFK/dTWcEPIOzOWP13tbjuzSHjRQEDSWMAtaUWxsir+oiJp5+Z/Lq6KQaPf7LReDq3pNAu15pYrUuOgOatz/U0JgQMu0XyVXIKFrdkYv8ar0bsp6TLqggFmDD8LPZlg2ghHBy6KYoNSZJzqtvkt4GQzvzP4PsmY4w= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1697626424; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=OomHNEc3YdhSiuttr6A9SCDWgkRJv4MmHFSzvqAWfQQ=; b=PlNZXvncH1yjOmniXFkJPYbyDcVSeMFZnu/Kq/sg5vOgFd7sdCkmLOJh1MMHSwBCT2aYIB MPx9JrDBRSDMONFav70Q2AN8KpNOdpqhEEhqsBST2a/0l2/MkuK6yUxwCvD0bOk42vGE3E zbMWv6FigkZFJjekb/yG8ni2QYG2WAM= Received: from mail-qt1-f197.google.com (mail-qt1-f197.google.com [209.85.160.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-108-QTPynY7-M0CyMR6CMpYaig-1; Wed, 18 Oct 2023 06:53:33 -0400 X-MC-Unique: QTPynY7-M0CyMR6CMpYaig-1 Received: by mail-qt1-f197.google.com with SMTP id d75a77b69052e-417fd6a8575so75421941cf.2 for ; Wed, 18 Oct 2023 03:53:33 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697626412; x=1698231212; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=NzyeQdCxpajvfNa7brjBPNkgbKMePeAolljkTq2yEBI=; b=E38Ju3lpxfvJZo2mf1OjhkWlKhV3INB8KJgFpqXKkq8+sshgRLYV0Qn90aSNlaAdda yDWVCev96KxbbI+DSsiBRqs06ePdxxJ1d1uHEej0DRiT8w7ftlIOhG9bDvqcBLR1gkio TkkBUHougNb3W6BylW7mbJI3TjdXMVZl5S3hiqg3+Rbl3vdvWBhPw/aFWkQmloWJYQnx /j8Pj4DlBGuym3Fw9SvAvQSkRftppyLc15QlCtJDHntklQH/RMzjZ3Bu9UcJu9Epc7Hh yGNsuS7XJ69+VX+obUQW545bzB88URqPWylhT5ylZViVcIFCkUPoRpIA17rvXq1QMeSg If6Q== X-Gm-Message-State: AOJu0YxE4Q8cUXYnC/lKP2I+b3cK73yrJkX2iZF+5l/dZy1TeaNo+ftN IwSHrA5dhH8/tCbpwwBvjvbJMqkQOfIT+bE6n5a4e/FENXz1bitqvng7E4MVDrDE0b293pSvDCj 14o/5VcxIYnvjosEtiohn2UTdi87/kMTN663Z3nQpIJPLKY4X7A1/3LA6TCt88I4dY6MVOdeKCb B33o5Ygg== X-Received: by 2002:ad4:5e8e:0:b0:66d:9d6:633a with SMTP id jl14-20020ad45e8e000000b0066d09d6633amr5323473qvb.33.1697626412569; Wed, 18 Oct 2023 03:53:32 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFbKVuIwTmQW7h7X2WIxvEIFzikrRjN6KthIYl7pOtCp4kn1/5Pvk2gHAYcrijoXPjm6gtt0g== X-Received: by 2002:ad4:5e8e:0:b0:66d:9d6:633a with SMTP id jl14-20020ad45e8e000000b0066d09d6633amr5323457qvb.33.1697626412129; Wed, 18 Oct 2023 03:53:32 -0700 (PDT) Received: from localhost ([31.111.84.209]) by smtp.gmail.com with ESMTPSA id d14-20020a0cfe8e000000b006616fbcc077sm1259377qvs.129.2023.10.18.03.53.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Oct 2023 03:53:31 -0700 (PDT) From: Andrew Burgess To: gdb-patches@sourceware.org Cc: Andrew Burgess Subject: [PATCH 2/5] gdb: merge debug symbol file lookup code from coffread & elfread paths Date: Wed, 18 Oct 2023 11:53:20 +0100 Message-Id: <07d050dec424c75095135c8a4836f24e3d713a32.1697626088.git.aburgess@redhat.com> X-Mailer: git-send-email 2.25.4 In-Reply-To: References: MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-11.5 required=5.0 tests=BAYES_00, DKIM_INVALID, DKIM_SIGNED, GIT_PATCH_0, KAM_DMARC_NONE, KAM_DMARC_STATUS, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, 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.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org This commit merges the code that looks for and loads the separate debug symbol files from coffread.c and elfread.c. The factored out code is moved into a new objfile::find_and_add_separate_symbol_file() method. For the elfread.c path there should be no user visible changes after this commit. For the coffread.c path GDB will now attempt to perform a debuginfod lookup for the missing debug information, assuming that GDB can find a build-id in the COFF file. I don't know if COFF files can include a build-id, but I the existing coffread.c code already includes a call to find_separate_debug_file_by_build-id, so I know that it is at least OK for GDB to ask a COFF file for a build-id. If the COFF file doesn't include a build-id then the debuginfod lookup code will not trigger and the new code is harmless. If the COFF file does include a build-id, then we're going to end up asking debuginfod for the debug file. As build-ids should be unique, this should be harmless, even if debuginfod doesn't contain any suitable debug data, it just costs us one debuginfod lookup, so I'm not too worried about this for now. I don't have access to a COFF target right now, so beyond compiling it, the coffread.c changes are completely untested. --- gdb/coffread.c | 24 ++--------------- gdb/elfread.c | 57 +++------------------------------------ gdb/objfiles.h | 10 +++++++ gdb/symfile-debug.c | 66 +++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 81 insertions(+), 76 deletions(-) diff --git a/gdb/coffread.c b/gdb/coffread.c index e1415d6b258..5898b3a8e08 100644 --- a/gdb/coffread.c +++ b/gdb/coffread.c @@ -40,8 +40,6 @@ #include "coff-pe-read.h" -#include "build-id.h" - /* The objfile we are currently reading. */ static struct objfile *coffread_objfile; @@ -729,26 +727,8 @@ coff_symfile_read (struct objfile *objfile, symfile_add_flags symfile_flags) && objfile->separate_debug_objfile == NULL && objfile->separate_debug_objfile_backlink == NULL) { - deferred_warnings warnings; - std::string debugfile - = find_separate_debug_file_by_buildid (objfile, &warnings); - - if (debugfile.empty ()) - debugfile - = find_separate_debug_file_by_debuglink (objfile, &warnings); - - if (!debugfile.empty ()) - { - gdb_bfd_ref_ptr debug_bfd (symfile_bfd_open (debugfile.c_str ())); - - symbol_file_add_separate (debug_bfd, debugfile.c_str (), - symfile_flags, objfile); - } - /* If all the methods to collect the debuginfo failed, print any - warnings that were collected, this is a no-op if there are no - warnings. */ - if (debugfile.empty ()) - warnings.emit (); + if (objfile->find_and_add_separate_symbol_file (symfile_flags)) + gdb_assert (objfile->separate_debug_objfile != nullptr); } } diff --git a/gdb/elfread.c b/gdb/elfread.c index 7900dfbc388..86e7f61586e 100644 --- a/gdb/elfread.c +++ b/gdb/elfread.c @@ -41,14 +41,12 @@ #include "regcache.h" #include "bcache.h" #include "gdb_bfd.h" -#include "build-id.h" #include "location.h" #include "auxv.h" #include "mdebugread.h" #include "ctfread.h" #include "gdbsupport/gdb_string_view.h" #include "gdbsupport/scoped_fd.h" -#include "debuginfod-support.h" #include "dwarf2/public.h" #include "cli/cli-cmds.h" @@ -1218,59 +1216,10 @@ elf_symfile_read_dwarf2 (struct objfile *objfile, && objfile->separate_debug_objfile == NULL && objfile->separate_debug_objfile_backlink == NULL) { - deferred_warnings warnings; - - std::string debugfile - = find_separate_debug_file_by_buildid (objfile, &warnings); - - if (debugfile.empty ()) - debugfile = find_separate_debug_file_by_debuglink (objfile, &warnings); - - if (!debugfile.empty ()) - { - gdb_bfd_ref_ptr debug_bfd - (symfile_bfd_open_no_error (debugfile.c_str ())); - - if (debug_bfd != nullptr) - symbol_file_add_separate (debug_bfd, debugfile.c_str (), - symfile_flags, objfile); - } + if (objfile->find_and_add_separate_symbol_file (symfile_flags)) + gdb_assert (objfile->separate_debug_objfile != nullptr); else - { - has_dwarf2 = false; - const struct bfd_build_id *build_id - = build_id_bfd_get (objfile->obfd.get ()); - const char *filename = bfd_get_filename (objfile->obfd.get ()); - - if (build_id != nullptr) - { - gdb::unique_xmalloc_ptr symfile_path; - scoped_fd fd (debuginfod_debuginfo_query (build_id->data, - build_id->size, - filename, - &symfile_path)); - - if (fd.get () >= 0) - { - /* File successfully retrieved from server. */ - gdb_bfd_ref_ptr debug_bfd - (symfile_bfd_open_no_error (symfile_path.get ())); - - if (debug_bfd != nullptr - && build_id_verify (debug_bfd.get (), build_id->size, - build_id->data)) - { - symbol_file_add_separate (debug_bfd, symfile_path.get (), - symfile_flags, objfile); - has_dwarf2 = true; - } - } - } - } - /* If all the methods to collect the debuginfo failed, print the - warnings, this is a no-op if there are no warnings. */ - if (debugfile.empty () && !has_dwarf2) - warnings.emit (); + has_dwarf2 = false; } return has_dwarf2; diff --git a/gdb/objfiles.h b/gdb/objfiles.h index 4b8aa9bfcec..ec9d354e4a7 100644 --- a/gdb/objfiles.h +++ b/gdb/objfiles.h @@ -513,6 +513,16 @@ struct objfile bool has_partial_symbols (); + /* Look for a separate debug symbol file for this objfile, make use of + build-id, debug-link, and debuginfod as necessary. If a suitable + separate debug symbol file is found then it is loaded using a call to + symbol_file_add_separate (SYMFILE_FLAGS is passed through unmodified + to this call) and this function returns true. If no suitable separate + debug symbol file is found and loaded then this function returns + false. */ + + bool find_and_add_separate_symbol_file (symfile_add_flags symfile_flags); + /* Return true if this objfile has any unexpanded symbols. A return value of false indicates either, that this objfile has all its symbols fully expanded (i.e. fully read in), or that this objfile has diff --git a/gdb/symfile-debug.c b/gdb/symfile-debug.c index 850da4147a3..961ae2327f7 100644 --- a/gdb/symfile-debug.c +++ b/gdb/symfile-debug.c @@ -35,6 +35,8 @@ #include "block.h" #include "filenames.h" #include "cli/cli-style.h" +#include "build-id.h" +#include "debuginfod-support.h" /* We need to save a pointer to the real symbol functions. Plus, the debug versions are malloc'd because we have to NULL out the @@ -558,6 +560,70 @@ objfile::require_partial_symbols (bool verbose) } } +/* See objfiles.h. */ + +bool +objfile::find_and_add_separate_symbol_file (symfile_add_flags symfile_flags) +{ + bool has_dwarf2 = true; + + deferred_warnings warnings; + + std::string debugfile + = find_separate_debug_file_by_buildid (this, &warnings); + + if (debugfile.empty ()) + debugfile = find_separate_debug_file_by_debuglink (this, &warnings); + + if (!debugfile.empty ()) + { + gdb_bfd_ref_ptr debug_bfd + (symfile_bfd_open_no_error (debugfile.c_str ())); + + if (debug_bfd != nullptr) + symbol_file_add_separate (debug_bfd, debugfile.c_str (), + symfile_flags, this); + } + else + { + has_dwarf2 = false; + const struct bfd_build_id *build_id + = build_id_bfd_get (this->obfd.get ()); + const char *filename = bfd_get_filename (this->obfd.get ()); + + if (build_id != nullptr) + { + gdb::unique_xmalloc_ptr symfile_path; + scoped_fd fd (debuginfod_debuginfo_query (build_id->data, + build_id->size, + filename, + &symfile_path)); + + if (fd.get () >= 0) + { + /* File successfully retrieved from server. */ + gdb_bfd_ref_ptr debug_bfd + (symfile_bfd_open_no_error (symfile_path.get ())); + + if (debug_bfd != nullptr + && build_id_verify (debug_bfd.get (), build_id->size, + build_id->data)) + { + symbol_file_add_separate (debug_bfd, symfile_path.get (), + symfile_flags, this); + has_dwarf2 = true; + } + } + } + } + /* If all the methods to collect the debuginfo failed, print the + warnings, this is a no-op if there are no warnings. */ + if (debugfile.empty () && !has_dwarf2) + warnings.emit (); + + return has_dwarf2; +} + /* Debugging version of struct sym_probe_fns. */