From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from omta040.useast.a.cloudfilter.net (omta040.useast.a.cloudfilter.net [44.202.169.39]) by sourceware.org (Postfix) with ESMTPS id 390F93858C66 for ; Wed, 17 Jan 2024 18:59:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 390F93858C66 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 390F93858C66 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=44.202.169.39 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1705517945; cv=none; b=emzpeVOniPjoulQIHiH01gcADHMy1anu++buEY+3vFgAPUy3/qXz3hteepr0BaEFzRHphDXUHtdvQuZszuDb2AMAtEeZwKc/ku74JQnKBjm4Gngn6Lwu0nQLRNjZMA8JcZwthkmqZ76yOLmBnpGgv8Ttim9WHPXp7czzLPguV6E= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1705517945; c=relaxed/simple; bh=ZfTJ4LD/c5YDaJxmBiUaTqUoT4MiVpXY052+n8R0h/A=; h=DKIM-Signature:From:Date:Subject:MIME-Version:Message-Id:To; b=DFzH29a+OLI67MhxOedJgxoRBM/mbtUhlGhmv8c5lFcDKt+Vjr/1CxMUkgu3rmkXZWLQOuIKlgNW2UhKHKdaZznacVGaNhuDE0u7QWo+C7MtwVbDvt1FirFSW5ZSAhARghAoHE2Ee3YfQwVb+oD8Tdj/xzBBfGlBNMploys0eu8= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from eig-obgw-5008a.ext.cloudfilter.net ([10.0.29.246]) by cmsmtp with ESMTPS id Q6vyrLA2BTHHuQB7vrxT0I; Wed, 17 Jan 2024 18:59:03 +0000 Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with ESMTPS id QB7trs4nML3AmQB7urRFOt; Wed, 17 Jan 2024 18:59:02 +0000 X-Authority-Analysis: v=2.4 cv=Sdrky9du c=1 sm=1 tr=0 ts=65a82376 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=mDV3o1hIAAAA:8 a=Q54NkQ1-krxB2HtNLs4A:9 a=QEXdDO2ut3YA:10 a=_FVE-zBwftR9WsbkzFJk:22 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tromey.com; s=default; h=Cc:To:In-Reply-To:References:Message-Id: Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date:From:Sender: Reply-To: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=a5cSvSDVBwSPzyrAl2Ctz/lMGTNf1E73fDrJtCjsgVk=; b=UXdV7fRYHQnEMNjKkNdHmc/1K7 KCYSi8me4vjNGM9mmc6fW52U440XhUqJJUZiNYmMYWlZb+Y4m/f/l5M2aivnZ65FNt2fYjrLTqNTo Kq32Ck4H/v1pCL5s9fSkKtlm4; Received: from 97-122-68-157.hlrn.qwest.net ([97.122.68.157]:45122 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 1rQB7t-004FFp-0s; Wed, 17 Jan 2024 11:59:01 -0700 From: Tom Tromey Date: Wed, 17 Jan 2024 11:58:51 -0700 Subject: [PATCH 4/7] Introduce class parent_map for DIE range map MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20240117-die-map-madness-v1-4-42fb435ad1ed@tromey.com> References: <20240117-die-map-madness-v1-0-42fb435ad1ed@tromey.com> In-Reply-To: <20240117-die-map-madness-v1-0-42fb435ad1ed@tromey.com> To: gdb-patches@sourceware.org Cc: Tom de Vries 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: 1rQB7t-004FFp-0s 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]:45122 X-Source-Auth: tom+tromey.com X-Email-Count: 7 X-Org: HG=bhshared;ORG=bluehost; X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes X-CMAE-Envelope: MS4xfM4xRIDCmvd72kvvxOR7RZC6qK7D0E2ueva+4C4XX3QtCnT2xZcJ+9QJSqhEhgjqM/KxnOEKaeSDtcoxkjPWJ2AauA4spRnENI5V5SR6HBqBsmmBXIs2 CJ7y0+X5WF1Z2VOq3T/Gu/iWNrOLOp2qVQONmjesZuGpGiuNvRtKCKyLrDnaYEs3WenZLIAIrZGWafc8oqZvkBAb5mAsCY7wVnM= X-Spam-Status: No, score=-3022.7 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,GIT_PATCH_0,JMQ_SPF_NEUTRAL,KAM_SHORT,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 List-Id: This changes the DIE range map from a raw addrmap to a custom class. A new type is used to represent the ranges, in an attempt to gain a little type safety as well. Note that the new code includes a map-of-maps type. This is not used yet, but will be used in the next patch. Co-Authored-By: Tom de Vries --- gdb/dwarf2/cooked-index.h | 7 +-- gdb/dwarf2/parent-map.h | 132 ++++++++++++++++++++++++++++++++++++++++++++++ gdb/dwarf2/read.c | 46 +++++++--------- 3 files changed, 154 insertions(+), 31 deletions(-) diff --git a/gdb/dwarf2/cooked-index.h b/gdb/dwarf2/cooked-index.h index ebaed04753c..442ee9e14fd 100644 --- a/gdb/dwarf2/cooked-index.h +++ b/gdb/dwarf2/cooked-index.h @@ -35,6 +35,7 @@ #include "dwarf2/read.h" #include "dwarf2/tag.h" #include "dwarf2/abbrev-cache.h" +#include "dwarf2/parent-map.h" #include "gdbsupport/range-chain.h" #include "gdbsupport/task-group.h" #include "complaints.h" @@ -74,7 +75,7 @@ DEF_ENUM_FLAGS_TYPE (enum cooked_index_flag_enum, cooked_index_flag); union cooked_index_entry_ref { - cooked_index_entry_ref (CORE_ADDR deferred_) + cooked_index_entry_ref (parent_map::addr_type deferred_) { deferred = deferred_; } @@ -85,7 +86,7 @@ union cooked_index_entry_ref } const cooked_index_entry *resolved; - CORE_ADDR deferred; + parent_map::addr_type deferred; }; /* Return a string representation of FLAGS. */ @@ -265,7 +266,7 @@ struct cooked_index_entry : public allocate_on_obstack } /* Return deferred parent entry. */ - CORE_ADDR get_deferred_parent () const + parent_map::addr_type get_deferred_parent () const { gdb_assert ((flags & IS_PARENT_DEFERRED) != 0); return m_parent_entry.deferred; diff --git a/gdb/dwarf2/parent-map.h b/gdb/dwarf2/parent-map.h new file mode 100644 index 00000000000..f070d505356 --- /dev/null +++ b/gdb/dwarf2/parent-map.h @@ -0,0 +1,132 @@ +/* DIE indexing + + Copyright (C) 2024 Free Software Foundation, Inc. + + This file is part of GDB. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +#ifndef GDB_DWARF2_PARENT_MAP_H +#define GDB_DWARF2_PARENT_MAP_H + +#include + +class cooked_index_entry; + +/* A class that handles mapping from a DIE range to a parent + entry. + + The generated DWARF can sometimes have the declaration for a method + in a class (or perhaps namespace) scope, with the definition + appearing outside this scope... just one of the many bad things + about DWARF. In order to handle this situation, we defer certain + entries until the end of scanning, at which point we'll know the + containing context of all the DIEs that we might have scanned. */ +class parent_map +{ +public: + + parent_map () = default; + ~parent_map () = default; + + /* Move only. */ + DISABLE_COPY_AND_ASSIGN (parent_map); + parent_map (parent_map &&) = default; + parent_map &operator= (parent_map &&) = default; + + /* A reasonably opaque type that is used here to combine a section + offset and the 'dwz' flag into a single value. */ + enum addr_type : CORE_ADDR { }; + + /* Turn a section offset into a value that can be used in a parent + map. */ + static addr_type form_addr (sect_offset offset, bool is_dwz) + { + CORE_ADDR value = to_underlying (offset); + if (is_dwz) + value |= ((CORE_ADDR) 1) << (8 * sizeof (CORE_ADDR) - 1); + return addr_type (value); + } + + /* Add a new entry to this map. DIEs from START to END, inclusive, + are mapped to PARENT. */ + void add_entry (addr_type start, addr_type end, + const cooked_index_entry *parent) + { + gdb_assert (parent != nullptr); + m_map.set_empty (start, end, (void *) parent); + } + + /* Look up an entry in this map. */ + const cooked_index_entry *find (addr_type search) const + { + return static_cast (m_map.find (search)); + } + + /* Return a fixed addrmap that is equivalent to this map. */ + addrmap_fixed *to_fixed (struct obstack *obstack) const + { + return new (obstack) addrmap_fixed (obstack, &m_map); + } + +private: + + /* An addrmap that maps from section offsets to cooked_index_entry *. */ + addrmap_mutable m_map; +}; + +/* Keep a collection of parent_map objects, and allow for lookups + across all of them. */ +class parent_map_map +{ +public: + + parent_map_map () = default; + ~parent_map_map () = default; + + DISABLE_COPY_AND_ASSIGN (parent_map_map); + + /* Add a parent_map to this map. */ + void add_map (const parent_map &map) + { + m_maps.push_back (map.to_fixed (&m_storage)); + } + + /* Look up an entry in this map. */ + const cooked_index_entry *find (parent_map::addr_type search) const + { + for (const auto &iter : m_maps) + { + const cooked_index_entry *result + = static_cast (iter->find (search)); + if (result != nullptr) + return result; + } + return nullptr; + } + +private: + + /* Storage for the convert maps. */ + auto_obstack m_storage; + + /* While conceptually this class is a combination of parent_maps, in + practice it is just a number of fixed maps. This is important + because we want to allow concurrent lookups, but a mutable + addrmap is based on a splay-tree, which is not thread-safe, even + for nominally read-only lookups. */ + std::vector m_maps; +}; + +#endif /* GDB_DWARF2_PARENT_MAP_H */ diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c index bf64d89ef3c..585c15212f8 100644 --- a/gdb/dwarf2/read.c +++ b/gdb/dwarf2/read.c @@ -96,6 +96,7 @@ #include "split-name.h" #include "gdbsupport/thread-pool.h" #include "run-on-main-thread.h" +#include "dwarf2/parent-map.h" /* When == 1, print basic high level tracing messages. When > 1, be more verbose. @@ -4473,16 +4474,6 @@ class cooked_indexer private: - /* A helper function to turn a section offset into an address that - can be used in an addrmap. */ - CORE_ADDR form_addr (sect_offset offset, bool is_dwz) - { - CORE_ADDR value = to_underlying (offset); - if (is_dwz) - value |= ((CORE_ADDR) 1) << (8 * sizeof (CORE_ADDR) - 1); - return value; - } - /* A helper function to scan the PC bounds of READER and record them in the storage's addrmap. */ void check_bounds (cutu_reader *reader); @@ -4520,7 +4511,7 @@ class cooked_indexer cooked_index_flag *flags, sect_offset *sibling_offset, const cooked_index_entry **parent_entry, - CORE_ADDR *maybe_defer, + parent_map::addr_type *maybe_defer, bool for_specification); /* Handle DW_TAG_imported_unit, by scanning the DIE to find @@ -4547,10 +4538,9 @@ class cooked_indexer /* The language that we're assuming when reading. */ enum language m_language; - /* An addrmap that maps from section offsets (see the form_addr - method) to newly-created entries. See m_deferred_entries to - understand this. */ - addrmap_mutable m_die_range_map; + /* Map from DIE ranges to newly-created entries. See + m_deferred_entries to understand this. */ + parent_map m_die_range_map; /* The generated DWARF can sometimes have the declaration for a method in a class (or perhaps namespace) scope, with the @@ -16165,7 +16155,7 @@ cooked_indexer::scan_attributes (dwarf2_per_cu_data *scanning_per_cu, cooked_index_flag *flags, sect_offset *sibling_offset, const cooked_index_entry **parent_entry, - CORE_ADDR *maybe_defer, + parent_map::addr_type *maybe_defer, bool for_specification) { bool origin_is_dwz = false; @@ -16337,15 +16327,13 @@ cooked_indexer::scan_attributes (dwarf2_per_cu_data *scanning_per_cu, if (*parent_entry == nullptr) { - CORE_ADDR addr = form_addr (origin_offset, origin_is_dwz); + parent_map::addr_type addr + = parent_map::form_addr (origin_offset, origin_is_dwz); if (new_reader->cu == reader->cu && new_info_ptr > watermark_ptr) *maybe_defer = addr; else - { - void *obj = m_die_range_map.find (addr); - *parent_entry = static_cast (obj); - } + *parent_entry = m_die_range_map.find (addr); } unsigned int bytes_read; @@ -16463,11 +16451,13 @@ cooked_indexer::recurse (cutu_reader *reader, { /* Both start and end are inclusive, so use both "+ 1" and "- 1" to limit the range to the children of parent_entry. */ - CORE_ADDR start = form_addr (parent_entry->die_offset + 1, - reader->cu->per_cu->is_dwz); - CORE_ADDR end = form_addr (sect_offset (info_ptr - 1 - reader->buffer), + parent_map::addr_type start + = parent_map::form_addr (parent_entry->die_offset + 1, + reader->cu->per_cu->is_dwz); + parent_map::addr_type end + = parent_map::form_addr (sect_offset (info_ptr - 1 - reader->buffer), reader->cu->per_cu->is_dwz); - m_die_range_map.set_empty (start, end, (void *) parent_entry); + m_die_range_map.add_entry (start, end, parent_entry); } return info_ptr; @@ -16509,7 +16499,7 @@ cooked_indexer::index_dies (cutu_reader *reader, const char *name = nullptr; const char *linkage_name = nullptr; - CORE_ADDR defer = 0; + parent_map::addr_type defer {}; cooked_index_flag flags = IS_STATIC; sect_offset sibling {}; const cooked_index_entry *this_parent_entry = parent_entry; @@ -16645,8 +16635,8 @@ cooked_indexer::make_index (cutu_reader *reader) for (const auto &entry : m_deferred_entries) { - void *obj = m_die_range_map.find (entry->get_deferred_parent ()); - cooked_index_entry *parent = static_cast (obj); + const cooked_index_entry *parent + = m_die_range_map.find (entry->get_deferred_parent ()); entry->resolve_parent (parent); } } -- 2.43.0