[binutils-gdb] Refactor cooked_index_shard::handle_gnat_encoded_entry
Tom Tromey
tromey@sourceware.org
Mon Sep 9 17:42:07 GMT 2024
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=052736020af3aae80f8eddbfc8a695916cdcbb9a
commit 052736020af3aae80f8eddbfc8a695916cdcbb9a
Author: Tom Tromey <tromey@adacore.com>
Date: Tue Sep 3 12:04:18 2024 -0600
Refactor cooked_index_shard::handle_gnat_encoded_entry
This changes cooked_index_shard::handle_gnat_encoded_entry to modify
the incoming entry itself, and to return void rather than a new name.
this simplifies the caller a little, which is convenient for a
different series I am working on.
Approved-By: Tom de Vries <tdevries@suse.de>
Diff:
---
gdb/dwarf2/cooked-index.c | 23 +++++++++--------------
gdb/dwarf2/cooked-index.h | 5 ++---
2 files changed, 11 insertions(+), 17 deletions(-)
diff --git a/gdb/dwarf2/cooked-index.c b/gdb/dwarf2/cooked-index.c
index 41aa9d0da58..4073c924890 100644
--- a/gdb/dwarf2/cooked-index.c
+++ b/gdb/dwarf2/cooked-index.c
@@ -288,7 +288,7 @@ cooked_index_shard::add (sect_offset die_offset, enum dwarf_tag tag,
/* See cooked-index.h. */
-gdb::unique_xmalloc_ptr<char>
+void
cooked_index_shard::handle_gnat_encoded_entry (cooked_index_entry *entry,
htab_t gnat_entries)
{
@@ -298,7 +298,10 @@ cooked_index_shard::handle_gnat_encoded_entry (cooked_index_entry *entry,
source charset does not affect the indexer directly. */
std::string canonical = ada_decode (entry->name, false, false, false);
if (canonical.empty ())
- return {};
+ {
+ entry->canonical = entry->name;
+ return;
+ }
std::vector<std::string_view> names = split_name (canonical.c_str (),
split_style::DOT_STYLE);
std::string_view tail = names.back ();
@@ -329,7 +332,9 @@ cooked_index_shard::handle_gnat_encoded_entry (cooked_index_entry *entry,
}
entry->set_parent (parent);
- return make_unique_xstrndup (tail.data (), tail.length ());
+ auto new_canon = make_unique_xstrndup (tail.data (), tail.length ());
+ entry->canonical = new_canon.get ();
+ m_names.push_back (std::move (new_canon));
}
/* See cooked-index.h. */
@@ -389,17 +394,7 @@ cooked_index_shard::finalize (const parent_map_map *parent_maps)
if ((entry->flags & IS_LINKAGE) != 0)
entry->canonical = entry->name;
else if (entry->lang == language_ada)
- {
- gdb::unique_xmalloc_ptr<char> canon_name
- = handle_gnat_encoded_entry (entry, gnat_entries.get ());
- if (canon_name == nullptr)
- entry->canonical = entry->name;
- else
- {
- entry->canonical = canon_name.get ();
- m_names.push_back (std::move (canon_name));
- }
- }
+ handle_gnat_encoded_entry (entry, gnat_entries.get ());
else if (entry->lang == language_cplus || entry->lang == language_c)
{
void **slot = htab_find_slot (seen_names.get (), entry,
diff --git a/gdb/dwarf2/cooked-index.h b/gdb/dwarf2/cooked-index.h
index e9f13c97be0..5b48b8162da 100644
--- a/gdb/dwarf2/cooked-index.h
+++ b/gdb/dwarf2/cooked-index.h
@@ -338,9 +338,8 @@ class cooked_index_shard
/* GNAT only emits mangled ("encoded") names in the DWARF, and does
not emit the module structure. However, we need this structure
to do lookups. This function recreates that structure for an
- existing entry. It returns the base name (last element) of the
- full decoded name. */
- gdb::unique_xmalloc_ptr<char> handle_gnat_encoded_entry
+ existing entry, modifying ENTRY as appropriate. */
+ void handle_gnat_encoded_entry
(cooked_index_entry *entry, htab_t gnat_entries);
/* Finalize the index. This should be called a single time, when
More information about the Gdb-cvs
mailing list