From patchwork Wed Jan 17 16:39:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 84266 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 811963857C4D for ; Wed, 17 Jan 2024 16:41:12 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from omta036.useast.a.cloudfilter.net (omta036.useast.a.cloudfilter.net [44.202.169.35]) by sourceware.org (Postfix) with ESMTPS id DE36C3858C66 for ; Wed, 17 Jan 2024 16:39:38 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org DE36C3858C66 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=tromey.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=tromey.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org DE36C3858C66 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=44.202.169.35 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1705509581; cv=none; b=LkKmSqXLemJOfuh8xwsMD3XvpfI20C5iSe4OjGyW2GVe+gT7stMCN5dEGqXD14C2BpcmWFccjsTu0ep8HyQwvopWZIEGCrsu616FT5sOgBP161HLgJBVRo50mqXBnRRwJZe55E/h8aLNhEruS3bSrr3dy7OBm7SVkFNclNW7sfY= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1705509581; c=relaxed/simple; bh=ImMkScJSbRLthpFDvIOm/ZaXHYrW/ltikvfOLV7R7+w=; h=DKIM-Signature:From:Date:Subject:MIME-Version:Message-Id:To; b=Fmst68Sk8XLFZtUIEU8/37NTmCHFAhkEEAhGsjyL4QfPk/gywCrDvwnmQp8cXU1++vktP5WPuygpX/N4WS5Q034VQtza3C8yGqRtEjP08zKAOvAHhqUQxBbWTf5E7RFG+zQhbJ20Abk511H+cm3d5e9axVGf9RA4q34G0DWJQfw= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from eig-obgw-6007a.ext.cloudfilter.net ([10.0.30.247]) by cmsmtp with ESMTPS id Pw9sr8ZBr8uLRQ8x0riXzZ; Wed, 17 Jan 2024 16:39:38 +0000 Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with ESMTPS id Q8wzr5k8lyxR5Q8wzrmxZ0; Wed, 17 Jan 2024 16:39:38 +0000 X-Authority-Analysis: v=2.4 cv=JYOvEGGV c=1 sm=1 tr=0 ts=65a802ca a=ApxJNpeYhEAb1aAlGBBbmA==:117 a=ApxJNpeYhEAb1aAlGBBbmA==:17 a=OWjo9vPv0XrRhIrVQ50Ab3nP57M=:19 a=dLZJa+xiwSxG16/P+YVxDGlgEgI=:19 a=IkcTkHD0fZMA:10 a=dEuoMetlWLkA:10 a=Qbun_eYptAEA:10 a=WFHUNgFRegjDTDzTyKkA:9 a=QEXdDO2ut3YA:10 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tromey.com; s=default; h=To:In-Reply-To:References:Message-Id:Content-Transfer-Encoding: Content-Type:MIME-Version:Subject:Date:From:Sender:Reply-To:Cc:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=XBp6gtRgXQ54f6kVLWLrK63smXiWzm1JUJcJz7xBUr8=; b=v48ZV4x3Qb/kFsqzzFqiWA5+GA qHaRoPC/9c4xElJ6nJ/XtYI2BudsM+5+nmYfQSbVDVG9TiBrOVRV9VuYSdB9tLduBYTJCUi9eBzh+ jpSsz3Ow95OR+76pMkfw1MOqc; Received: from 97-122-68-157.hlrn.qwest.net ([97.122.68.157]:56636 helo=[192.168.0.21]) by box5379.bluehost.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96.2) (envelope-from ) id 1rQ8wz-002OXE-1F for gdb-patches@sourceware.org; Wed, 17 Jan 2024 09:39:37 -0700 From: Tom Tromey Date: Wed, 17 Jan 2024 09:39:33 -0700 Subject: [PATCH v2 05/17] Add language to cooked_index_entry MIME-Version: 1.0 Message-Id: <20240117-debug-names-fix-v2-5-dbd5971a9c31@tromey.com> References: <20240117-debug-names-fix-v2-0-dbd5971a9c31@tromey.com> In-Reply-To: <20240117-debug-names-fix-v2-0-dbd5971a9c31@tromey.com> To: gdb-patches@sourceware.org X-Mailer: b4 0.12.4 X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - box5379.bluehost.com X-AntiAbuse: Original Domain - sourceware.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - tromey.com X-BWhitelist: no X-Source-IP: 97.122.68.157 X-Source-L: No X-Exim-ID: 1rQ8wz-002OXE-1F X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: 97-122-68-157.hlrn.qwest.net ([192.168.0.21]) [97.122.68.157]:56636 X-Source-Auth: tom+tromey.com X-Email-Count: 10 X-Org: HG=bhshared;ORG=bluehost; X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes X-CMAE-Envelope: MS4xfI1PZi01I2jj9K8wFgsYYcIVRIwDGDvaiV5EZg1yp7XMoHTCCvHoBiJcSQbLWM1+/LCXYiSp3Vy2W6so22sGnGRwuXOGetNDLA6K9gO+o7YpXmKEozjb uTRnS86xKw6C9oQYf+wvVfUwDNFQsYFphDaLUcxOSEdtuTYrfG8oxC6pWiuZycpt1U1kkhA3d5s/FHaqCKRhkyNUmkojXMg70SQ= X-Spam-Status: No, score=-3022.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, JMQ_SPF_NEUTRAL, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_PASS, 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 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 This adds a new 'lang' member to cooked_index_entry. This holds the language of the symbol. This is primarily useful for the new .debug_names reader, which will not scan the CUs for languages up front. This also changes cooked_index_shard::add to return a non-const pointer. This doesn't impact the current code, but is needed for the new reader. --- gdb/dwarf2/cooked-index.c | 22 +++++++++++----------- gdb/dwarf2/cooked-index.h | 14 ++++++++++---- gdb/dwarf2/index-write.c | 4 ++-- 3 files changed, 23 insertions(+), 17 deletions(-) diff --git a/gdb/dwarf2/cooked-index.c b/gdb/dwarf2/cooked-index.c index f15ae9c28df..54c622977b1 100644 --- a/gdb/dwarf2/cooked-index.c +++ b/gdb/dwarf2/cooked-index.c @@ -207,7 +207,7 @@ cooked_index_entry::full_name (struct obstack *storage, bool for_main) const return local_name; const char *sep = nullptr; - switch (per_cu->lang ()) + switch (lang) { case language_cplus: case language_rust: @@ -247,11 +247,12 @@ cooked_index_entry::write_scope (struct obstack *storage, cooked_index_entry * cooked_index_shard::add (sect_offset die_offset, enum dwarf_tag tag, - cooked_index_flag flags, const char *name, + cooked_index_flag flags, enum language lang, + const char *name, cooked_index_entry_ref parent_entry, dwarf2_per_cu_data *per_cu) { - cooked_index_entry *result = create (die_offset, tag, flags, name, + cooked_index_entry *result = create (die_offset, tag, flags, lang, name, parent_entry, per_cu); m_entries.push_back (result); @@ -262,7 +263,7 @@ cooked_index_shard::add (sect_offset die_offset, enum dwarf_tag tag, else if ((flags & IS_PARENT_DEFERRED) == 0 && parent_entry.resolved == nullptr && m_main == nullptr - && language_may_use_plain_main (per_cu->lang ()) + && language_may_use_plain_main (lang) && strcmp (name, "main") == 0) m_main = result; @@ -301,7 +302,7 @@ cooked_index_shard::handle_gnat_encoded_entry (cooked_index_entry *entry, gdb::unique_xmalloc_ptr new_name = make_unique_xstrndup (name.data (), name.length ()); last = create (entry->die_offset, DW_TAG_namespace, - 0, new_name.get (), parent, + 0, language_ada, new_name.get (), parent, entry->per_cu); last->canonical = last->name; m_names.push_back (std::move (new_name)); @@ -364,7 +365,7 @@ cooked_index_shard::finalize () gdb_assert (entry->canonical == nullptr); if ((entry->flags & IS_LINKAGE) != 0) entry->canonical = entry->name; - else if (entry->per_cu->lang () == language_ada) + else if (entry->lang == language_ada) { gdb::unique_xmalloc_ptr canon_name = handle_gnat_encoded_entry (entry, gnat_entries.get ()); @@ -376,15 +377,14 @@ cooked_index_shard::finalize () m_names.push_back (std::move (canon_name)); } } - else if (entry->per_cu->lang () == language_cplus - || entry->per_cu->lang () == language_c) + else if (entry->lang == language_cplus || entry->lang == language_c) { void **slot = htab_find_slot (seen_names.get (), entry, INSERT); if (*slot == nullptr) { gdb::unique_xmalloc_ptr canon_name - = (entry->per_cu->lang () == language_cplus + = (entry->lang == language_cplus ? cp_canonicalize_string (entry->name) : c_canonicalize_name (entry->name)); if (canon_name == nullptr) @@ -572,7 +572,7 @@ cooked_index::get_main_name (struct obstack *obstack, enum language *lang) if (entry == nullptr) return nullptr; - *lang = entry->per_cu->lang (); + *lang = entry->lang; return entry->full_name (obstack, true); } @@ -595,7 +595,7 @@ cooked_index::get_main () const { if ((entry->flags & IS_MAIN) != 0) { - if (!language_requires_canonicalization (entry->per_cu->lang ())) + if (!language_requires_canonicalization (entry->lang)) { /* There won't be one better than this. */ return entry; diff --git a/gdb/dwarf2/cooked-index.h b/gdb/dwarf2/cooked-index.h index 691a027704a..6caa8132f53 100644 --- a/gdb/dwarf2/cooked-index.h +++ b/gdb/dwarf2/cooked-index.h @@ -107,12 +107,14 @@ extern bool language_requires_canonicalization (enum language lang); struct cooked_index_entry : public allocate_on_obstack { cooked_index_entry (sect_offset die_offset_, enum dwarf_tag tag_, - cooked_index_flag flags_, const char *name_, + cooked_index_flag flags_, + enum language lang_, const char *name_, cooked_index_entry_ref parent_entry_, dwarf2_per_cu_data *per_cu_) : name (name_), tag (tag_), flags (flags_), + lang (lang_), die_offset (die_offset_), per_cu (per_cu_), m_parent_entry (parent_entry_) @@ -281,6 +283,8 @@ struct cooked_index_entry : public allocate_on_obstack enum dwarf_tag tag; /* Any flags attached to this entry. */ cooked_index_flag flags; + /* The language of this symbol. */ + ENUM_BITFIELD (language) lang : LANGUAGE_BITS; /* The offset of this DIE. */ sect_offset die_offset; /* The CU from which this entry originates. */ @@ -318,7 +322,7 @@ class cooked_index_shard /* Create a new cooked_index_entry and register it with this object. Entries are owned by this object. The new item is returned. */ cooked_index_entry *add (sect_offset die_offset, enum dwarf_tag tag, - cooked_index_flag flags, + cooked_index_flag flags, enum language lang, const char *name, cooked_index_entry_ref parent_entry, dwarf2_per_cu_data *per_cu); @@ -370,12 +374,13 @@ class cooked_index_shard cooked_index_entry *create (sect_offset die_offset, enum dwarf_tag tag, cooked_index_flag flags, + enum language lang, const char *name, cooked_index_entry_ref parent_entry, dwarf2_per_cu_data *per_cu) { return new (&m_storage) cooked_index_entry (die_offset, tag, flags, - name, parent_entry, + lang, name, parent_entry, per_cu); } @@ -439,7 +444,8 @@ class cooked_index_storage cooked_index_entry_ref parent_entry, dwarf2_per_cu_data *per_cu) { - return m_index->add (die_offset, tag, flags, name, parent_entry, per_cu); + return m_index->add (die_offset, tag, flags, per_cu->lang (), + name, parent_entry, per_cu); } /* Install the current addrmap into the shard being constructed, diff --git a/gdb/dwarf2/index-write.c b/gdb/dwarf2/index-write.c index 081046d4237..2decee62a4c 100644 --- a/gdb/dwarf2/index-write.c +++ b/gdb/dwarf2/index-write.c @@ -1282,7 +1282,7 @@ write_cooked_index (cooked_index *table, const char *name = entry->full_name (symtab->obstack ()); - if (entry->per_cu->lang () == language_ada) + if (entry->lang == language_ada) { /* In order for the index to work when read back into gdb, it has to use the encoded name, with any @@ -1290,7 +1290,7 @@ write_cooked_index (cooked_index *table, std::string encoded = ada_encode (name, false); name = obstack_strdup (symtab->obstack (), encoded.c_str ()); } - else if (entry->per_cu->lang () == language_cplus + else if (entry->lang == language_cplus && (entry->flags & IS_LINKAGE) != 0) { /* GDB never put C++ linkage names into .gdb_index. The