From patchwork Wed May 20 18:15:39 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Marchi X-Patchwork-Id: 135362 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 4BADE4BB3BFF for ; Wed, 20 May 2026 18:16:50 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4BADE4BB3BFF Authentication-Results: sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=polymtl.ca header.i=@polymtl.ca header.a=rsa-sha256 header.s=oct2025 header.b=kTPVpvWL X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from smtp.polymtl.ca (smtp.polymtl.ca [132.207.4.11]) by sourceware.org (Postfix) with ESMTPS id 9FDAE4BA23EC for ; Wed, 20 May 2026 18:16:21 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 9FDAE4BA23EC Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=polymtl.ca Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=polymtl.ca ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 9FDAE4BA23EC Authentication-Results: sourceware.org; arc=none smtp.remote-ip=132.207.4.11 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1779300981; cv=none; b=laIjR5EAguMeFhfFA41qu4zOMkkhYW0VIS9Ux17Iwt+iPcXzPGsn0VsLYPe8/LSyHz/3l05d4/MYFfwRfgVmMyYCUvEHdA+0O17nD6K+jHr+ToURYvjt1oleHL/CNqOXMj5Z6r6NXtQoBPaa37Do4/RN6gMXM3KWh2xPHSucV78= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1779300981; c=relaxed/simple; bh=KB0RtCIrmjdV/qkHK2OXsi54QgBO0ZRQ7BYFzmv9VdM=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=lH5AyeeMAJ5C4wPSGCHLWLtWb/MESh6JLauqlQgf1Jl2Z1SI333tYmZ7WXNe0OYlmEpw8MP3BfzRHi+jThZdvtUsbEsNNZBLCqlLTTLnfkWKmn2rRVY4H4Gf2BOAiNhHwEI2L+LDBmiy+fQONfgmrm/uk9qq6hFSwHJjqvgGyx0= ARC-Authentication-Results: i=1; sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=polymtl.ca header.i=@polymtl.ca header.a=rsa-sha256 header.s=oct2025 header.b=kTPVpvWL DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9FDAE4BA23EC Received: from simark.ca (simark.ca [158.69.221.121]) (authenticated bits=0) by smtp.polymtl.ca (8.14.7/8.14.7) with ESMTP id 64KIGDdf181104 (version=TLSv1/SSLv3 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 20 May 2026 14:16:17 -0400 DKIM-Filter: OpenDKIM Filter v2.11.0 smtp.polymtl.ca 64KIGDdf181104 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=polymtl.ca; s=oct2025; t=1779300978; bh=WFRvK360c44eq9dzeHkkYPv6tedMBmAj7ImTSkY0rAQ=; h=From:To:Cc:Subject:Date:From; b=kTPVpvWLYhmyDsdcoPW694/v/WKwkQss8pUbA6fuC2OAnabZNjCWecMD1G2NK2+Ot M+HVUdItt2YKuOxgK/rEEJ8WL+4AHJj5jMBFSIn8/sm0tAVCplREsFQkfYCXKIf/Z4 tRqwg44XC3Slreix3+GKuDLfcVJsrSAF93IshMJGo6jj4nlfuu8ayL9gu9sdpwQD4M FYURlnTF2VvU0druV6ZND+UbpzJYuRH94uu7rF9Ym5ePMgPPh6RemMrQBeACYFqgVT YBtk4AkezmYC9WZLTfBOyzT/kIZ86W9PXXd1cA0cAO0WoZlfBljN/eNiqSNc18DTAQ cJYX4c5EJPEUQ== Received: by simark.ca (Postfix) id 039AA1E024; Wed, 20 May 2026 14:16:12 -0400 (EDT) From: simon.marchi@polymtl.ca To: gdb-patches@sourceware.org Cc: Simon Marchi Subject: [PATCH] gdb/dwarf: make dwarf2_per_bfd::get_unit return a reference Date: Wed, 20 May 2026 14:15:39 -0400 Message-ID: <20260520181610.4066987-1-simon.marchi@polymtl.ca> X-Mailer: git-send-email 2.54.0 MIME-Version: 1.0 X-Poly-FromMTA: (simark.ca [158.69.221.121]) at Wed, 20 May 2026 18:16:13 +0000 X-Spam-Status: No, score=-3034.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_PASS, SPF_NONE, TXREP shortcircuit=no autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on 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 From: Simon Marchi This method can't return nullptr, switch it to return a reference. Change all_units_iterator::operator* too. Change-Id: I15c945553abfebdcc8834438a3b45d9895d628f0 --- gdb/dwarf2/read.c | 26 +++++++++++++------------- gdb/dwarf2/read.h | 6 +++--- 2 files changed, 16 insertions(+), 16 deletions(-) base-commit: ba415df8ba3817ab6eb5c9ec441ed2d979abe3b1 diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c index f8ade564b0ba..911cabc07993 100644 --- a/gdb/dwarf2/read.c +++ b/gdb/dwarf2/read.c @@ -1727,9 +1727,9 @@ dwarf2_base_index_functions::print_stats (struct objfile *objfile, for (int i = 0; i < total; ++i) { - dwarf2_per_cu *per_cu = per_objfile->per_bfd->get_unit (i); + dwarf2_per_cu &per_cu = per_objfile->per_bfd->get_unit (i); - if (!per_objfile->compunit_symtab_set_p (per_cu)) + if (!per_objfile->compunit_symtab_set_p (&per_cu)) ++count; } gdb_printf (_(" Number of read units: %d\n"), total - count); @@ -1743,7 +1743,7 @@ dwarf2_base_index_functions::expand_all_symtabs (struct objfile *objfile) { dwarf2_per_objfile *per_objfile = get_dwarf2_per_objfile (objfile); - for (dwarf2_per_cu *per_cu : all_units_range (per_objfile->per_bfd)) + for (dwarf2_per_cu &per_cu : all_units_range (per_objfile->per_bfd)) { /* If a .debug_names index contains a foreign TU but no index entry references it, the TU won't have a hint CU. This is a problem, because @@ -1753,7 +1753,7 @@ dwarf2_base_index_functions::expand_all_symtabs (struct objfile *objfile) are unlikely to contain anything interesting, symbol-wise. - They are likely to be referred to by some other unit (otherwise, why does it exist?), so will get expanded anyway. */ - if (signatured_type *sig_type = per_cu->as_signatured_type (); + if (signatured_type *sig_type = per_cu.as_signatured_type (); (sig_type != nullptr && sig_type->section () == nullptr && sig_type->hint_per_cu == nullptr)) @@ -1764,7 +1764,7 @@ dwarf2_base_index_functions::expand_all_symtabs (struct objfile *objfile) be triggered later on. See PR symtab/23010. So, tell dw2_instantiate_symtab to skip partial CUs -- any important partial CU will be read via DW_TAG_imported_unit anyway. */ - dw2_instantiate_symtab (per_cu, per_objfile, true); + dw2_instantiate_symtab (&per_cu, per_objfile, true); } } @@ -1983,16 +1983,16 @@ dwarf2_base_index_functions::map_symbol_filenames (objfile *objfile, } } - for (dwarf2_per_cu *per_cu : all_units_range (per_objfile->per_bfd)) + for (dwarf2_per_cu &per_cu : all_units_range (per_objfile->per_bfd)) { /* We only need to look at symtabs not already expanded. */ - if (per_cu->is_debug_types () - || per_objfile->compunit_symtab_set_p (per_cu)) + if (per_cu.is_debug_types () + || per_objfile->compunit_symtab_set_p (&per_cu)) continue; - if (per_cu->fnd != nullptr) + if (per_cu.fnd != nullptr) { - file_and_directory *fnd = per_cu->fnd.get (); + file_and_directory *fnd = per_cu.fnd.get (); const char *filename = fnd->get_name (); const char *key = filename; @@ -2008,7 +2008,7 @@ dwarf2_base_index_functions::map_symbol_filenames (objfile *objfile, fun (filename, fullname); } - quick_file_names *file_data = dw2_get_file_names (per_cu, per_objfile); + quick_file_names *file_data = dw2_get_file_names (&per_cu, per_objfile); if (file_data == nullptr || qfn_cache.find (file_data) != qfn_cache.end ()) continue; @@ -13887,11 +13887,11 @@ cooked_index_functions::search gdb_assert (lookup_name != nullptr || symbol_matcher == nullptr); if (lookup_name == nullptr) { - for (dwarf2_per_cu *per_cu : all_units_range (per_objfile->per_bfd)) + for (dwarf2_per_cu &per_cu : all_units_range (per_objfile->per_bfd)) { QUIT; - if (search_one (per_cu, per_objfile, cus_to_skip, compunit_callback, + if (search_one (&per_cu, per_objfile, cus_to_skip, compunit_callback, lang_matcher) == iteration_status::stop) return iteration_status::stop; diff --git a/gdb/dwarf2/read.h b/gdb/dwarf2/read.h index 12dc6224d8c0..327b6eb421a1 100644 --- a/gdb/dwarf2/read.h +++ b/gdb/dwarf2/read.h @@ -591,9 +591,9 @@ struct dwarf2_per_bfd { return bfd_get_filename (this->obfd); } /* Return the unit given its index. */ - dwarf2_per_cu *get_unit (int index) const + dwarf2_per_cu &get_unit (int index) const { - return this->all_units[index].get (); + return *this->all_units[index]; } /* Ensure that the all_units vector is in the expected order for @@ -802,7 +802,7 @@ class all_units_iterator return *this; } - dwarf2_per_cu *operator* () const + dwarf2_per_cu &operator* () const { return m_per_bfd->get_unit (m_index); }