From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id GYW7H5ooa2nKTQcAWB0awg (envelope-from ) for ; Sat, 17 Jan 2026 01:13:46 -0500 Authentication-Results: simark.ca; dkim=pass (2048-bit key; unprotected) header.d=polymtl.ca header.i=@polymtl.ca header.a=rsa-sha256 header.s=oct2025 header.b=M3Jv3NNH; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 7E1271E0DD; Sat, 17 Jan 2026 01:13:46 -0500 (EST) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-2.4 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED,RCVD_IN_VALIDITY_CERTIFIED_BLOCKED, RCVD_IN_VALIDITY_RPBL_BLOCKED,RCVD_IN_VALIDITY_SAFE_BLOCKED autolearn=ham autolearn_force=no version=4.0.1 Received: from vm01.sourceware.org (vm01.sourceware.org [38.145.34.32]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 141E31E08D for ; Sat, 17 Jan 2026 01:13:46 -0500 (EST) Received: from vm01.sourceware.org (localhost [127.0.0.1]) by sourceware.org (Postfix) with ESMTP id 8C87A4BA23EC for ; Sat, 17 Jan 2026 06:13:45 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8C87A4BA23EC 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=M3Jv3NNH Received: from smtp.polymtl.ca (smtp.polymtl.ca [132.207.4.11]) by sourceware.org (Postfix) with ESMTPS id DB5844BA2E1E for ; Sat, 17 Jan 2026 06:13:05 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org DB5844BA2E1E 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 DB5844BA2E1E Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=132.207.4.11 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1768630386; cv=none; b=T/VNcQhs4VT0QCpjMPcIcOR2NjxD0Z/mNW+M2TT4YClFd0u2ZP08oEjxif4CgWuF6dIqBO4yO4SGwMexEgvbUbvzf783c1flYDQ3xsyKastSlw+CiZrz2zgfqkDe22l/Gy0tku/o0utqJiEy/jMS3dvUkl+2JPxr4fXxOL2NrzA= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1768630386; c=relaxed/simple; bh=6oodETTj0y4RnXPGRHOOZkVUMUwou9yk9EuRtc6nsW0=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=U31q9kIdgy5uMU/UtSonywjqPfUjwhOkq224Nvox++nlKpuQ8hCv2NonYuw6hxVfNrNlhsLUOhFDjmizkNfOyk+3KZS+imWV88gclFWAOqJd8tEROb8NQOyVw79YmLFbIcRCfIGNlpvudtejAB75W2oXu6r3+m1F7RlaFhIsjjY= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org DB5844BA2E1E 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 60H6D0Ca097927 (version=TLSv1/SSLv3 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Sat, 17 Jan 2026 01:13:04 -0500 DKIM-Filter: OpenDKIM Filter v2.11.0 smtp.polymtl.ca 60H6D0Ca097927 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=polymtl.ca; s=oct2025; t=1768630385; bh=htR+A1Wtyl5421rsAl4FspUQTUA2AI1Y49rUYuf46j4=; h=From:To:Cc:Subject:Date:In-Reply-To:From; b=M3Jv3NNHVT7G25UEKIq5ypWVsrI5IwACKFjXHn2oyPnMERuOSNnbiBNIVphsyVCSj 2AdGS50hSL57fIxsawqJ8kYOAZoAEZp1IHg44Aw2+DcDATE1BCSkrYI4hEal9avOZd aqDGR3Vf1tPG3lAoKrK0MJzr3b8qhPcluA/P2x7hMBDyazKYIEcrbec0t+/W3yt6Qe TxXOE0J0VlwV38JWqV5QZSBAcLHBluZNBKF7ZHmdn7kui3ZoP/Dl2nkxHfczhRvaJE DAQBLO6rJgGR4dzyvk4/VBrt80Y+1RYvdyNYzmjZ2UNMEtkLubKZVxEw4aOBn+/eRN Vn7zXdyXKUpzw== Received: by simark.ca (Postfix) id F0BB61E0EF; Sat, 17 Jan 2026 01:03:36 -0500 (EST) From: simon.marchi@polymtl.ca To: gdb-patches@sourceware.org Cc: Simon Marchi Subject: [PATCH 5/5] gdb/dwarf: add unit_lists structure to index writer Date: Sat, 17 Jan 2026 01:02:35 -0500 Message-ID: <20260117060335.691691-6-simon.marchi@polymtl.ca> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260117060335.691691-1-simon.marchi@polymtl.ca> References: <20260117060335.691691-1-simon.marchi@polymtl.ca> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Poly-FromMTA: (simark.ca [158.69.221.121]) at Sat, 17 Jan 2026 06:13:00 +0000 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~public-inbox=simark.ca@sourceware.org From: Simon Marchi I think it makes the code more readable than the pair of vector. Also, I'm considering adding a third list (foreigh type units), which will be easier with the structure. Change-Id: I38ec4ddf8f786a2ba10c5b371cfe04c2baaa7da9 --- gdb/dwarf2/index-write.c | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/gdb/dwarf2/index-write.c b/gdb/dwarf2/index-write.c index c4bd424d4340..ffbd3777b4c7 100644 --- a/gdb/dwarf2/index-write.c +++ b/gdb/dwarf2/index-write.c @@ -1314,21 +1314,25 @@ write_shortcuts_table (cooked_index *table, data_buf &shortcuts, shortcuts.append_offset (main_name_offset); } +struct unit_lists +{ + std::vector comp; + std::vector type; +}; + /* Get sorted (by section offset) lists of comp units and type units. */ -static std::pair, - std::vector> +static unit_lists get_unit_lists (const dwarf2_per_bfd &per_bfd) { - std::vector comp_units; - std::vector type_units; + unit_lists lists; for (const auto &unit : per_bfd.all_units) if (const signatured_type *sig_type = unit->as_signatured_type (); sig_type != nullptr) - type_units.emplace_back (sig_type); + lists.type.emplace_back (sig_type); else - comp_units.emplace_back (unit.get ()); + lists.comp.emplace_back (unit.get ()); auto by_sect_off = [] (const dwarf2_per_cu *lhs, const dwarf2_per_cu *rhs) { return lhs->sect_off () < rhs->sect_off (); }; @@ -1342,10 +1346,10 @@ get_unit_lists (const dwarf2_per_bfd &per_bfd) However, it helps make sure that GDB produce a stable and predictable output, which is nice. */ - std::sort (comp_units.begin (), comp_units.end (), by_sect_off); - std::sort (type_units.begin (), type_units.end (), by_sect_off); + std::sort (lists.comp.begin (), lists.comp.end (), by_sect_off); + std::sort (lists.type.begin (), lists.type.end (), by_sect_off); - return {std::move (comp_units), std::move (type_units)}; + return lists; } /* Write contents of a .gdb_index section for OBJFILE into OUT_FILE. @@ -1365,14 +1369,14 @@ write_gdbindex (dwarf2_per_bfd *per_bfd, cooked_index *table, cu_index_map cu_index_htab; cu_index_htab.reserve (per_bfd->all_units.size ()); - auto [comp_units, type_units] = get_unit_lists (*per_bfd); + unit_lists units = get_unit_lists (*per_bfd); int counter = 0; /* Write comp units. */ data_buf objfile_cu_list; data_buf dwz_cu_list; - for (const dwarf2_per_cu *per_cu : comp_units) + for (const dwarf2_per_cu *per_cu : units.comp) { const auto insertpair = cu_index_htab.emplace (per_cu, counter); gdb_assert (insertpair.second); @@ -1390,7 +1394,7 @@ write_gdbindex (dwarf2_per_bfd *per_bfd, cooked_index *table, /* Write type units. */ data_buf types_cu_list; - for (const signatured_type *sig_type : type_units) + for (const signatured_type *sig_type : units.type) { const auto insertpair = cu_index_htab.emplace (sig_type, counter); gdb_assert (insertpair.second); @@ -1449,12 +1453,12 @@ write_debug_names (dwarf2_per_bfd *per_bfd, cooked_index *table, const enum bfd_endian dwarf5_byte_order = bfd_big_endian (per_bfd->obfd) ? BFD_ENDIAN_BIG : BFD_ENDIAN_LITTLE; - auto [comp_units, type_units] = get_unit_lists (*per_bfd); + unit_lists units = get_unit_lists (*per_bfd); debug_names nametable (per_bfd, dwarf5_is_dwarf64, dwarf5_byte_order); data_buf comp_unit_list; int comp_unit_counter = 0; - for (const auto per_cu : comp_units) + for (const auto per_cu : units.comp) { nametable.add_cu (per_cu, comp_unit_counter); comp_unit_list.append_uint (nametable.dwarf5_offset_size (), @@ -1466,7 +1470,7 @@ write_debug_names (dwarf2_per_bfd *per_bfd, cooked_index *table, data_buf type_unit_list; int type_unit_counter = 0; - for (const auto per_cu : type_units) + for (const auto per_cu : units.type) { nametable.add_cu (per_cu, type_unit_counter); type_unit_list.append_uint (nametable.dwarf5_offset_size (), -- 2.52.0