From b04c791586da2916ca87521eca3c82ba71cd22fb Mon Sep 17 00:00:00 2001 From: Tom de Vries 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