public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: tdevries <tdevries@suse.de>
To: Tom Tromey <tom@tromey.com>
Cc: gdb-patches@sourceware.org
Subject: Re: [PATCH] Add initializers to comp_unit_head
Date: Sun, 25 Dec 2022 08:06:53 +0000	[thread overview]
Message-ID: <71d0815665fb2b2c4904264b023840d1@suse.de> (raw)
In-Reply-To: <20221224224435.760523-1-tom@tromey.com>

[-- Attachment #1: Type: text/plain, Size: 477 bytes --]

On 2022-12-24 22:44, Tom Tromey wrote:
> PR symtab/29343 points out that it would be beneficial if
> comp_unit_head had a constructor and used initializers.  This patch
> implements this.

LGTM.

> I'm unsure if this is sufficient to close the bug,
> but at least it's a step.
> 

I think it's sufficient.

FWIW, I've rebased the patch attached to the PR on your patch, and I'm 
left with the patch below, which makes the length field of 
comp_unit_head private.

Thanks,
- Tom

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-gdb-symtab-Make-comp_unit_head.length-private.patch --]
[-- Type: text/x-patch; name=0001-gdb-symtab-Make-comp_unit_head.length-private.patch, Size: 3328 bytes --]

From b04c791586da2916ca87521eca3c82ba71cd22fb Mon Sep 17 00:00:00 2001
From: Tom de Vries <tdevries@suse.de>
Date: Sun, 25 Dec 2022 08:53:43 +0100
Subject: [PATCH] [gdb/symtab] Make comp_unit_head.length private

Make comp_unit_head.length private, to enforce using accessor function
get_length.

Tested on x86_64-linux.

PR symtab/29343
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=29343
---
 gdb/dwarf2/comp-unit-head.c |  4 ++--
 gdb/dwarf2/comp-unit-head.h | 16 +++++++++++++---
 gdb/dwarf2/read.c           |  4 ++--
 3 files changed, 17 insertions(+), 7 deletions(-)

diff --git a/gdb/dwarf2/comp-unit-head.c b/gdb/dwarf2/comp-unit-head.c
index edb2a8aa55a..128d62fcbb1 100644
--- a/gdb/dwarf2/comp-unit-head.c
+++ b/gdb/dwarf2/comp-unit-head.c
@@ -44,7 +44,7 @@ read_comp_unit_head (struct comp_unit_head *cu_header,
   const char *filename = section->get_file_name ();
   bfd *abfd = section->get_bfd_owner ();
 
-  cu_header->length = read_initial_length (abfd, info_ptr, &bytes_read);
+  cu_header->set_length (read_initial_length (abfd, info_ptr, &bytes_read));
   cu_header->initial_length_size = bytes_read;
   cu_header->offset_size = (bytes_read == 4) ? 4 : 8;
   info_ptr += bytes_read;
@@ -166,7 +166,7 @@ error_check_comp_unit_head (dwarf2_per_objfile *per_objfile,
       > section->size)
     error (_("Dwarf Error: bad length (0x%x) in compilation unit header "
 	   "(offset %s + 0) [in module %s]"),
-	   header->length, sect_offset_str (header->sect_off),
+	   header->get_length (false), sect_offset_str (header->sect_off),
 	   filename);
 }
 
diff --git a/gdb/dwarf2/comp-unit-head.h b/gdb/dwarf2/comp-unit-head.h
index 7579fe7fa29..56b37ae537e 100644
--- a/gdb/dwarf2/comp-unit-head.h
+++ b/gdb/dwarf2/comp-unit-head.h
@@ -34,7 +34,9 @@
    translation, looks like this.  */
 struct comp_unit_head
 {
-  unsigned int length = 0;
+private:
+  unsigned int m_length = 0;
+public:
   unsigned char version = 0;
   unsigned char addr_size = 0;
   unsigned char signed_addr_p = 0;
@@ -65,10 +67,18 @@ struct comp_unit_head
      DW_UT_skeleton or DW_UT_split_compile.  */
   ULONGEST signature = 0;
 
+  void set_length (unsigned int length)
+  {
+    m_length = length;
+  }
+
   /* Return the total length of the CU described by this header.  */
-  unsigned int get_length () const
+  unsigned int get_length (bool include_initial = true) const
   {
-    return initial_length_size + length;
+    unsigned int res = m_length;
+    if (include_initial)
+      res += initial_length_size;
+    return res;
   }
 
   /* Return TRUE if OFF is within this CU.  */
diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index 28fadb886aa..50881929d47 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -7744,7 +7744,7 @@ load_full_comp_unit (dwarf2_per_cu_data *this_cu,
 
   gdb_assert (cu->die_hash == NULL);
   cu->die_hash =
-    htab_create_alloc_ex (cu->header.length / 12,
+    htab_create_alloc_ex (cu->header.get_length (false) / 12,
 			  die_hash,
 			  die_eq,
 			  NULL,
@@ -23026,7 +23026,7 @@ read_signatured_type (signatured_type *sig_type,
 
       gdb_assert (cu->die_hash == NULL);
       cu->die_hash =
-	htab_create_alloc_ex (cu->header.length / 12,
+	htab_create_alloc_ex (cu->header.get_length (false) / 12,
 			      die_hash,
 			      die_eq,
 			      NULL,
-- 
2.34.1


  reply	other threads:[~2022-12-25  8:06 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-12-24 22:44 Tom Tromey
2022-12-25  8:06 ` tdevries [this message]
2022-12-25 15:33   ` Tom Tromey
2022-12-25 17:56     ` tdevries
2022-12-26 17:59       ` Tom Tromey
2022-12-30 12:58         ` [pushed] [gdb/symtab] Make comp_unit_head.length private Tom de Vries

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=71d0815665fb2b2c4904264b023840d1@suse.de \
    --to=tdevries@suse.de \
    --cc=gdb-patches@sourceware.org \
    --cc=tom@tromey.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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).