public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Tom Tromey <tom@tromey.com>
To: gdb-patches@sourceware.org
Cc: Tom Tromey <tom@tromey.com>
Subject: [PATCH] Add initializers to comp_unit_head
Date: Sat, 24 Dec 2022 15:44:35 -0700	[thread overview]
Message-ID: <20221224224435.760523-1-tom@tromey.com> (raw)

PR symtab/29343 points out that it would be beneficial if
comp_unit_head had a constructor and used initializers.  This patch
implements this.  I'm unsure if this is sufficient to close the bug,
but at least it's a step.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=29343
---
 gdb/dwarf2/comp-unit-head.h | 24 ++++++++++++------------
 gdb/dwarf2/cu.h             |  2 +-
 gdb/dwarf2/read.c           |  2 --
 gdb/dwarf2/read.h           |  2 +-
 4 files changed, 14 insertions(+), 16 deletions(-)

diff --git a/gdb/dwarf2/comp-unit-head.h b/gdb/dwarf2/comp-unit-head.h
index a7ee3e64546..7579fe7fa29 100644
--- a/gdb/dwarf2/comp-unit-head.h
+++ b/gdb/dwarf2/comp-unit-head.h
@@ -34,36 +34,36 @@
    translation, looks like this.  */
 struct comp_unit_head
 {
-  unsigned int length;
-  unsigned char version;
-  unsigned char addr_size;
-  unsigned char signed_addr_p;
-  sect_offset abbrev_sect_off;
+  unsigned int length = 0;
+  unsigned char version = 0;
+  unsigned char addr_size = 0;
+  unsigned char signed_addr_p = 0;
+  sect_offset abbrev_sect_off {};
 
   /* Size of file offsets; either 4 or 8.  */
-  unsigned int offset_size;
+  unsigned int offset_size = 0;
 
   /* Size of the length field; either 4 or 12.  */
-  unsigned int initial_length_size;
+  unsigned int initial_length_size = 0;
 
-  enum dwarf_unit_type unit_type;
+  enum dwarf_unit_type unit_type {};
 
   /* Offset to first die in this cu from the start of the cu.
      This will be the first byte following the compilation unit header.  */
-  cu_offset first_die_cu_offset;
+  cu_offset first_die_cu_offset {};
 
   /* Offset to the first byte of this compilation unit header in the
      .debug_info section, for resolving relative reference dies.  */
-  sect_offset sect_off;
+  sect_offset sect_off {};
 
   /* For types, offset in the type's DIE of the type defined by this TU.  */
-  cu_offset type_cu_offset_in_tu;
+  cu_offset type_cu_offset_in_tu {};
 
   /* 64-bit signature of this unit. For type units, it denotes the signature of
      the type (DW_UT_type in DWARF 4, additionally DW_UT_split_type in DWARF 5).
      Also used in DWARF 5, to denote the dwo id when the unit type is
      DW_UT_skeleton or DW_UT_split_compile.  */
-  ULONGEST signature;
+  ULONGEST signature = 0;
 
   /* Return the total length of the CU described by this header.  */
   unsigned int get_length () const
diff --git a/gdb/dwarf2/cu.h b/gdb/dwarf2/cu.h
index 52975095871..b126acab7b2 100644
--- a/gdb/dwarf2/cu.h
+++ b/gdb/dwarf2/cu.h
@@ -98,7 +98,7 @@ struct dwarf2_cu
   void add_dependence (struct dwarf2_per_cu_data *ref_per_cu);
 
   /* The header of the compilation unit.  */
-  struct comp_unit_head header {};
+  struct comp_unit_head header;
 
   /* Base address of this compilation unit.  */
   gdb::optional<CORE_ADDR> base_address;
diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index 7bd12c107e2..28fadb886aa 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -23580,8 +23580,6 @@ dwarf2_per_cu_data::get_header () const
       const gdb_byte *info_ptr
 	= this->section->buffer + to_underlying (this->sect_off);
 
-      memset (&m_header, 0, sizeof (m_header));
-
       read_comp_unit_head (&m_header, info_ptr, this->section,
 			   rcuh_kind::COMPILE);
 
diff --git a/gdb/dwarf2/read.h b/gdb/dwarf2/read.h
index dd718266883..0dc4e2e885c 100644
--- a/gdb/dwarf2/read.h
+++ b/gdb/dwarf2/read.h
@@ -206,7 +206,7 @@ struct dwarf2_per_cu_data
 
      Don't access this field directly, use the get_header method instead.  It
      should be private, but we can't make it private at the moment.  */
-  mutable comp_unit_head m_header {};
+  mutable comp_unit_head m_header;
 
   /* The file and directory for this CU.  This is cached so that we
      don't need to re-examine the DWO in some situations.  This may be
-- 
2.38.1


             reply	other threads:[~2022-12-24 22:44 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-12-24 22:44 Tom Tromey [this message]
2022-12-25  8:06 ` tdevries
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=20221224224435.760523-1-tom@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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).