Skip to content

Commit 4d78ce7

Browse files
committed
Add initializers to comp_unit_head
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
1 parent 639601f commit 4d78ce7

File tree

4 files changed

+14
-16
lines changed

4 files changed

+14
-16
lines changed

gdb/dwarf2/comp-unit-head.h

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -34,36 +34,36 @@
3434
translation, looks like this. */
3535
struct comp_unit_head
3636
{
37-
unsigned int length;
38-
unsigned char version;
39-
unsigned char addr_size;
40-
unsigned char signed_addr_p;
41-
sect_offset abbrev_sect_off;
37+
unsigned int length = 0;
38+
unsigned char version = 0;
39+
unsigned char addr_size = 0;
40+
unsigned char signed_addr_p = 0;
41+
sect_offset abbrev_sect_off {};
4242

4343
/* Size of file offsets; either 4 or 8. */
44-
unsigned int offset_size;
44+
unsigned int offset_size = 0;
4545

4646
/* Size of the length field; either 4 or 12. */
47-
unsigned int initial_length_size;
47+
unsigned int initial_length_size = 0;
4848

49-
enum dwarf_unit_type unit_type;
49+
enum dwarf_unit_type unit_type {};
5050

5151
/* Offset to first die in this cu from the start of the cu.
5252
This will be the first byte following the compilation unit header. */
53-
cu_offset first_die_cu_offset;
53+
cu_offset first_die_cu_offset {};
5454

5555
/* Offset to the first byte of this compilation unit header in the
5656
.debug_info section, for resolving relative reference dies. */
57-
sect_offset sect_off;
57+
sect_offset sect_off {};
5858

5959
/* For types, offset in the type's DIE of the type defined by this TU. */
60-
cu_offset type_cu_offset_in_tu;
60+
cu_offset type_cu_offset_in_tu {};
6161

6262
/* 64-bit signature of this unit. For type units, it denotes the signature of
6363
the type (DW_UT_type in DWARF 4, additionally DW_UT_split_type in DWARF 5).
6464
Also used in DWARF 5, to denote the dwo id when the unit type is
6565
DW_UT_skeleton or DW_UT_split_compile. */
66-
ULONGEST signature;
66+
ULONGEST signature = 0;
6767

6868
/* Return the total length of the CU described by this header. */
6969
unsigned int get_length () const

gdb/dwarf2/cu.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ struct dwarf2_cu
9898
void add_dependence (struct dwarf2_per_cu_data *ref_per_cu);
9999

100100
/* The header of the compilation unit. */
101-
struct comp_unit_head header {};
101+
struct comp_unit_head header;
102102

103103
/* Base address of this compilation unit. */
104104
gdb::optional<CORE_ADDR> base_address;

gdb/dwarf2/read.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23580,8 +23580,6 @@ dwarf2_per_cu_data::get_header () const
2358023580
const gdb_byte *info_ptr
2358123581
= this->section->buffer + to_underlying (this->sect_off);
2358223582

23583-
memset (&m_header, 0, sizeof (m_header));
23584-
2358523583
read_comp_unit_head (&m_header, info_ptr, this->section,
2358623584
rcuh_kind::COMPILE);
2358723585

gdb/dwarf2/read.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ struct dwarf2_per_cu_data
206206
207207
Don't access this field directly, use the get_header method instead. It
208208
should be private, but we can't make it private at the moment. */
209-
mutable comp_unit_head m_header {};
209+
mutable comp_unit_head m_header;
210210

211211
/* The file and directory for this CU. This is cached so that we
212212
don't need to re-examine the DWO in some situations. This may be

0 commit comments

Comments
 (0)