From: simon.marchi@polymtl.ca
To: gdb-patches@sourceware.org
Cc: Simon Marchi <simon.marchi@polymtl.ca>
Subject: [PATCH 2/8] gdb/dwarf: move dwo_unit and dwo_file to read.h
Date: Mon, 16 Mar 2026 19:19:20 -0400 [thread overview]
Message-ID: <20260316232042.368080-3-simon.marchi@polymtl.ca> (raw)
In-Reply-To: <20260316232042.368080-1-simon.marchi@polymtl.ca>
From: Simon Marchi <simon.marchi@polymtl.ca>
This is to allow index-write.c to see these types, in a later patch.
Change-Id: Ia32e0643f95561d3a1bfb67d501c8e20f5682f0e
---
gdb/dwarf2/read.c | 125 ----------------------------------------------
gdb/dwarf2/read.h | 125 +++++++++++++++++++++++++++++++++++++++++++++-
2 files changed, 124 insertions(+), 126 deletions(-)
diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index 8b87d58dd9c5..c13ea6c1622f 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -266,86 +266,6 @@ struct loclists_rnglists_header
unsigned int offset_entry_count;
};
-/* These sections are what may appear in a (real or virtual) DWO file. */
-
-struct dwo_sections
-{
- struct dwarf2_section_info abbrev;
- struct dwarf2_section_info line;
- struct dwarf2_section_info loc;
- struct dwarf2_section_info loclists;
- struct dwarf2_section_info macinfo;
- struct dwarf2_section_info macro;
- struct dwarf2_section_info rnglists;
- struct dwarf2_section_info str;
- struct dwarf2_section_info str_offsets;
- /* In the case of a virtual DWO file, these two are unused. */
- std::vector<dwarf2_section_info> infos;
- std::vector<dwarf2_section_info> types;
-};
-
-/* CUs/TUs in DWP/DWO files. */
-
-struct dwo_unit
-{
- /* Backlink to the containing struct dwo_file. */
- struct dwo_file *dwo_file = nullptr;
-
- /* The "id" that distinguishes this CU/TU.
- .debug_info calls this "dwo_id", .debug_types calls this "signature".
- Since signatures came first, we stick with it for consistency. */
- ULONGEST signature = 0;
-
- /* The section this CU/TU lives in, in the DWO file. */
- dwarf2_section_info *section = nullptr;
-
- /* This is set if SECTION is owned by this dwo_unit. */
- dwarf2_section_info_up section_holder;
-
- /* Same as dwarf2_per_cu::{sect_off,length} but in the DWO section. */
- sect_offset sect_off {};
- unsigned int length = 0;
-
- /* For types, offset in the type's DIE of the type defined by this TU. */
- cu_offset type_offset_in_tu;
-};
-
-using dwo_unit_up = std::unique_ptr<dwo_unit>;
-
-/* Hash function for dwo_unit objects, based on the signature. */
-
-struct dwo_unit_hash
-{
- using is_transparent = void;
-
- std::size_t operator() (ULONGEST signature) const noexcept
- { return signature; }
-
- std::size_t operator() (const dwo_unit_up &unit) const noexcept
- { return (*this) (unit->signature); }
-};
-
-/* Equal function for dwo_unit objects, based on the signature.
-
- The signature is assumed to be unique within the DWO file. So while object
- file CU dwo_id's always have the value zero, that's OK, assuming each object
- file DWO file has only one CU, and that's the rule for now. */
-
-struct dwo_unit_eq
-{
- using is_transparent = void;
-
- bool operator() (ULONGEST sig, const dwo_unit_up &unit) const noexcept
- { return sig == unit->signature; }
-
- bool operator() (const dwo_unit_up &a, const dwo_unit_up &b) const noexcept
- { return (*this) (a->signature, b); }
-};
-
-/* Set of dwo_unit object, using their signature as identity. */
-
-using dwo_unit_set = gdb::unordered_set<dwo_unit_up, dwo_unit_hash, dwo_unit_eq>;
-
/* 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. */
@@ -355,51 +275,6 @@ enum dwp_v2_section_ids
DW_SECT_MIN = 1
};
-/* Data for one DWO file.
-
- This includes virtual DWO files (a virtual DWO file is a DWO file as it
- appears in a DWP file). DWP files don't really have DWO files per se -
- comdat folding of types "loses" the DWO file they came from, and from
- a high level view DWP files appear to contain a mass of random types.
- However, to maintain consistency with the non-DWP case we pretend DWP
- files contain virtual DWO files, and we assign each TU with one virtual
- DWO file (generally based on the line and abbrev section offsets -
- a heuristic that seems to work in practice). */
-
-struct dwo_file
-{
- dwo_file () = default;
- DISABLE_COPY_AND_ASSIGN (dwo_file);
-
- /* 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
- from related CU+TUs. */
- std::string dwo_name;
-
- /* The DW_AT_comp_dir attribute. */
- const char *comp_dir = nullptr;
-
- /* The bfd, when the file is open. Otherwise this is NULL.
- This is unused(NULL) for virtual DWO files where we use dwp_file.dbfd. */
- gdb_bfd_ref_ptr dbfd;
-
- /* The sections that make up this DWO file.
- Remember that for virtual DWO files in DWP V2 or DWP V5, these are virtual
- sections (for lack of a better name). */
- struct dwo_sections sections {};
-
- /* The CUs in the file.
-
- Multiple CUs per DWO are supported as an extension to handle LLVM's Link
- Time Optimization output (where multiple source files may be compiled into
- a single object/dwo pair). */
- dwo_unit_set cus;
-
- /* Table of TUs in the file. */
- dwo_unit_set tus;
-};
-
/* See dwarf2/read.h. */
std::size_t
diff --git a/gdb/dwarf2/read.h b/gdb/dwarf2/read.h
index 86f97e7ccf4a..5a46786e4f3f 100644
--- a/gdb/dwarf2/read.h
+++ b/gdb/dwarf2/read.h
@@ -489,7 +489,130 @@ using signatured_type_set
= gdb::unordered_set<signatured_type *, signatured_type_hash,
signatured_type_eq>;
-struct dwo_file;
+/* CUs/TUs in DWP/DWO files. */
+
+struct dwo_unit
+{
+ /* Backlink to the containing struct dwo_file. */
+ struct dwo_file *dwo_file = nullptr;
+
+ /* The "id" that distinguishes this CU/TU.
+ .debug_info calls this "dwo_id", .debug_types calls this "signature".
+ Since signatures came first, we stick with it for consistency. */
+ ULONGEST signature = 0;
+
+ /* The section this CU/TU lives in, in the DWO file. */
+ dwarf2_section_info *section = nullptr;
+
+ /* This is set if SECTION is owned by this dwo_unit. */
+ dwarf2_section_info_up section_holder;
+
+ /* Same as dwarf2_per_cu::{sect_off,length} but in the DWO section. */
+ sect_offset sect_off {};
+ unsigned int length = 0;
+
+ /* For types, offset in the type's DIE of the type defined by this TU. */
+ cu_offset type_offset_in_tu;
+};
+
+using dwo_unit_up = std::unique_ptr<dwo_unit>;
+
+/* These sections are what may appear in a (real or virtual) DWO file. */
+
+struct dwo_sections
+{
+ struct dwarf2_section_info abbrev;
+ struct dwarf2_section_info line;
+ struct dwarf2_section_info loc;
+ struct dwarf2_section_info loclists;
+ struct dwarf2_section_info macinfo;
+ struct dwarf2_section_info macro;
+ struct dwarf2_section_info rnglists;
+ struct dwarf2_section_info str;
+ struct dwarf2_section_info str_offsets;
+ /* In the case of a virtual DWO file, these two are unused. */
+ std::vector<dwarf2_section_info> infos;
+ std::vector<dwarf2_section_info> types;
+};
+
+/* Hash function for dwo_unit objects, based on the signature. */
+
+struct dwo_unit_hash
+{
+ using is_transparent = void;
+
+ std::size_t operator() (ULONGEST signature) const noexcept
+ { return signature; }
+
+ std::size_t operator() (const dwo_unit_up &unit) const noexcept
+ { return (*this) (unit->signature); }
+};
+
+/* Equal function for dwo_unit objects, based on the signature.
+
+ The signature is assumed to be unique within the DWO file. So while object
+ file CU dwo_id's always have the value zero, that's OK, assuming each object
+ file DWO file has only one CU, and that's the rule for now. */
+
+struct dwo_unit_eq
+{
+ using is_transparent = void;
+
+ bool operator() (ULONGEST sig, const dwo_unit_up &unit) const noexcept
+ { return sig == unit->signature; }
+
+ bool operator() (const dwo_unit_up &a, const dwo_unit_up &b) const noexcept
+ { return (*this) (a->signature, b); }
+};
+
+/* Set of dwo_unit object, using their signature as identity. */
+
+using dwo_unit_set = gdb::unordered_set<dwo_unit_up, dwo_unit_hash, dwo_unit_eq>;
+
+/* Data for one DWO file.
+
+ This includes virtual DWO files (a virtual DWO file is a DWO file as it
+ appears in a DWP file). DWP files don't really have DWO files per se -
+ comdat folding of types "loses" the DWO file they came from, and from
+ a high level view DWP files appear to contain a mass of random types.
+ However, to maintain consistency with the non-DWP case we pretend DWP
+ files contain virtual DWO files, and we assign each TU with one virtual
+ DWO file (generally based on the line and abbrev section offsets -
+ a heuristic that seems to work in practice). */
+
+struct dwo_file
+{
+ dwo_file () = default;
+ DISABLE_COPY_AND_ASSIGN (dwo_file);
+
+ /* 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
+ from related CU+TUs. */
+ std::string dwo_name;
+
+ /* The DW_AT_comp_dir attribute. */
+ const char *comp_dir = nullptr;
+
+ /* The bfd, when the file is open. Otherwise this is NULL.
+ This is unused(NULL) for virtual DWO files where we use dwp_file.dbfd. */
+ gdb_bfd_ref_ptr dbfd;
+
+ /* The sections that make up this DWO file.
+ Remember that for virtual DWO files in DWP V2 or DWP V5, these are virtual
+ sections (for lack of a better name). */
+ struct dwo_sections sections {};
+
+ /* The CUs in the file.
+
+ Multiple CUs per DWO are supported as an extension to handle LLVM's Link
+ Time Optimization output (where multiple source files may be compiled into
+ a single object/dwo pair). */
+ dwo_unit_set cus;
+
+ /* Table of TUs in the file. */
+ dwo_unit_set tus;
+};
using dwo_file_up = std::unique_ptr<dwo_file>;
--
2.53.0
next prev parent reply other threads:[~2026-03-16 23:22 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 ` simon.marchi [this message]
2026-03-16 23:19 ` [PATCH 3/8] gdb/dwarf: move dwarf2_cu::section to cu.c simon.marchi
2026-03-16 23:19 ` [PATCH 4/8] gdb/dwarf: add dwo_file::find_tus simon.marchi
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-3-simon.marchi@polymtl.ca \
--to=simon.marchi@polymtl.ca \
--cc=gdb-patches@sourceware.org \
/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