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 76CD13865C2A for ; Wed, 18 Oct 2023 10:53:46 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 76CD13865C2A 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 76CD13865C2A 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=1697626427; cv=none; b=Kr7XWtFwcL52fHtQEqeRs3ybhA2gqrLcNfyJNp3EvOho/O5JCrl/txmI/hm7wusxuAqJLEaJr6o21JK+tN8qJ7lEgWG2eqeLnLaXEXA3h77IuAaZQPVMmgiVYhWKZGh6fkmM/DeXqDe2Q609odm2fjt/WdI/I0dqE0nHZIY1FWg= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697626427; c=relaxed/simple; bh=AsPNaC7DR+vKmGo7w4l2kzK/FUB0k68zciQvo7BqqYo=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=R6jMbqCqc9SNC7yvsdXt+pQyk9lXSSbPZW7YtWA2Sh/fDPqyhXDLjpWu0mpHunDlH8Fi/37Hc9/FzvUlkzKP6Z5VS34YTtHK96xrAb0EmqRCOklJH4O3DX9wcKLxhETZuTR1xIj8P2yIkojVyyplSDzeVnaFEk12IaqvcCiaD0g= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1697626426; 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=XEbz6kK670MIaDXtMFSMzBNaLL64DTWbYGClrFH2SYQ=; b=adAUT2L+eoEtbnpzDGbn1w4Wjz6+qxntFirMIO57jMbAqRitsRnVE3rGlKNS7Dm7/5g6Qy 00fNY+BlYVrvKpxtSQRwYLhhaompFKC77HIYqziHvVt6t06Z1v2tyEKKbANMNlOBgQk976 ljgMwOH5LX5D87geSixlXxofnvTGUxw= 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-140-buRrqzB5P96DgiRUGXyj0w-1; Wed, 18 Oct 2023 06:53:35 -0400 X-MC-Unique: buRrqzB5P96DgiRUGXyj0w-1 Received: by mail-qt1-f197.google.com with SMTP id d75a77b69052e-418099ca1c2so75663891cf.0 for ; Wed, 18 Oct 2023 03:53:35 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697626414; x=1698231214; 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=XEbz6kK670MIaDXtMFSMzBNaLL64DTWbYGClrFH2SYQ=; b=WMbhmU8XAQ5jekK0gVu4BkAMDagS+hHNhhoP4SrdJaSlVaAKqguY7drF2H2M6snEul g7Iu5ySwWWDo2/zdwhmskjMSiyP/sZJky9R+FZq29j0c0hihltiNIT5Z5NtxM4udL/jC GQEf1m6znq6FH050ZAuP2A9kxRZRN8Gtg11nrdqZkCs84+6yaGsAMZMCRPZahZN0plA/ B0mf2QdM9TXLiS3qdc/z/F4HS262Qwf4MWX4qbcrt3kfvVeIvqeO2S/RX7ABDdnFPtgt n4Jric4+XDMw4JkyUSl+JpO2Ar4pEJmRZRtPLh849++BE8bW4lEtQclZgnltixYPEO66 rHeQ== X-Gm-Message-State: AOJu0Ywn9UR+VkNfn0hoME43rj5NvQiFRbkIRh/lL4LmOsvCDceYJDBG BUXNgNNfJsFraS3VvNikhCRPtX4fYRQjpgf9xMhHa5hl9P1UApB3G9LeZnjd0Xz2F5b8PxuzB0W gbzco0160vBGFDqxQo5DgZht9fulpU+yFjTb+vhFNbmCmgoRn8R0Pl0WExlW3j+pbDtTJZGHkU7 +1dwlCog== X-Received: by 2002:a05:622a:282:b0:403:fcd9:963 with SMTP id z2-20020a05622a028200b00403fcd90963mr5235805qtw.67.1697626414504; Wed, 18 Oct 2023 03:53:34 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHUq53XopbBlpy6tgliv6hPAr/yc+JpWK6TgEuXIGVPF/34lMs+Kb8rkyrwjhuRZLotkGa4NA== X-Received: by 2002:a05:622a:282:b0:403:fcd9:963 with SMTP id z2-20020a05622a028200b00403fcd90963mr5235785qtw.67.1697626414151; Wed, 18 Oct 2023 03:53:34 -0700 (PDT) Received: from localhost ([31.111.84.209]) by smtp.gmail.com with ESMTPSA id r19-20020ac85e93000000b0041cbb7139a9sm482828qtx.65.2023.10.18.03.53.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Oct 2023 03:53:33 -0700 (PDT) From: Andrew Burgess To: gdb-patches@sourceware.org Cc: Andrew Burgess Subject: [PATCH 3/5] gdb: refactor objfile::find_and_add_separate_symbol_file Date: Wed, 18 Oct 2023 11:53:21 +0100 Message-Id: <108c51107d11eae41fd77d54d73613569875c4c7.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 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII"; x-default=true X-Spam-Status: No, score=-11.6 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_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 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. There should be no user visible changes after this commit. --- gdb/symfile-debug.c | 127 ++++++++++++++++++++++++++++---------------- 1 file changed, 82 insertions(+), 45 deletions(-) diff --git a/gdb/symfile-debug.c b/gdb/symfile-debug.c index 961ae2327f7..0a4499320c7 100644 --- a/gdb/symfile-debug.c +++ b/gdb/symfile-debug.c @@ -560,65 +560,102 @@ 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_dwarf2 = false; deferred_warnings warnings; - std::string debugfile - = find_separate_debug_file_by_buildid (this, &warnings); + std::pair result; - 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 ())); + result = 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 (result.first == nullptr) + result = simple_find_and_open_separate_symbol_file + (this, find_separate_debug_file_by_debuglink, &warnings); - 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 (result.first == nullptr) + result = debuginfod_find_and_open_separate_symbol_file (this); - 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 (result.first != nullptr) + { + symbol_file_add_separate (result.first, result.second.c_str (), + 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) + if (!has_dwarf2) warnings.emit (); return has_dwarf2; -- 2.25.4