From patchwork Mon Dec 19 16:45:57 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 62157 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 ED5E53858035 for ; Mon, 19 Dec 2022 16:46:40 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org ED5E53858035 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1671468401; bh=c5jKEWROi4qOwSS90kwTcT0ptoKidUTzdeOI8Osa3Sc=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=kZxPo1K8C33P5pk6eOKVPRE3s56v1+/bEGXZNnABbt3EGve5yK1BsPOZP480YoFYG /17H6UsGyp18Rq9uGHOvxoGGQ66g1S9LIWZTlkQUWsnSPg+3O5oABG2uylxA7jyKPk R/eFXx4qjgnC4K1s2ZMv+pHrwwJfi0hXxH8llJTA= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-il1-x12e.google.com (mail-il1-x12e.google.com [IPv6:2607:f8b0:4864:20::12e]) by sourceware.org (Postfix) with ESMTPS id B6C1B3858D32 for ; Mon, 19 Dec 2022 16:46:09 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org B6C1B3858D32 Received: by mail-il1-x12e.google.com with SMTP id i25so5005141ila.8 for ; Mon, 19 Dec 2022 08:46:09 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=c5jKEWROi4qOwSS90kwTcT0ptoKidUTzdeOI8Osa3Sc=; b=ZWY7nrWYtC+k8YmzhkDqs21eucNCqzvCfLTlfe4WPKLdAniiafXTaJBREfvVhnSG4v tTjGM1khMaZmeSyW7AtrfUcgp+ZKXNxfH8JY2WmBGoI28s7dKPb2Ll+NiAYwnoFBkD73 WzYiexKjr0IO7VIQQv2NIjdoa90OipPi18tPZb2WUL2K3R9FkLX/umIy8HDyLuu+mN6V 1ieoLKevlkX0gj8QZUhOkilTYajNtCtUuO0M3cnBvxOqVlcjdH26agfnOCL3+KAY+GPb xUiN/SgOpl5kf4oYKYZlWvmTTw53AQQyahRf6dbv5CDaeRIKBn51QZmP3mUVw/Ya7bYL iJXQ== X-Gm-Message-State: ANoB5pnNtTnv5PGBsQOACH0Kor5TGXNLmgKoCFvqPCM0/iCpg7y2mUfL oNgWoQXqESWnZmGFAUYLQqM5+tuGjqep/OG1 X-Google-Smtp-Source: AA0mqf6zD35uG8ejEkNXU2QwoO3QE6Sc/rBNjdNXAkopYY+gHW1wSSm7v3BGOTCmNszeQK6hTv4BsA== X-Received: by 2002:a92:2904:0:b0:302:f5cf:ec8a with SMTP id l4-20020a922904000000b00302f5cfec8amr24099917ilg.18.1671468367626; Mon, 19 Dec 2022 08:46:07 -0800 (PST) Received: from localhost.localdomain (97-122-76-186.hlrn.qwest.net. [97.122.76.186]) by smtp.gmail.com with ESMTPSA id x22-20020a056638027600b00363fe31cf55sm3645787jaq.40.2022.12.19.08.46.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Dec 2022 08:46:07 -0800 (PST) To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH v3 1/2] Only use the per-BFD object to write a DWARF index Date: Mon, 19 Dec 2022 09:45:57 -0700 Message-Id: <20221219164558.378363-2-tromey@adacore.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221219164558.378363-1-tromey@adacore.com> References: <20221219164558.378363-1-tromey@adacore.com> MIME-Version: 1.0 X-Spam-Status: No, score=-10.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, OBFU_UNSUB_UL, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP 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.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Tom Tromey via Gdb-patches From: Tom Tromey Reply-To: Tom Tromey Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" The DWARF index does not need access to the objfile or per-objfile objects when writing -- it's entirely based on the objfile-independent per-BFD data. This patch implements this idea by changing the entire API to only be passed the per-BFD object. This simplifies some lifetime reasoning for the next patch. This patch removes some code that ensures that the BFD came from a file. It seems to me that checking for the existence of a build-id is good enough for the index cache. --- gdb/dwarf2/index-cache.c | 20 ++++------ gdb/dwarf2/index-cache.h | 4 +- gdb/dwarf2/index-write.c | 81 ++++++++++++++++++---------------------- gdb/dwarf2/index-write.h | 2 +- gdb/dwarf2/read.c | 2 +- 5 files changed, 48 insertions(+), 61 deletions(-) diff --git a/gdb/dwarf2/index-cache.c b/gdb/dwarf2/index-cache.c index 6de58592050..b2902de5dcd 100644 --- a/gdb/dwarf2/index-cache.c +++ b/gdb/dwarf2/index-cache.c @@ -89,23 +89,17 @@ index_cache::disable () /* See dwarf-index-cache.h. */ void -index_cache::store (dwarf2_per_objfile *per_objfile) +index_cache::store (dwarf2_per_bfd *per_bfd) { - objfile *obj = per_objfile->objfile; - if (!enabled ()) return; - /* If the objfile does not correspond to an actual file, skip it. */ - if ((obj->flags & OBJF_NOT_FILENAME) != 0) - return; - /* Get build id of objfile. */ - const bfd_build_id *build_id = build_id_bfd_get (obj->obfd.get ()); + const bfd_build_id *build_id = build_id_bfd_get (per_bfd->obfd); if (build_id == nullptr) { index_cache_debug ("objfile %s has no build id", - objfile_name (obj)); + bfd_get_filename (per_bfd->obfd)); return; } @@ -113,7 +107,7 @@ index_cache::store (dwarf2_per_objfile *per_objfile) /* Get build id of dwz file, if present. */ gdb::optional dwz_build_id_str; - const dwz_file *dwz = dwarf2_get_dwz_file (per_objfile->per_bfd); + const dwz_file *dwz = dwarf2_get_dwz_file (per_bfd); const char *dwz_build_id_ptr = NULL; if (dwz != nullptr) @@ -148,18 +142,18 @@ index_cache::store (dwarf2_per_objfile *per_objfile) } index_cache_debug ("writing index cache for objfile %s", - objfile_name (obj)); + bfd_get_filename (per_bfd->obfd)); /* Write the index itself to the directory, using the build id as the filename. */ - write_dwarf_index (per_objfile, m_dir.c_str (), + write_dwarf_index (per_bfd, m_dir.c_str (), build_id_str.c_str (), dwz_build_id_ptr, dw_index_kind::GDB_INDEX); } catch (const gdb_exception_error &except) { index_cache_debug ("couldn't store index cache for objfile %s: %s", - objfile_name (obj), except.what ()); + bfd_get_filename (per_bfd->obfd), except.what ()); } } diff --git a/gdb/dwarf2/index-cache.h b/gdb/dwarf2/index-cache.h index 6366a9a9360..a6ac0112e41 100644 --- a/gdb/dwarf2/index-cache.h +++ b/gdb/dwarf2/index-cache.h @@ -24,6 +24,8 @@ #include "gdbsupport/array-view.h" #include "symfile.h" +class dwarf2_per_bfd; + /* Base of the classes used to hold the resources of the indices loaded from the cache (e.g. mmapped files). */ @@ -53,7 +55,7 @@ class index_cache void disable (); /* Store an index for the specified object file in the cache. */ - void store (dwarf2_per_objfile *per_objfile); + void store (dwarf2_per_bfd *per_bfd); /* Look for an index file matching BUILD_ID. If found, return the contents as an array_view and store the underlying resources (allocated memory, diff --git a/gdb/dwarf2/index-write.c b/gdb/dwarf2/index-write.c index 3d215a6307b..a63c461da0b 100644 --- a/gdb/dwarf2/index-write.c +++ b/gdb/dwarf2/index-write.c @@ -522,7 +522,7 @@ write_address_map (struct addrmap *addrmap, data_buf &addr_vec, class debug_names { public: - debug_names (dwarf2_per_objfile *per_objfile, bool is_dwarf64, + debug_names (dwarf2_per_bfd *per_bfd, bool is_dwarf64, bfd_endian dwarf5_byte_order) : m_dwarf5_byte_order (dwarf5_byte_order), m_dwarf32 (dwarf5_byte_order), @@ -532,7 +532,7 @@ class debug_names : static_cast (m_dwarf32)), m_name_table_string_offs (m_dwarf.name_table_string_offs), m_name_table_entry_offs (m_dwarf.name_table_entry_offs), - m_debugstrlookup (per_objfile) + m_debugstrlookup (per_bfd) {} int dwarf5_offset_size () const @@ -785,23 +785,23 @@ class debug_names { public: - /* Object constructor to be called for current DWARF2_PER_OBJFILE. + /* Object constructor to be called for current DWARF2_PER_BFD. All .debug_str section strings are automatically stored. */ - debug_str_lookup (dwarf2_per_objfile *per_objfile) - : m_abfd (per_objfile->objfile->obfd.get ()), - m_per_objfile (per_objfile) + debug_str_lookup (dwarf2_per_bfd *per_bfd) + : m_abfd (per_bfd->obfd), + m_per_bfd (per_bfd) { - per_objfile->per_bfd->str.read (per_objfile->objfile); - if (per_objfile->per_bfd->str.buffer == NULL) + gdb_assert (per_bfd->str.readin); + if (per_bfd->str.buffer == NULL) return; - for (const gdb_byte *data = per_objfile->per_bfd->str.buffer; - data < (per_objfile->per_bfd->str.buffer - + per_objfile->per_bfd->str.size);) + for (const gdb_byte *data = per_bfd->str.buffer; + data < (per_bfd->str.buffer + + per_bfd->str.size);) { const char *const s = reinterpret_cast (data); const auto insertpair = m_str_table.emplace (c_str_view (s), - data - per_objfile->per_bfd->str.buffer); + data - per_bfd->str.buffer); if (!insertpair.second) complaint (_("Duplicate string \"%s\" in " ".debug_str section [in module %s]"), @@ -818,7 +818,7 @@ class debug_names const auto it = m_str_table.find (c_str_view (s)); if (it != m_str_table.end ()) return it->second; - const size_t offset = (m_per_objfile->per_bfd->str.size + const size_t offset = (m_per_bfd->str.size + m_str_add_buf.size ()); m_str_table.emplace (c_str_view (s), offset); m_str_add_buf.append_cstr0 (s); @@ -834,7 +834,7 @@ class debug_names private: std::unordered_map m_str_table; bfd *const m_abfd; - dwarf2_per_objfile *m_per_objfile; + dwarf2_per_bfd *m_per_bfd; /* Data to add at the end of .debug_str for new needed symbol names. */ data_buf m_str_add_buf; @@ -1046,9 +1046,9 @@ class debug_names .debug_names section. */ static bool -check_dwarf64_offsets (dwarf2_per_objfile *per_objfile) +check_dwarf64_offsets (dwarf2_per_bfd *per_bfd) { - for (const auto &per_cu : per_objfile->per_bfd->all_units) + for (const auto &per_cu : per_bfd->all_units) { if (to_underlying (per_cu->sect_off) >= (static_cast (1) << 32)) @@ -1197,7 +1197,7 @@ write_cooked_index (cooked_index_vector *table, associated dwz file, DWZ_OUT_FILE must be NULL. */ static void -write_gdbindex (dwarf2_per_objfile *per_objfile, +write_gdbindex (dwarf2_per_bfd *per_bfd, cooked_index_vector *table, FILE *out_file, FILE *dwz_out_file) { @@ -1210,7 +1210,7 @@ write_gdbindex (dwarf2_per_objfile *per_objfile, in the index file). This will later be needed to write the address table. */ cu_index_map cu_index_htab; - cu_index_htab.reserve (per_objfile->per_bfd->all_units.size ()); + cu_index_htab.reserve (per_bfd->all_units.size ()); /* Store out the .debug_type CUs, if any. */ data_buf types_cu_list; @@ -1221,10 +1221,9 @@ write_gdbindex (dwarf2_per_objfile *per_objfile, int counter = 0; int types_counter = 0; - for (int i = 0; i < per_objfile->per_bfd->all_units.size (); ++i) + for (int i = 0; i < per_bfd->all_units.size (); ++i) { - dwarf2_per_cu_data *per_cu - = per_objfile->per_bfd->all_units[i].get (); + dwarf2_per_cu_data *per_cu = per_bfd->all_units[i].get (); int &this_counter = per_cu->is_debug_types ? types_counter : counter; @@ -1287,27 +1286,25 @@ static const gdb_byte dwarf5_gdb_augmentation[] = { 'G', 'D', 'B', 0 }; many bytes were expected to be written into OUT_FILE. */ static void -write_debug_names (dwarf2_per_objfile *per_objfile, +write_debug_names (dwarf2_per_bfd *per_bfd, cooked_index_vector *table, FILE *out_file, FILE *out_file_str) { - const bool dwarf5_is_dwarf64 = check_dwarf64_offsets (per_objfile); - struct objfile *objfile = per_objfile->objfile; + const bool dwarf5_is_dwarf64 = check_dwarf64_offsets (per_bfd); const enum bfd_endian dwarf5_byte_order - = gdbarch_byte_order (objfile->arch ()); + = bfd_big_endian (per_bfd->obfd) ? BFD_ENDIAN_BIG : BFD_ENDIAN_LITTLE; /* The CU list is already sorted, so we don't need to do additional work here. Also, the debug_types entries do not appear in all_units, but only in their own hash table. */ data_buf cu_list; data_buf types_cu_list; - debug_names nametable (per_objfile, dwarf5_is_dwarf64, dwarf5_byte_order); + debug_names nametable (per_bfd, dwarf5_is_dwarf64, dwarf5_byte_order); int counter = 0; int types_counter = 0; - for (int i = 0; i < per_objfile->per_bfd->all_units.size (); ++i) + for (int i = 0; i < per_bfd->all_units.size (); ++i) { - dwarf2_per_cu_data *per_cu - = per_objfile->per_bfd->all_units[i].get (); + dwarf2_per_cu_data *per_cu = per_bfd->all_units[i].get (); int &this_counter = per_cu->is_debug_types ? types_counter : counter; data_buf &this_list = per_cu->is_debug_types ? types_cu_list : cu_list; @@ -1320,8 +1317,8 @@ write_debug_names (dwarf2_per_objfile *per_objfile, } /* Verify that all units are represented. */ - gdb_assert (counter == per_objfile->per_bfd->all_comp_units.size ()); - gdb_assert (types_counter == per_objfile->per_bfd->all_type_units.size ()); + gdb_assert (counter == per_bfd->all_units.size ()); + gdb_assert (types_counter == per_bfd->all_type_units.size ()); for (const cooked_index_entry *entry : table->all_entries ()) nametable.insert (entry); @@ -1454,23 +1451,17 @@ struct index_wip_file /* See dwarf-index-write.h. */ void -write_dwarf_index (dwarf2_per_objfile *per_objfile, const char *dir, +write_dwarf_index (dwarf2_per_bfd *per_bfd, const char *dir, const char *basename, const char *dwz_basename, dw_index_kind index_kind) { - struct objfile *objfile = per_objfile->objfile; - - if (per_objfile->per_bfd->index_table == nullptr) + if (per_bfd->index_table == nullptr) error (_("No debugging symbols")); - cooked_index_vector *table - = per_objfile->per_bfd->index_table->index_for_writing (); + cooked_index_vector *table = per_bfd->index_table->index_for_writing (); - if (per_objfile->per_bfd->types.size () > 1) + if (per_bfd->types.size () > 1) error (_("Cannot make an index when the file has multiple .debug_types sections")); - - gdb_assert ((objfile->flags & OBJF_NOT_FILENAME) == 0); - const char *index_suffix = (index_kind == dw_index_kind::DEBUG_NAMES ? INDEX5_SUFFIX : INDEX4_SUFFIX); @@ -1484,13 +1475,13 @@ write_dwarf_index (dwarf2_per_objfile *per_objfile, const char *dir, { index_wip_file str_wip_file (dir, basename, DEBUG_STR_SUFFIX); - write_debug_names (per_objfile, table, objfile_index_wip.out_file.get (), + write_debug_names (per_bfd, table, objfile_index_wip.out_file.get (), str_wip_file.out_file.get ()); str_wip_file.finalize (); } else - write_gdbindex (per_objfile, table, objfile_index_wip.out_file.get (), + write_gdbindex (per_bfd, table, objfile_index_wip.out_file.get (), (dwz_index_wip.has_value () ? dwz_index_wip->out_file.get () : NULL)); @@ -1545,8 +1536,8 @@ save_gdb_index_command (const char *arg, int from_tty) if (dwz != NULL) dwz_basename = lbasename (dwz->filename ()); - write_dwarf_index (per_objfile, arg, basename, dwz_basename, - index_kind); + write_dwarf_index (per_objfile->per_bfd, arg, basename, + dwz_basename, index_kind); } catch (const gdb_exception_error &except) { diff --git a/gdb/dwarf2/index-write.h b/gdb/dwarf2/index-write.h index b8855dcae7c..3a9c1432c7f 100644 --- a/gdb/dwarf2/index-write.h +++ b/gdb/dwarf2/index-write.h @@ -33,7 +33,7 @@ same, but for the dwz file's index. */ extern void write_dwarf_index - (dwarf2_per_objfile *per_objfile, const char *dir, const char *basename, + (dwarf2_per_bfd *per_bfd, const char *dir, const char *basename, const char *dwz_basename, dw_index_kind index_kind); #endif /* DWARF_INDEX_WRITE_H */ diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c index ddea38cf596..fc8239b4261 100644 --- a/gdb/dwarf2/read.c +++ b/gdb/dwarf2/read.c @@ -5434,7 +5434,7 @@ dwarf2_build_psymtabs (struct objfile *objfile) dwarf2_build_psymtabs_hard (per_objfile); /* (maybe) store an index in the cache. */ - global_index_cache.store (per_objfile); + global_index_cache.store (per_objfile->per_bfd); } catch (const gdb_exception_error &except) {