From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id 1bHqOOUdfGmrwRwAWB0awg (envelope-from ) for ; Thu, 29 Jan 2026 21:56:37 -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=jf3OKda2; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id CE23D1E0BA; Thu, 29 Jan 2026 21:56:37 -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 72F221E0BA for ; Thu, 29 Jan 2026 21:56:36 -0500 (EST) Received: from vm01.sourceware.org (localhost [127.0.0.1]) by sourceware.org (Postfix) with ESMTP id D52324BB3BCC for ; Fri, 30 Jan 2026 02:56:35 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D52324BB3BCC 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=jf3OKda2 Received: from smtp.polymtl.ca (smtp.polymtl.ca [132.207.4.11]) by sourceware.org (Postfix) with ESMTPS id 81A0A4BAD140 for ; Fri, 30 Jan 2026 02:55:54 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 81A0A4BAD140 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 81A0A4BAD140 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=1769741754; cv=none; b=OhozIzXaEq2B4IXyuTEnQkzJUhb4DVNPZwktcgwWwEFpWDCcDP1vIfom6ZGPKrJbnU4xJOY7c513JxZM7uej1ODXKojCfO0K9DQuOAJ0G0FVB8D+PQ44eK7S36v6NftmHUTuL+D8MahSaj+oPSWeeUkqdy5wpp6auLGNGpctN4c= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1769741754; c=relaxed/simple; bh=od515XwmxZJr5BaATwjU01iKmvvNWn1Hi4jWtT+sjoU=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=TotpkeFn4x5RGRzguOw+tOfPBE51BVSWu/jWnVFSuQ97n1tQ03PVPka2++AUSkTAMFoygLBgOvs+2UlCv5dxPGEOdBBgRDtbyqUaSYGFsnEeuerLJV5zEAmIj6DUddg37JCTF1G0N4sgczJk1gntmjx5PIXscN4Mr8xQ3znTNOk= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 81A0A4BAD140 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 60U2tlRj001873 (version=TLSv1/SSLv3 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 29 Jan 2026 21:55:52 -0500 DKIM-Filter: OpenDKIM Filter v2.11.0 smtp.polymtl.ca 60U2tlRj001873 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=polymtl.ca; s=oct2025; t=1769741752; bh=F6zvjda8TMu4Qkm/JKbvVsSyf7styfHtg73MlYTvRf0=; h=From:To:Cc:Subject:Date:In-Reply-To:From; b=jf3OKda21yZCJ8ZW9Y3eILsc7FtZLgeUQjGGTSnZViEzAKAtd4TC5ElyZgPU4DRrT woG4ltWvF3mzrbDDKD1VryjaizwR5dqxkd+wOUT766S7sfLQj2Wok/OY4XFA9xfOA+ iLU+1bPCwTXE3BHKXnFyJTHDJxqemc+kOCTdq+Rbcy1Fgb6tIpy/htIvCl7PKC7QnG k7Qzjkj2qd7vyP7q9wSjEPm667jgRCBOxvQ0K51CxjruYkcOAbaKr1+UckHIarkIXy cSvTMCGSdQ7Y1MqIk3j0irqTs8mk8Zp9PRQ89CKLBUFrj7QoTQGxm5Svc1KOn+2XkL aDrBRrShwhzvw== Received: by simark.ca (Postfix) id 5E7771E0BA; Thu, 29 Jan 2026 21:55:47 -0500 (EST) From: simon.marchi@polymtl.ca To: gdb-patches@sourceware.org Cc: Simon Marchi Subject: [PATCH 2/3] gdb/symtab: make compunit_symtab::includes a std::vector Date: Thu, 29 Jan 2026 21:55:27 -0500 Message-ID: <20260130025546.322629-2-simon.marchi@polymtl.ca> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260130025546.322629-1-simon.marchi@polymtl.ca> References: <20260130025546.322629-1-simon.marchi@polymtl.ca> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Poly-FromMTA: (simark.ca [158.69.221.121]) at Fri, 30 Jan 2026 02:55:47 +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 Since compunit_symtab is now a properly constructed and destructed object, we can use fancy C++ things in it. Change the includes field to be an std::vector. Previously, the includes list was NULL-terminated. I went through all users and I'm pretty sure that none of them rely on it being NULL-terminated anymore. Change-Id: Ie68a8dc0f227fd49c291d85c3e8e020463e9d0d4 --- gdb/block.c | 11 +++++++++-- gdb/dwarf2/read.c | 37 +++++++++---------------------------- gdb/symmisc.c | 42 ++++++++++++++---------------------------- gdb/symtab.h | 5 ++--- 4 files changed, 34 insertions(+), 61 deletions(-) diff --git a/gdb/block.c b/gdb/block.c index fa2246383d1e..e61122410650 100644 --- a/gdb/block.c +++ b/gdb/block.c @@ -426,7 +426,7 @@ initialize_block_iterator (const struct block *block, functions. If there are no included symtabs, we only need to search a single block, so we might as well just do that directly. */ - if (cu->includes == NULL) + if (cu->includes.empty ()) { iter->d.block = block; /* A signal value meaning that we're iterating over a single @@ -447,7 +447,14 @@ block_iterator::compunit_symtab () const { if (this->idx == -1) return this->d.compunit_symtab; - return this->d.compunit_symtab->includes[this->idx]; + + auto &includes = this->d.compunit_symtab->includes; + + if (this->idx < includes.size ()) + return includes[this->idx]; + + /* Iteration is complete. */ + return nullptr; } /* Perform a single step for a plain block iterator, iterating across diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c index 036ec7e6337f..94fa3919b885 100644 --- a/gdb/dwarf2/read.c +++ b/gdb/dwarf2/read.c @@ -2117,24 +2117,16 @@ static struct compunit_symtab * recursively_find_pc_sect_compunit_symtab (struct compunit_symtab *cust, CORE_ADDR pc) { - int i; - if (cust->blockvector () != nullptr && cust->blockvector ()->contains (pc)) return cust; - if (cust->includes == NULL) - return NULL; - - for (i = 0; cust->includes[i]; ++i) - { - struct compunit_symtab *s = cust->includes[i]; - - s = recursively_find_pc_sect_compunit_symtab (s, pc); - if (s != NULL) - return s; - } + for (compunit_symtab *include : cust->includes) + if (compunit_symtab *found + = recursively_find_pc_sect_compunit_symtab (include, pc); + found != nullptr) + return found; - return NULL; + return nullptr; } struct compunit_symtab * @@ -4744,8 +4736,8 @@ recursively_compute_inclusions cust); } -/* Compute the compunit_symtab 'includes' fields for the compunit_symtab of - PER_CU. */ +/* Compute compunit_symtab::includes for the compunit_symtab of PER_CU. This + is the transitive closure of all the included compunit_symtabs. */ static void compute_compunit_symtab_includes (dwarf2_per_cu *per_cu, @@ -4755,8 +4747,6 @@ compute_compunit_symtab_includes (dwarf2_per_cu *per_cu, if (!per_cu->imported_symtabs.empty ()) { - int len; - std::vector result_symtabs; compunit_symtab *cust = per_objfile->get_symtab (per_cu); /* If we don't have a symtab, we can just skip this case. */ @@ -4767,18 +4757,9 @@ compute_compunit_symtab_includes (dwarf2_per_cu *per_cu, gdb::unordered_set all_type_symtabs; for (dwarf2_per_cu *ptr : per_cu->imported_symtabs) - recursively_compute_inclusions (&result_symtabs, all_children, + recursively_compute_inclusions (&cust->includes, all_children, all_type_symtabs, ptr, per_objfile, cust); - - /* Now we have a transitive closure of all the included symtabs. */ - len = result_symtabs.size (); - cust->includes - = XOBNEWVEC (&per_objfile->objfile->objfile_obstack, - struct compunit_symtab *, len + 1); - memcpy (cust->includes, result_symtabs.data (), - len * sizeof (compunit_symtab *)); - cust->includes[len] = NULL; } } diff --git a/gdb/symmisc.c b/gdb/symmisc.c index 838c2a002e15..258489fe8f07 100644 --- a/gdb/symmisc.c +++ b/gdb/symmisc.c @@ -362,21 +362,13 @@ dump_symtab_1 (struct symtab *symtab, struct ui_file *outfile) struct compunit_symtab *cust = symtab->compunit (); if (cust->user != nullptr) - { - const char *addr - = host_address_to_string (cust->user->primary_filetab ()); - gdb_printf (outfile, _("Compunit user: %s\n"), addr); - } - if (cust->includes != nullptr) - for (int i = 0; ; ++i) - { - struct compunit_symtab *include = cust->includes[i]; - if (include == nullptr) - break; - const char *addr - = host_address_to_string (include->primary_filetab ()); - gdb_printf (outfile, _("Compunit include: %s\n"), addr); - } + gdb_printf (outfile, _("Compunit user: %s\n"), + host_address_to_string (cust->user->primary_filetab ())); + + + for (compunit_symtab *include : cust->includes) + gdb_printf (outfile, _("Compunit include: %s\n"), + host_address_to_string (include->primary_filetab ())); } } @@ -816,21 +808,15 @@ maintenance_info_symtabs (const char *regexp, int from_tty) cust.user != nullptr ? host_address_to_string (cust.user) : "(null)"); - if (cust.includes != nullptr) + if (!cust.includes.empty ()) { gdb_printf (_(" ( includes\n")); - for (int i = 0; ; ++i) - { - struct compunit_symtab *include - = cust.includes[i]; - if (include == nullptr) - break; - const char *addr - = host_address_to_string (include); - gdb_printf (" (%s %s)\n", - "(struct compunit_symtab *)", - addr); - } + + for (compunit_symtab *include : cust.includes) + gdb_printf (" (%s %s)\n", + "(struct compunit_symtab *)", + host_address_to_string (include)); + gdb_printf (" )\n"); } printed_compunit_symtab_start = 1; diff --git a/gdb/symtab.h b/gdb/symtab.h index 6a1320aabad8..8f0cc728410d 100644 --- a/gdb/symtab.h +++ b/gdb/symtab.h @@ -2008,14 +2008,13 @@ struct compunit_symtab : intrusive_list_node the given compilation unit, but it currently is. */ struct macro_table *m_macro_table = nullptr; - /* If non-NULL, then this points to a NULL-terminated vector of - included compunits. When searching the static or global + /* Vector of included compunit symtabs. When searching the static or global block of this compunit, the corresponding block of all included compunits will also be searched. Note that this list must be flattened -- the symbol reader is responsible for ensuring that this vector contains the transitive closure of all included compunits. */ - struct compunit_symtab **includes = nullptr; + std::vector includes; /* If this is an included compunit, this points to one includer of the table. This user is considered the canonical compunit -- 2.52.0