From: Tom Tromey Date: Sat, 8 Feb 2020 20:40:54 +0000 (-0700) Subject: Add some methods to dwarf2_per_cu_data X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=09ba997f323198495bcf6884dd402fa5b9cc8978;p=binutils-gdb.git Add some methods to dwarf2_per_cu_data This changes a few helper functions to be methods on dwarf2_per_cu_data. 2020-02-08 Tom Tromey * dwarf2/loc.c (dwarf2_find_location_expression) (dwarf_evaluate_loc_desc::get_tls_address) (dwarf_evaluate_loc_desc::push_dwarf_reg_entry_value) (rw_pieced_value, dwarf2_evaluate_loc_desc_full) (dwarf2_locexpr_baton_eval, dwarf2_evaluate_property) (dwarf2_compile_property_to_c) (dwarf2_loc_desc_get_symbol_read_needs) (dwarf2_compile_expr_to_ax, locexpr_describe_location) (locexpr_tracepoint_var_ref, locexpr_generate_c_location) (loclist_describe_location, loclist_tracepoint_var_ref) (loclist_generate_c_location): Update. * compile/compile-loc2c.c (do_compile_dwarf_expr_to_c): Update. * dwarf2/loc.h (dwarf2_per_cu_objfile, dwarf2_per_cu_addr_size) (dwarf2_per_cu_ref_addr_size, dwarf2_per_cu_offset_size) (dwarf2_per_cu_text_offset, dwarf2_version): Don't declare. * dwarf2/read.c (dwarf2_per_cu_data::objfile) (dwarf2_per_cu_data::addr_size) (dwarf2_per_cu_data::ref_addr_size) (dwarf2_per_cu_data::text_offset) (dwarf2_per_cu_data::addr_type): Now methods. (per_cu_header_read_in): Make per_cu "const". (dwarf2_version): Remove. (dwarf2_per_cu_data::int_type): Now a method. (dwarf2_per_cu_data::_addr_sized_int_type): Likewise. (set_die_type, read_array_type, read_subrange_index_type) (read_tag_string_type, read_subrange_type): Update. * dwarf2/read.h (struct dwarf2_per_cu_data) : Declare methods. Change-Id: I07a42fa26e00795352389fa7a0cc1c12997d26f7 --- diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 17d7c954a71..6bce0eb8159 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,35 @@ +2020-02-08 Tom Tromey + + * dwarf2/loc.c (dwarf2_find_location_expression) + (dwarf_evaluate_loc_desc::get_tls_address) + (dwarf_evaluate_loc_desc::push_dwarf_reg_entry_value) + (rw_pieced_value, dwarf2_evaluate_loc_desc_full) + (dwarf2_locexpr_baton_eval, dwarf2_evaluate_property) + (dwarf2_compile_property_to_c) + (dwarf2_loc_desc_get_symbol_read_needs) + (dwarf2_compile_expr_to_ax, locexpr_describe_location) + (locexpr_tracepoint_var_ref, locexpr_generate_c_location) + (loclist_describe_location, loclist_tracepoint_var_ref) + (loclist_generate_c_location): Update. + * compile/compile-loc2c.c (do_compile_dwarf_expr_to_c): Update. + * dwarf2/loc.h (dwarf2_per_cu_objfile, dwarf2_per_cu_addr_size) + (dwarf2_per_cu_ref_addr_size, dwarf2_per_cu_offset_size) + (dwarf2_per_cu_text_offset, dwarf2_version): Don't declare. + * dwarf2/read.c (dwarf2_per_cu_data::objfile) + (dwarf2_per_cu_data::addr_size) + (dwarf2_per_cu_data::ref_addr_size) + (dwarf2_per_cu_data::text_offset) + (dwarf2_per_cu_data::addr_type): Now methods. + (per_cu_header_read_in): Make per_cu "const". + (dwarf2_version): Remove. + (dwarf2_per_cu_data::int_type): Now a method. + (dwarf2_per_cu_data::_addr_sized_int_type): Likewise. + (set_die_type, read_array_type, read_subrange_index_type) + (read_tag_string_type, read_subrange_type): Update. + * dwarf2/read.h (struct dwarf2_per_cu_data) : Declare methods. + 2020-02-08 Tom Tromey * dwarf2/read.h (struct dwarf2_per_cu_data) : diff --git a/gdb/compile/compile-loc2c.c b/gdb/compile/compile-loc2c.c index 636c929b022..06a044de048 100644 --- a/gdb/compile/compile-loc2c.c +++ b/gdb/compile/compile-loc2c.c @@ -21,6 +21,7 @@ #include "dwarf2.h" #include "dwarf2/expr.h" #include "dwarf2/loc.h" +#include "dwarf2/read.h" #include "ui-file.h" #include "utils.h" #include "compile-internal.h" @@ -718,7 +719,7 @@ do_compile_dwarf_expr_to_c (int indent, string_file *stream, index, not an address. We don't support things like branching between the address and the TLS op. */ if (op_ptr >= op_end || *op_ptr != DW_OP_GNU_push_tls_address) - uoffset += dwarf2_per_cu_text_offset (per_cu); + uoffset += per_cu->text_offset (); push (indent, stream, uoffset); break; diff --git a/gdb/dwarf2/loc.c b/gdb/dwarf2/loc.c index e337a02d473..ad13e8920ff 100644 --- a/gdb/dwarf2/loc.c +++ b/gdb/dwarf2/loc.c @@ -312,13 +312,13 @@ const gdb_byte * dwarf2_find_location_expression (struct dwarf2_loclist_baton *baton, size_t *locexpr_length, CORE_ADDR pc) { - struct objfile *objfile = dwarf2_per_cu_objfile (baton->per_cu); + struct objfile *objfile = baton->per_cu->objfile (); struct gdbarch *gdbarch = get_objfile_arch (objfile); enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); - unsigned int addr_size = dwarf2_per_cu_addr_size (baton->per_cu); + unsigned int addr_size = baton->per_cu->addr_size (); int signed_addr_p = bfd_get_sign_extend_vma (objfile->obfd); /* Adjust base_address for relocatable objects. */ - CORE_ADDR base_offset = dwarf2_per_cu_text_offset (baton->per_cu); + CORE_ADDR base_offset = baton->per_cu->text_offset (); CORE_ADDR base_address = baton->base_address + base_offset; const gdb_byte *loc_ptr, *buf_end; @@ -336,7 +336,7 @@ dwarf2_find_location_expression (struct dwarf2_loclist_baton *baton, kind = decode_debug_loc_dwo_addresses (baton->per_cu, loc_ptr, buf_end, &new_ptr, &low, &high, byte_order); - else if (dwarf2_version (baton->per_cu) < 5) + else if (baton->per_cu->version () < 5) kind = decode_debug_loc_addresses (loc_ptr, buf_end, &new_ptr, &low, &high, byte_order, addr_size, @@ -382,7 +382,7 @@ dwarf2_find_location_expression (struct dwarf2_loclist_baton *baton, high += base_address; } - if (dwarf2_version (baton->per_cu) < 5) + if (baton->per_cu->version () < 5) { length = extract_unsigned_integer (loc_ptr, 2, byte_order); loc_ptr += 2; @@ -643,7 +643,7 @@ class dwarf_evaluate_loc_desc : public dwarf_expr_context current thread's thread-local storage with offset OFFSET. */ CORE_ADDR get_tls_address (CORE_ADDR offset) override { - struct objfile *objfile = dwarf2_per_cu_objfile (per_cu); + struct objfile *objfile = per_cu->objfile (); return target_translate_tls_address (objfile, offset); } @@ -730,12 +730,11 @@ class dwarf_evaluate_loc_desc : public dwarf_expr_context (CORE_ADDR) 0); scoped_restore save_arch = make_scoped_restore (&this->gdbarch); - this->gdbarch - = get_objfile_arch (dwarf2_per_cu_objfile (per_cu)); + this->gdbarch = get_objfile_arch (per_cu->objfile ()); scoped_restore save_addr_size = make_scoped_restore (&this->addr_size); - this->addr_size = dwarf2_per_cu_addr_size (per_cu); + this->addr_size = per_cu->addr_size (); scoped_restore save_offset = make_scoped_restore (&this->offset); - this->offset = dwarf2_per_cu_text_offset (per_cu); + this->offset = per_cu->text_offset (); this->eval (data_src, size); } @@ -1819,7 +1818,7 @@ rw_pieced_value (struct value *v, struct value *from) break; } - struct objfile *objfile = dwarf2_per_cu_objfile (c->per_cu); + struct objfile *objfile = c->per_cu->objfile (); struct gdbarch *objfile_gdbarch = get_objfile_arch (objfile); ULONGEST stack_value_size_bits = 8 * TYPE_LENGTH (value_type (p->v.value)); @@ -2176,7 +2175,7 @@ dwarf2_evaluate_loc_desc_full (struct type *type, struct frame_info *frame, LONGEST subobj_byte_offset) { struct value *retval; - struct objfile *objfile = dwarf2_per_cu_objfile (per_cu); + struct objfile *objfile = per_cu->objfile (); if (subobj_type == NULL) { @@ -2197,9 +2196,9 @@ dwarf2_evaluate_loc_desc_full (struct type *type, struct frame_info *frame, scoped_value_mark free_values; ctx.gdbarch = get_objfile_arch (objfile); - ctx.addr_size = dwarf2_per_cu_addr_size (per_cu); - ctx.ref_addr_size = dwarf2_per_cu_ref_addr_size (per_cu); - ctx.offset = dwarf2_per_cu_text_offset (per_cu); + ctx.addr_size = per_cu->addr_size (); + ctx.ref_addr_size = per_cu->ref_addr_size (); + ctx.offset = per_cu->text_offset (); try { @@ -2411,12 +2410,12 @@ dwarf2_locexpr_baton_eval (const struct dwarf2_locexpr_baton *dlbaton, ctx.per_cu = dlbaton->per_cu; ctx.obj_address = addr; - objfile = dwarf2_per_cu_objfile (dlbaton->per_cu); + objfile = dlbaton->per_cu->objfile (); ctx.gdbarch = get_objfile_arch (objfile); - ctx.addr_size = dwarf2_per_cu_addr_size (dlbaton->per_cu); - ctx.ref_addr_size = dwarf2_per_cu_ref_addr_size (dlbaton->per_cu); - ctx.offset = dwarf2_per_cu_text_offset (dlbaton->per_cu); + ctx.addr_size = dlbaton->per_cu->addr_size (); + ctx.ref_addr_size = dlbaton->per_cu->ref_addr_size (); + ctx.offset = dlbaton->per_cu->text_offset (); try { @@ -2504,7 +2503,7 @@ dwarf2_evaluate_property (const struct dynamic_prop *prop, CORE_ADDR on 64bit machine has 8 bytes but address size of an 32bit application is bytes. */ const int addr_size - = (dwarf2_per_cu_addr_size (baton->locexpr.per_cu) + = (baton->locexpr.per_cu->addr_size () * TARGET_CHAR_BIT); const CORE_ADDR neg_mask = (~((CORE_ADDR) 0) << (addr_size - 1)); @@ -2610,7 +2609,7 @@ dwarf2_compile_property_to_c (string_file *stream, compile_dwarf_bounds_to_c (stream, result_name, prop, sym, pc, gdbarch, registers_used, - dwarf2_per_cu_addr_size (per_cu), + per_cu->addr_size (), data, data + size, per_cu); } @@ -2732,7 +2731,7 @@ dwarf2_loc_desc_get_symbol_read_needs (const gdb_byte *data, size_t size, struct dwarf2_per_cu_data *per_cu) { int in_reg; - struct objfile *objfile = dwarf2_per_cu_objfile (per_cu); + struct objfile *objfile = per_cu->objfile (); scoped_value_mark free_values; @@ -2741,9 +2740,9 @@ dwarf2_loc_desc_get_symbol_read_needs (const gdb_byte *data, size_t size, ctx.needs = SYMBOL_NEEDS_NONE; ctx.per_cu = per_cu; ctx.gdbarch = get_objfile_arch (objfile); - ctx.addr_size = dwarf2_per_cu_addr_size (per_cu); - ctx.ref_addr_size = dwarf2_per_cu_ref_addr_size (per_cu); - ctx.offset = dwarf2_per_cu_text_offset (per_cu); + ctx.addr_size = per_cu->addr_size (); + ctx.ref_addr_size = per_cu->ref_addr_size (); + ctx.offset = per_cu->text_offset (); ctx.eval (data, size); @@ -2984,7 +2983,7 @@ dwarf2_compile_expr_to_ax (struct agent_expr *expr, struct axs_value *loc, index, not an address. We don't support things like branching between the address and the TLS op. */ if (op_ptr >= op_end || *op_ptr != DW_OP_GNU_push_tls_address) - uoffset += dwarf2_per_cu_text_offset (per_cu); + uoffset += per_cu->text_offset (); ax_const_l (expr, uoffset); break; @@ -4292,9 +4291,9 @@ locexpr_describe_location (struct symbol *symbol, CORE_ADDR addr, { struct dwarf2_locexpr_baton *dlbaton = (struct dwarf2_locexpr_baton *) SYMBOL_LOCATION_BATON (symbol); - struct objfile *objfile = dwarf2_per_cu_objfile (dlbaton->per_cu); - unsigned int addr_size = dwarf2_per_cu_addr_size (dlbaton->per_cu); - int offset_size = dwarf2_per_cu_offset_size (dlbaton->per_cu); + struct objfile *objfile = dlbaton->per_cu->objfile (); + unsigned int addr_size = dlbaton->per_cu->addr_size (); + int offset_size = dlbaton->per_cu->offset_size (); locexpr_describe_location_1 (symbol, addr, stream, dlbaton->data, dlbaton->size, @@ -4311,7 +4310,7 @@ locexpr_tracepoint_var_ref (struct symbol *symbol, struct agent_expr *ax, { struct dwarf2_locexpr_baton *dlbaton = (struct dwarf2_locexpr_baton *) SYMBOL_LOCATION_BATON (symbol); - unsigned int addr_size = dwarf2_per_cu_addr_size (dlbaton->per_cu); + unsigned int addr_size = dlbaton->per_cu->addr_size (); if (dlbaton->size == 0) value->optimized_out = 1; @@ -4330,7 +4329,7 @@ locexpr_generate_c_location (struct symbol *sym, string_file *stream, { struct dwarf2_locexpr_baton *dlbaton = (struct dwarf2_locexpr_baton *) SYMBOL_LOCATION_BATON (sym); - unsigned int addr_size = dwarf2_per_cu_addr_size (dlbaton->per_cu); + unsigned int addr_size = dlbaton->per_cu->addr_size (); if (dlbaton->size == 0) error (_("symbol \"%s\" is optimized out"), sym->natural_name ()); @@ -4429,14 +4428,14 @@ loclist_describe_location (struct symbol *symbol, CORE_ADDR addr, struct dwarf2_loclist_baton *dlbaton = (struct dwarf2_loclist_baton *) SYMBOL_LOCATION_BATON (symbol); const gdb_byte *loc_ptr, *buf_end; - struct objfile *objfile = dwarf2_per_cu_objfile (dlbaton->per_cu); + struct objfile *objfile = dlbaton->per_cu->objfile (); struct gdbarch *gdbarch = get_objfile_arch (objfile); enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); - unsigned int addr_size = dwarf2_per_cu_addr_size (dlbaton->per_cu); - int offset_size = dwarf2_per_cu_offset_size (dlbaton->per_cu); + unsigned int addr_size = dlbaton->per_cu->addr_size (); + int offset_size = dlbaton->per_cu->offset_size (); int signed_addr_p = bfd_get_sign_extend_vma (objfile->obfd); /* Adjust base_address for relocatable objects. */ - CORE_ADDR base_offset = dwarf2_per_cu_text_offset (dlbaton->per_cu); + CORE_ADDR base_offset = dlbaton->per_cu->text_offset (); CORE_ADDR base_address = dlbaton->base_address + base_offset; int done = 0; @@ -4520,7 +4519,7 @@ loclist_tracepoint_var_ref (struct symbol *symbol, struct agent_expr *ax, = (struct dwarf2_loclist_baton *) SYMBOL_LOCATION_BATON (symbol); const gdb_byte *data; size_t size; - unsigned int addr_size = dwarf2_per_cu_addr_size (dlbaton->per_cu); + unsigned int addr_size = dlbaton->per_cu->addr_size (); data = dwarf2_find_location_expression (dlbaton, &size, ax->scope); if (size == 0) @@ -4540,7 +4539,7 @@ loclist_generate_c_location (struct symbol *sym, string_file *stream, { struct dwarf2_loclist_baton *dlbaton = (struct dwarf2_loclist_baton *) SYMBOL_LOCATION_BATON (sym); - unsigned int addr_size = dwarf2_per_cu_addr_size (dlbaton->per_cu); + unsigned int addr_size = dlbaton->per_cu->addr_size (); const gdb_byte *data; size_t size; diff --git a/gdb/dwarf2/loc.h b/gdb/dwarf2/loc.h index a49a9903b11..2cc7e066a33 100644 --- a/gdb/dwarf2/loc.h +++ b/gdb/dwarf2/loc.h @@ -35,29 +35,6 @@ struct axs_value; /* `set debug entry-values' setting. */ extern unsigned int entry_values_debug; -/* Return the OBJFILE associated with the compilation unit CU. If CU - came from a separate debuginfo file, then the master objfile is - returned. */ -struct objfile *dwarf2_per_cu_objfile (struct dwarf2_per_cu_data *cu); - -/* Return the address size given in the compilation unit header for CU. */ -int dwarf2_per_cu_addr_size (struct dwarf2_per_cu_data *cu); - -/* Return the DW_FORM_ref_addr size given in the compilation unit header for - CU. */ -int dwarf2_per_cu_ref_addr_size (struct dwarf2_per_cu_data *cu); - -/* Return the offset size given in the compilation unit header for CU. */ -int dwarf2_per_cu_offset_size (struct dwarf2_per_cu_data *cu); - -/* Return the text offset of the CU. The returned offset comes from - this CU's objfile. If this objfile came from a separate debuginfo - file, then the offset may be different from the corresponding - offset in the parent objfile. */ -CORE_ADDR dwarf2_per_cu_text_offset (struct dwarf2_per_cu_data *cu); - -short dwarf2_version (struct dwarf2_per_cu_data *per_cu); - /* Find a particular location expression from a location list. */ const gdb_byte *dwarf2_find_location_expression (struct dwarf2_loclist_baton *baton, diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c index 9501a9eff59..474ed4d9b49 100644 --- a/gdb/dwarf2/read.c +++ b/gdb/dwarf2/read.c @@ -1639,13 +1639,6 @@ static void queue_comp_unit (struct dwarf2_per_cu_data *per_cu, static void process_queue (struct dwarf2_per_objfile *dwarf2_per_objfile); -static struct type *dwarf2_per_cu_addr_type (struct dwarf2_per_cu_data *per_cu); -static struct type *dwarf2_per_cu_addr_sized_int_type - (struct dwarf2_per_cu_data *per_cu, bool unsigned_p); -static struct type *dwarf2_per_cu_int_type - (struct dwarf2_per_cu_data *per_cu, int size_in_bytes, - bool unsigned_p); - /* Class, the destructor of which frees all allocated queue entries. This will only have work to do if an error was thrown while processing the dwarf. If no error was thrown then the queue entries should have all @@ -13169,7 +13162,7 @@ read_func_scope (struct die_info *die, struct dwarf2_cu *cu) newobj->static_link = XOBNEW (&objfile->objfile_obstack, struct dynamic_prop); attr_to_dynamic_prop (attr, die, cu, newobj->static_link, - dwarf2_per_cu_addr_type (cu->per_cu)); + cu->per_cu->addr_type ()); } cu->list_in_scope = cu->get_builder ()->get_local_symbols (); @@ -16006,8 +15999,7 @@ read_array_type (struct die_info *die, struct dwarf2_cu *cu) if (attr != NULL) { int stride_ok; - struct type *prop_type - = dwarf2_per_cu_addr_sized_int_type (cu->per_cu, false); + struct type *prop_type = cu->per_cu->addr_sized_int_type (false); byte_stride_prop = (struct dynamic_prop *) alloca (sizeof (struct dynamic_prop)); @@ -16809,13 +16801,13 @@ read_tag_string_type (struct die_info *die, struct dwarf2_cu *cu) /* Pass 0 as the default as we know this attribute is constant and the default value will not be returned. */ LONGEST sz = dwarf2_get_attr_constant_value (len, 0); - prop_type = dwarf2_per_cu_int_type (cu->per_cu, sz, true); + prop_type = cu->per_cu->int_type (sz, true); } else { /* If the size is not specified then we assume it is the size of an address on this target. */ - prop_type = dwarf2_per_cu_addr_sized_int_type (cu->per_cu, true); + prop_type = cu->per_cu->addr_sized_int_type (true); } /* Convert the attribute into a dynamic property. */ @@ -17417,14 +17409,12 @@ attr_to_dynamic_prop (const struct attribute *attr, struct die_info *die, return 1; } -/* Find an integer type SIZE_IN_BYTES bytes in size and return it. - UNSIGNED_P controls if the integer is unsigned or not. */ +/* See read.h. */ -static struct type * -dwarf2_per_cu_int_type (struct dwarf2_per_cu_data *per_cu, - int size_in_bytes, bool unsigned_p) +struct type * +dwarf2_per_cu_data::int_type (int size_in_bytes, bool unsigned_p) const { - struct objfile *objfile = per_cu->dwarf2_per_objfile->objfile; + struct objfile *objfile = dwarf2_per_objfile->objfile; struct type *int_type; /* Helper macro to examine the various builtin types. */ @@ -17446,16 +17436,13 @@ dwarf2_per_cu_int_type (struct dwarf2_per_cu_data *per_cu, gdb_assert_not_reached ("unable to find suitable integer type"); } -/* Find an integer type the same size as the address size given in the - compilation unit header for PER_CU. UNSIGNED_P controls if the integer - is unsigned or not. */ +/* See read.h. */ -static struct type * -dwarf2_per_cu_addr_sized_int_type (struct dwarf2_per_cu_data *per_cu, - bool unsigned_p) +struct type * +dwarf2_per_cu_data::addr_sized_int_type (bool unsigned_p) const { - int addr_size = dwarf2_per_cu_addr_size (per_cu); - return dwarf2_per_cu_int_type (per_cu, addr_size, unsigned_p); + int addr_size = this->addr_size (); + return int_type (addr_size, unsigned_p); } /* Read the DW_AT_type attribute for a sub-range. If this attribute is not @@ -17480,7 +17467,7 @@ read_subrange_index_type (struct die_info *die, struct dwarf2_cu *cu) FIXME: muller/2010-05-28: Possible references to object for low bound, high bound or count are not yet handled by this code. */ if (TYPE_CODE (index_type) == TYPE_CODE_VOID) - index_type = dwarf2_per_cu_addr_sized_int_type (cu->per_cu, false); + index_type = cu->per_cu->addr_sized_int_type (false); return index_type; } @@ -17610,8 +17597,7 @@ read_subrange_type (struct die_info *die, struct dwarf2_cu *cu) attribute *attr_byte_stride = dwarf2_attr (die, DW_AT_byte_stride, cu); if (attr_byte_stride != nullptr) { - struct type *prop_type - = dwarf2_per_cu_addr_sized_int_type (cu->per_cu, false); + struct type *prop_type = cu->per_cu->addr_sized_int_type (false); attr_to_dynamic_prop (attr_byte_stride, die, cu, &byte_stride_prop, prop_type); } @@ -17631,8 +17617,7 @@ read_subrange_type (struct die_info *die, struct dwarf2_cu *cu) } else { - struct type *prop_type - = dwarf2_per_cu_addr_sized_int_type (cu->per_cu, false); + struct type *prop_type = cu->per_cu->addr_sized_int_type (false); attr_to_dynamic_prop (attr_bit_stride, die, cu, &bit_stride_prop, prop_type); } @@ -24523,14 +24508,12 @@ dwarf2_symbol_mark_computed (const struct attribute *attr, struct symbol *sym, } } -/* Return the OBJFILE associated with the compilation unit CU. If CU - came from a separate debuginfo file, then the master objfile is - returned. */ +/* See read.h. */ struct objfile * -dwarf2_per_cu_objfile (struct dwarf2_per_cu_data *per_cu) +dwarf2_per_cu_data::objfile () const { - struct objfile *objfile = per_cu->dwarf2_per_objfile->objfile; + struct objfile *objfile = dwarf2_per_objfile->objfile; /* Return the master objfile, so that we can report and look up the correct file containing this variable. */ @@ -24546,7 +24529,7 @@ dwarf2_per_cu_objfile (struct dwarf2_per_cu_data *per_cu) static const struct comp_unit_head * per_cu_header_read_in (struct comp_unit_head *cu_headerp, - struct dwarf2_per_cu_data *per_cu) + const struct dwarf2_per_cu_data *per_cu) { const gdb_byte *info_ptr; @@ -24562,41 +24545,41 @@ per_cu_header_read_in (struct comp_unit_head *cu_headerp, return cu_headerp; } -/* Return the address size given in the compilation unit header for CU. */ +/* See read.h. */ int -dwarf2_per_cu_addr_size (struct dwarf2_per_cu_data *per_cu) +dwarf2_per_cu_data::addr_size () const { struct comp_unit_head cu_header_local; const struct comp_unit_head *cu_headerp; - cu_headerp = per_cu_header_read_in (&cu_header_local, per_cu); + cu_headerp = per_cu_header_read_in (&cu_header_local, this); return cu_headerp->addr_size; } -/* Return the offset size given in the compilation unit header for CU. */ +/* See read.h. */ int -dwarf2_per_cu_offset_size (struct dwarf2_per_cu_data *per_cu) +dwarf2_per_cu_data::offset_size () const { struct comp_unit_head cu_header_local; const struct comp_unit_head *cu_headerp; - cu_headerp = per_cu_header_read_in (&cu_header_local, per_cu); + cu_headerp = per_cu_header_read_in (&cu_header_local, this); return cu_headerp->offset_size; } -/* See its dwarf2loc.h declaration. */ +/* See read.h. */ int -dwarf2_per_cu_ref_addr_size (struct dwarf2_per_cu_data *per_cu) +dwarf2_per_cu_data::ref_addr_size () const { struct comp_unit_head cu_header_local; const struct comp_unit_head *cu_headerp; - cu_headerp = per_cu_header_read_in (&cu_header_local, per_cu); + cu_headerp = per_cu_header_read_in (&cu_header_local, this); if (cu_headerp->version == 2) return cu_headerp->addr_size; @@ -24604,43 +24587,33 @@ dwarf2_per_cu_ref_addr_size (struct dwarf2_per_cu_data *per_cu) return cu_headerp->offset_size; } -/* Return the text offset of the CU. The returned offset comes from - this CU's objfile. If this objfile came from a separate debuginfo - file, then the offset may be different from the corresponding - offset in the parent objfile. */ +/* See read.h. */ CORE_ADDR -dwarf2_per_cu_text_offset (struct dwarf2_per_cu_data *per_cu) +dwarf2_per_cu_data::text_offset () const { - return per_cu->dwarf2_per_objfile->objfile->text_section_offset (); + struct objfile *objfile = dwarf2_per_objfile->objfile; + + return objfile->text_section_offset (); } -/* Return a type that is a generic pointer type, the size of which matches - the address size given in the compilation unit header for PER_CU. */ -static struct type * -dwarf2_per_cu_addr_type (struct dwarf2_per_cu_data *per_cu) +/* See read.h. */ + +struct type * +dwarf2_per_cu_data::addr_type () const { - struct objfile *objfile = per_cu->dwarf2_per_objfile->objfile; + struct objfile *objfile = dwarf2_per_objfile->objfile; struct type *void_type = objfile_type (objfile)->builtin_void; struct type *addr_type = lookup_pointer_type (void_type); - int addr_size = dwarf2_per_cu_addr_size (per_cu); + int addr_size = this->addr_size (); if (TYPE_LENGTH (addr_type) == addr_size) return addr_type; - addr_type - = dwarf2_per_cu_addr_sized_int_type (per_cu, TYPE_UNSIGNED (addr_type)); + addr_type = addr_sized_int_type (TYPE_UNSIGNED (addr_type)); return addr_type; } -/* Return DWARF version number of PER_CU. */ - -short -dwarf2_version (struct dwarf2_per_cu_data *per_cu) -{ - return per_cu->dwarf_version; -} - /* Locate the .debug_info compilation unit from CU's objfile which contains the DIE at OFFSET. Raises an error on failure. */ @@ -24899,8 +24872,7 @@ set_die_type (struct die_info *die, struct type *type, struct dwarf2_cu *cu) attr = dwarf2_attr (die, DW_AT_allocated, cu); if (attr != NULL && attr->form_is_block ()) { - struct type *prop_type - = dwarf2_per_cu_addr_sized_int_type (cu->per_cu, false); + struct type *prop_type = cu->per_cu->addr_sized_int_type (false); if (attr_to_dynamic_prop (attr, die, cu, &prop, prop_type)) add_dyn_prop (DYN_PROP_ALLOCATED, prop, type); } @@ -24915,8 +24887,7 @@ set_die_type (struct die_info *die, struct type *type, struct dwarf2_cu *cu) attr = dwarf2_attr (die, DW_AT_associated, cu); if (attr != NULL && attr->form_is_block ()) { - struct type *prop_type - = dwarf2_per_cu_addr_sized_int_type (cu->per_cu, false); + struct type *prop_type = cu->per_cu->addr_sized_int_type (false); if (attr_to_dynamic_prop (attr, die, cu, &prop, prop_type)) add_dyn_prop (DYN_PROP_ASSOCIATED, prop, type); } @@ -24930,7 +24901,7 @@ set_die_type (struct die_info *die, struct type *type, struct dwarf2_cu *cu) /* Read DW_AT_data_location and set in type. */ attr = dwarf2_attr (die, DW_AT_data_location, cu); if (attr_to_dynamic_prop (attr, die, cu, &prop, - dwarf2_per_cu_addr_type (cu->per_cu))) + cu->per_cu->addr_type ())) add_dyn_prop (DYN_PROP_DATA_LOCATION, prop, type); if (dwarf2_per_objfile->die_type_hash == NULL) diff --git a/gdb/dwarf2/read.h b/gdb/dwarf2/read.h index f76937c83fa..b06c2e218c1 100644 --- a/gdb/dwarf2/read.h +++ b/gdb/dwarf2/read.h @@ -394,6 +394,49 @@ struct dwarf2_per_cu_data delete imported_symtabs; imported_symtabs = nullptr; } + + /* Return the OBJFILE associated with this compilation unit. If + this compilation unit came from a separate debuginfo file, then + the master objfile is returned. */ + struct objfile *objfile () const; + + /* Return the address size given in the compilation unit header for + this CU. */ + int addr_size () const; + + /* Return the offset size given in the compilation unit header for + this CU. */ + int offset_size () const; + + /* Return the DW_FORM_ref_addr size given in the compilation unit + header for this CU. */ + int ref_addr_size () const; + + /* Return the text offset of the CU. The returned offset comes from + this CU's objfile. If this objfile came from a separate + debuginfo file, then the offset may be different from the + corresponding offset in the parent objfile. */ + CORE_ADDR text_offset () const; + + /* Return a type that is a generic pointer type, the size of which + matches the address size given in the compilation unit header for + this CU. */ + struct type *addr_type () const; + + /* Find an integer type SIZE_IN_BYTES bytes in size and return it. + UNSIGNED_P controls if the integer is unsigned or not. */ + struct type *int_type (int size_in_bytes, bool unsigned_p) const; + + /* Find an integer type the same size as the address size given in + the compilation unit header for this CU. UNSIGNED_P controls if + the integer is unsigned or not. */ + struct type *addr_sized_int_type (bool unsigned_p) const; + + /* Return DWARF version number of this CU. */ + short version () const + { + return dwarf_version; + } }; /* Entry in the signatured_types hash table. */