From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 E998138618B7 for ; Wed, 8 Nov 2023 15:49:13 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E998138618B7 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 E998138618B7 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=1699458555; cv=none; b=JoUSo6WfSbbhtLGPFikbyqtHFjj9w2WC62Tsjcuv9omiHGV0hBIrjhT5NYSK8xkSVg1JEWT+B5sQxVVKLFk3h/cG+knjE1cFHzJGhRJQ49FrwY2QNKZH2WBzv4nu5GyIDxYvGvzjxXS0+sEka5VKJZtci6M4+GiQwmdORlo/sJU= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1699458555; c=relaxed/simple; bh=9Ar3Mnzn8nRdOaYxeaHfHUXTOn0bLQn8Ei+ztnW9tMo=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=XegJ5WE6V6RXoImjO0sTgB1ogJmSJmOfL+vX/aXs4fOV3PQXB0J1+a69G3of+hLjjHk6vrVYdlEY9itleKqFBIs/stH/CE01CWdsWPEdX+bJQge9bJbMcv16oe87q/hdMS+FbOUH7hWctxKdnEIbZxsbM72aiOEHlYqFHUvV3W4= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1699458553; 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=dWzz2suwMqwYOJX7WJOwA0EAXROD5rS1PQZ1rzHNs0E=; b=BzNLcTPKmTjsOrhjGUWQ3vJg4rPZzzU2ck8adrOiLBAkw4kpQn3aV/oCzaKazn7oRWxCOm Rah/ZYFOhDeKnDSBbo5k9dDPSUG1Zh0NUZUg27NijdEbP6bHVaOhGyOnep2ThWs1pjfCCC 7mZbvJK+lcJKFKkd7Mrhm9vXbdi5Gd4= Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-124-MX8XvtBdOn6i-BPc5EijTQ-1; Wed, 08 Nov 2023 10:49:10 -0500 X-MC-Unique: MX8XvtBdOn6i-BPc5EijTQ-1 Received: by mail-wm1-f69.google.com with SMTP id 5b1f17b1804b1-4084d0b171eso6892545e9.0 for ; Wed, 08 Nov 2023 07:49:10 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699458549; x=1700063349; 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=mIIW4IqzR7Pbf+t1IImI+a6pOLc2Gtees8XagFYK0a8=; b=lIJ8el8tPG+olWxKfynQmZGwIkkxQDISfY7b7GiyPLfOqZ2lx9f2qDmgkNmtJIe2e+ ZSidlgBqBrLTd2lle5zyaKW6YSGSyyZxaV5tx5X8mCE2t26q9N3S9DEkdQOry98Oi7Hg /LsaDvAD5E+xmG0zuv9WK+n5PfAMrg79NH4v4AP4XIRuGTCTMzQvtvFm5Olfm6Yk2ED8 8v8ycwca7bLt/hPVzu4k0yMtOsMEkGguksnqBuQZG03PX1C2nCiJTkVyqDT8O/ei3mkN yBxHbRCnbphES2JaegkluY8Qk5RDJ22IZrYuUC6jnXLjuyJmUYtC7QAAyXq57U6RdJD8 xYEg== X-Gm-Message-State: AOJu0YxExeDFyXJE/XydAjEaiKJpqcDMIssIlskCVrml2MNLqYCVqP7z Qp5Fi0VZcSG6RBSpY1JukfQZBRCe8Kg6DoMiXWeHg1h0wYocYfrBKo5c9ewC0fdlSwDa7pIDJJ/ TPFmcnAIJh2K2yKJpihEO0jeIMtaDM1QmXjvtNNmWWl9TO/MUOhlpItN1rFqv33Og0mJkWFrp++ PycKngNA== X-Received: by 2002:a05:600c:3306:b0:405:3f06:d2ef with SMTP id q6-20020a05600c330600b004053f06d2efmr7497105wmp.4.1699458549056; Wed, 08 Nov 2023 07:49:09 -0800 (PST) X-Google-Smtp-Source: AGHT+IHZfH30huVTicxKYm+mVXRzmdXt9AYp5D1fkpx40Axh4e7EJN0WYpkmTaeXs7P0IafqIEnW3g== X-Received: by 2002:a05:600c:3306:b0:405:3f06:d2ef with SMTP id q6-20020a05600c330600b004053f06d2efmr7497078wmp.4.1699458548693; Wed, 08 Nov 2023 07:49:08 -0800 (PST) Received: from localhost (105.226.159.143.dyn.plus.net. [143.159.226.105]) by smtp.gmail.com with ESMTPSA id l6-20020a5d4806000000b0032dbf99bf4fsm5308093wrq.89.2023.11.08.07.49.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Nov 2023 07:49:08 -0800 (PST) From: Andrew Burgess To: gdb-patches@sourceware.org Cc: Andrew Burgess , Tom Tromey Subject: [PATCHv2 3/5] gdb: refactor objfile::find_and_add_separate_symbol_file Date: Wed, 8 Nov 2023 15:48:57 +0000 Message-Id: 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 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII"; x-default=true X-Spam-Status: No, score=-11.4 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,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: This is purely a refactoring commit. This commit splits objfile::find_and_add_separate_symbol_file into some separate helper functions. My hope is that the steps for looking up separate debug information are now clearer. In a later commit I'm going to extend objfile::find_and_add_separate_symbol_file, with some additional logic, so starting with a simpler function will make the following changes easier. When reading objfile::find_and_add_separate_symbol_file after this commit, you might be tempted to think that removing the `has_dwarf` local variable would be a good additional cleanup. After the next commit though it makes more sense to retain this local, so I've left this in place for now. There should be no user visible changes after this commit. --- gdb/symfile-debug.c | 135 +++++++++++++++++++++++++++++--------------- 1 file changed, 88 insertions(+), 47 deletions(-) diff --git a/gdb/symfile-debug.c b/gdb/symfile-debug.c index 961ae2327f7..0b6dc4752df 100644 --- a/gdb/symfile-debug.c +++ b/gdb/symfile-debug.c @@ -560,68 +560,109 @@ objfile::require_partial_symbols (bool verbose) } } +/* Call LOOKUP_FUNC to find the filename of a file containing the separate + debug information matching OBJFILE. If LOOKUP_FUNC does return a + filename then open this file and return a std::pair containing the + gdb_bfd_ref_ptr of the open file and the filename returned by + LOOKUP_FUNC, otherwise this function returns an empty pair; the first + item will be nullptr, and the second will be an empty string. + + Any warnings generated by this function, or by calling LOOKUP_FUNC are + placed into WARNINGS, these warnings are only displayed to the user if + GDB is unable to find the separate debug information via any route. */ +static std::pair +simple_find_and_open_separate_symbol_file + (struct objfile *objfile, + std::string (*lookup_func) (struct objfile *, deferred_warnings *), + deferred_warnings *warnings) +{ + std::string filename = lookup_func (objfile, warnings); + + if (!filename.empty ()) + { + gdb_bfd_ref_ptr symfile_bfd + = symfile_bfd_open_no_error (filename.c_str ()); + if (symfile_bfd != nullptr) + return { symfile_bfd, filename }; + } + + return {}; +} + +/* Lookup separate debug information for OBJFILE via debuginfod. If + successful the debug information will be have been downloaded into the + debuginfod cache and this function will return a std::pair containing a + gdb_bfd_ref_ptr of the open debug information file and the filename for + the file within the debuginfod cache. If no debug information could be + found then this function returns an empty pair; the first item will be + nullptr, and the second will be an empty string. */ + +static std::pair +debuginfod_find_and_open_separate_symbol_file (struct objfile * objfile) +{ + 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)) + return { debug_bfd, std::string (symfile_path.get ()) }; + } + } + + return {}; +} + /* See objfiles.h. */ bool objfile::find_and_add_separate_symbol_file (symfile_add_flags symfile_flags) { - bool has_dwarf2 = true; + bool has_dwarf = false; 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); + gdb_bfd_ref_ptr debug_bfd; + std::string filename; - if (!debugfile.empty ()) - { - gdb_bfd_ref_ptr debug_bfd - (symfile_bfd_open_no_error (debugfile.c_str ())); + std::tie (debug_bfd, filename) = simple_find_and_open_separate_symbol_file + (this, find_separate_debug_file_by_buildid, &warnings); - 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 (debug_bfd == nullptr) + std::tie (debug_bfd, filename) + = simple_find_and_open_separate_symbol_file + (this, find_separate_debug_file_by_debuglink, &warnings); - 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) + std::tie (debug_bfd, filename) + = debuginfod_find_and_open_separate_symbol_file (this); - 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 (debug_bfd != nullptr) + { + symbol_file_add_separate (debug_bfd, filename.c_str (), symfile_flags, + this); + has_dwarf = 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) + + /* If we still have not got a separate debug symbol file, then + emit any warnings we've collected so far. */ + if (!has_dwarf) warnings.emit (); - return has_dwarf2; + return has_dwarf; } -- 2.25.4