Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: simon.marchi@polymtl.ca
To: gdb-patches@sourceware.org
Cc: Simon Marchi <simon.marchi@efficios.com>
Subject: [PATCH 4/8] gdb/dwarf: add dwo_file::find_tus
Date: Mon, 16 Mar 2026 19:19:22 -0400	[thread overview]
Message-ID: <20260316232042.368080-5-simon.marchi@polymtl.ca> (raw)
In-Reply-To: <20260316232042.368080-1-simon.marchi@polymtl.ca>

From: Simon Marchi <simon.marchi@efficios.com>

Add this little helper to make finding a TU a bit simpler.  I always
find the STL way of doing things cryptic, so I think that hiding it in
small helper methods makes the code clearer.

A subsequent patch will add more uses of it

Change-Id: Ibfb20d0e44c65d2ff729f3e0980ec4435f223aef
---
 gdb/dwarf2/read.c | 18 ++++++++++++++----
 gdb/dwarf2/read.h |  5 +++++
 2 files changed, 19 insertions(+), 4 deletions(-)

diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index 3a0602b4ac08..fd1c37ad8e89 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -266,6 +266,18 @@ struct loclists_rnglists_header
   unsigned int offset_entry_count;
 };
 
+/* See read.h.  */
+
+dwo_unit *
+dwo_file::find_tu (ULONGEST signature) const
+{
+  auto it = this->tus.find (signature);
+  if (it == this->tus.end ())
+    return nullptr;
+
+  return it->get ();
+}
+
 /* include/dwarf2.h defines the DWP section codes.
    It defines a max value but it doesn't define a min value, which we
    use for error checking, so provide one.  */
@@ -2342,12 +2354,10 @@ lookup_dwo_signatured_type (struct dwarf2_cu *cu, ULONGEST sig)
   /* Note: cu->dwo_unit is the dwo_unit that references this TU, not the
      dwo_unit of the TU itself.  */
   dwo_file *dwo_file = cu->dwo_unit->dwo_file;
-  auto it = dwo_file->tus.find (sig);
-  if (it == dwo_file->tus.end ())
+  dwo_unit *dwo_entry = dwo_file->find_tu (sig);
+  if (dwo_entry == nullptr)
     return nullptr;
 
-  dwo_unit *dwo_entry = it->get ();
-
   /* If the global table doesn't have an entry for this TU, add one.  */
   if (sig_type_it == per_bfd->signatured_types.end ())
     {
diff --git a/gdb/dwarf2/read.h b/gdb/dwarf2/read.h
index 5a46786e4f3f..5c61e91870b4 100644
--- a/gdb/dwarf2/read.h
+++ b/gdb/dwarf2/read.h
@@ -585,6 +585,11 @@ struct dwo_file
   dwo_file () = default;
   DISABLE_COPY_AND_ASSIGN (dwo_file);
 
+  /* Look for a type unit with signature SIGNATURE in this dwo_file.
+
+     Return nullptr if not found.  */
+  dwo_unit *find_tu (ULONGEST signature) const;
+
   /* The DW_AT_GNU_dwo_name or DW_AT_dwo_name attribute.
      For virtual DWO files the name is constructed from the section offsets
      of abbrev,line,loc,str_offsets so that we combine virtual DWO files
-- 
2.53.0


  parent reply	other threads:[~2026-03-16 23:30 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-16 23:19 [PATCH 0/8] Handle foreign type units in .debug_names simon.marchi
2026-03-16 23:19 ` [PATCH 1/8] gdb/dwarf: refuse to produce .gdb_index when skeletonless type units are present simon.marchi
2026-03-17 12:57   ` Eli Zaretskii
2026-03-16 23:19 ` [PATCH 2/8] gdb/dwarf: move dwo_unit and dwo_file to read.h simon.marchi
2026-03-16 23:19 ` [PATCH 3/8] gdb/dwarf: move dwarf2_cu::section to cu.c simon.marchi
2026-03-16 23:19 ` simon.marchi [this message]
2026-03-16 23:19 ` [PATCH 5/8] gdb/dwarf: generate foreign type units in .debug_names simon.marchi
2026-03-16 23:19 ` [PATCH 6/8] gdb/dwarf: add debug output in read-debug-names.c simon.marchi
2026-03-16 23:19 ` [PATCH 7/8] gdb/dwarf: add more context to complaints in mapped_debug_names_reader::scan_one_entry simon.marchi
2026-03-16 23:19 ` [PATCH 8/8] gdb/dwarf: read foreign type units simon.marchi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260316232042.368080-5-simon.marchi@polymtl.ca \
    --to=simon.marchi@polymtl.ca \
    --cc=gdb-patches@sourceware.org \
    --cc=simon.marchi@efficios.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox