From: Tom Tromey <tom@tromey.com>
To: gdb-patches@sourceware.org
Cc: Tom Tromey <tom@tromey.com>
Subject: [PATCH 1/3] Remove 'read' call from dwz_file::read_string
Date: Sun, 23 Mar 2025 13:20:00 -0600 [thread overview]
Message-ID: <20250323-dwz-dwarf-5-v2-v1-1-3c0775ca5514@tromey.com> (raw)
In-Reply-To: <20250323-dwz-dwarf-5-v2-v1-0-3c0775ca5514@tromey.com>
dwz_file::read_string calls 'read' on the section, but this isn't
needed as the sections have all been pre-read.
This patch makes this change, and refactors dwz_file a bit to make
this more obvious -- by making it clear that only the "static
constructor" can create a dwz_file.
---
gdb/dwarf2/dwz.c | 8 +++++---
gdb/dwarf2/dwz.h | 25 +++++++++++++------------
gdb/dwarf2/read.c | 2 +-
3 files changed, 19 insertions(+), 16 deletions(-)
diff --git a/gdb/dwarf2/dwz.c b/gdb/dwarf2/dwz.c
index f36d6a6418a4220d7d531e3bf5b6e047b40edd6e..14cd8e882ba6bc16b57a82aa31296f4025261f15 100644
--- a/gdb/dwarf2/dwz.c
+++ b/gdb/dwarf2/dwz.c
@@ -34,7 +34,9 @@
const char *
dwz_file::read_string (struct objfile *objfile, LONGEST str_offset)
{
- str.read (objfile);
+ /* This must be true because the sections are read in when the
+ dwz_file is created. */
+ gdb_assert (str.readin);
if (str.buffer == NULL)
error (_("DW_FORM_GNU_strp_alt used without .debug_str "
@@ -177,7 +179,7 @@ dwz_search_other_debugdirs (std::string &filename, bfd_byte *buildid,
/* See dwz.h. */
void
-dwarf2_read_dwz_file (dwarf2_per_objfile *per_objfile)
+dwz_file::read_dwz_file (dwarf2_per_objfile *per_objfile)
{
bfd_size_type buildid_len_arg;
size_t buildid_len;
@@ -261,7 +263,7 @@ dwarf2_read_dwz_file (dwarf2_per_objfile *per_objfile)
error (_("could not find '.gnu_debugaltlink' file for %s"),
per_bfd->filename ());
- auto result = std::make_unique<dwz_file> (std::move (dwz_bfd));
+ dwz_file_up result (new dwz_file (std::move (dwz_bfd)));
for (asection *sec : gdb_bfd_sections (result->dwz_bfd))
locate_dwz_sections (per_objfile->objfile, result->dwz_bfd.get (),
diff --git a/gdb/dwarf2/dwz.h b/gdb/dwarf2/dwz.h
index cd5143ff0848564e1c831f4eb7ddccd7231d28e6..639eea3a41850249a44259e454daa770b246ef2b 100644
--- a/gdb/dwarf2/dwz.h
+++ b/gdb/dwarf2/dwz.h
@@ -31,10 +31,12 @@ struct dwarf2_per_objfile;
struct dwz_file
{
- dwz_file (gdb_bfd_ref_ptr &&bfd)
- : dwz_bfd (std::move (bfd))
- {
- }
+ /* Open the separate '.dwz' debug file, if needed. This will set
+ the appropriate field in the per-BFD structure. If the DWZ file
+ exists, the relevant sections are read in as well. Throws an
+ error if the .gnu_debugaltlink section exists but the file cannot
+ be found. */
+ static void read_dwz_file (dwarf2_per_objfile *per_objfile);
const char *filename () const
{
@@ -64,16 +66,15 @@ struct dwz_file
return a pointer to the string. */
const char *read_string (struct objfile *objfile, LONGEST str_offset);
-};
-using dwz_file_up = std::unique_ptr<dwz_file>;
+private:
-/* Open the separate '.dwz' debug file, if needed. This just sets the
- appropriate field in the per-BFD structure. If the DWZ file
- exists, the relevant sections are read in as well. Throws an error
- if the .gnu_debugaltlink section exists but the file cannot be
- found. */
+ explicit dwz_file (gdb_bfd_ref_ptr &&bfd)
+ : dwz_bfd (std::move (bfd))
+ {
+ }
+};
-extern void dwarf2_read_dwz_file (dwarf2_per_objfile *per_objfile);
+using dwz_file_up = std::unique_ptr<dwz_file>;
#endif /* GDB_DWARF2_DWZ_H */
diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index 8875e97a7b3303c5c8bf7ca90ed21f22f4d23b34..f4198d71ca28811bd02c5fb87b5206629f118874 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -1289,7 +1289,7 @@ dwarf2_has_info (struct objfile *objfile,
BFD, to avoid races. */
try
{
- dwarf2_read_dwz_file (per_objfile);
+ dwz_file::read_dwz_file (per_objfile);
}
catch (const gdb_exception_error &err)
{
--
2.46.1
next prev parent reply other threads:[~2025-03-23 19:21 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-03-23 19:19 [PATCH 0/3] Support DWARF 5 .debug_sup section Tom Tromey
2025-03-23 19:20 ` Tom Tromey [this message]
2025-03-24 14:25 ` [PATCH 1/3] Remove 'read' call from dwz_file::read_string Alexandra Petlanova Hajkova
2025-03-24 20:30 ` Simon Marchi
2025-03-24 20:52 ` Tom Tromey
2025-03-23 19:20 ` [PATCH 2/3] Handle DWARF 5 separate debug sections Tom Tromey
2025-03-24 15:45 ` Alexandra Petlanova Hajkova
2025-03-24 17:16 ` Tom Tromey
2025-04-03 14:39 ` Tom Tromey
2025-04-22 14:55 ` Tom Tromey
2025-04-22 15:10 ` Simon Marchi
2025-04-28 11:35 ` Tom de Vries
2025-03-24 20:52 ` Simon Marchi
2025-03-25 13:37 ` Tom Tromey
2025-03-23 19:20 ` [PATCH 3/3] Add "-5" flag to cc-with-tweaks Tom Tromey
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=20250323-dwz-dwarf-5-v2-v1-1-3c0775ca5514@tromey.com \
--to=tom@tromey.com \
--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