aboutsummaryrefslogtreecommitdiff
path: root/gdb
diff options
context:
space:
mode:
authorTom Tromey <tom@tromey.com>2020-02-08 13:40:54 -0700
committerTom Tromey <tom@tromey.com>2020-02-08 13:43:24 -0700
commitc8a7a66fb7c0bbc9c6f9cd896e20d9523a0d0900 (patch)
treee516ed0491bec503989bf23fecb131a2564ed241 /gdb
parent8266302dc32a88c9e05b4e451e3c2c1516603132 (diff)
downloadgdb-c8a7a66fb7c0bbc9c6f9cd896e20d9523a0d0900.zip
gdb-c8a7a66fb7c0bbc9c6f9cd896e20d9523a0d0900.tar.gz
gdb-c8a7a66fb7c0bbc9c6f9cd896e20d9523a0d0900.tar.bz2
Convert read_address to a method on comp_unit_head
This changes read_address to be a method on comp_unit_head. 2020-02-08 Tom Tromey <tom@tromey.com> * dwarf2/read.c (read_address): Move to comp-unit.c. (dwarf2_rnglists_process, dwarf2_ranges_process) (read_attribute_value, dwarf_decode_lines_1) (var_decode_location, decode_locdesc): Update. * dwarf2/comp-unit.c (comp_unit_head::read_address): Move from read.c. Remove "cu" parameter. * dwarf2/comp-unit.h (struct comp_unit_head) <read_address>: New method. Change-Id: Ibd6c7235f2e4d5fd88c272cfd2c3d3328618cc56
Diffstat (limited to 'gdb')
-rw-r--r--gdb/ChangeLog11
-rw-r--r--gdb/dwarf2/comp-unit.c50
-rw-r--r--gdb/dwarf2/comp-unit.h4
-rw-r--r--gdb/dwarf2/read.c87
4 files changed, 83 insertions, 69 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index db821ff..7755548 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,16 @@
2020-02-08 Tom Tromey <tom@tromey.com>
+ * dwarf2/read.c (read_address): Move to comp-unit.c.
+ (dwarf2_rnglists_process, dwarf2_ranges_process)
+ (read_attribute_value, dwarf_decode_lines_1)
+ (var_decode_location, decode_locdesc): Update.
+ * dwarf2/comp-unit.c (comp_unit_head::read_address): Move from
+ read.c. Remove "cu" parameter.
+ * dwarf2/comp-unit.h (struct comp_unit_head) <read_address>: New
+ method.
+
+2020-02-08 Tom Tromey <tom@tromey.com>
+
* dwarf2/read.c (read_attribute_value, read_indirect_string)
(read_indirect_line_string): Update.
* dwarf2/comp-unit.c (read_offset): Remove.
diff --git a/gdb/dwarf2/comp-unit.c b/gdb/dwarf2/comp-unit.c
index 847a148..0b6629f 100644
--- a/gdb/dwarf2/comp-unit.c
+++ b/gdb/dwarf2/comp-unit.c
@@ -221,3 +221,53 @@ read_and_check_comp_unit_head (struct dwarf2_per_objfile *dwarf2_per_objfile,
return info_ptr;
}
+
+CORE_ADDR
+comp_unit_head::read_address (bfd *abfd, const gdb_byte *buf,
+ unsigned int *bytes_read) const
+{
+ CORE_ADDR retval = 0;
+
+ if (signed_addr_p)
+ {
+ switch (addr_size)
+ {
+ case 2:
+ retval = bfd_get_signed_16 (abfd, buf);
+ break;
+ case 4:
+ retval = bfd_get_signed_32 (abfd, buf);
+ break;
+ case 8:
+ retval = bfd_get_signed_64 (abfd, buf);
+ break;
+ default:
+ internal_error (__FILE__, __LINE__,
+ _("read_address: bad switch, signed [in module %s]"),
+ bfd_get_filename (abfd));
+ }
+ }
+ else
+ {
+ switch (addr_size)
+ {
+ case 2:
+ retval = bfd_get_16 (abfd, buf);
+ break;
+ case 4:
+ retval = bfd_get_32 (abfd, buf);
+ break;
+ case 8:
+ retval = bfd_get_64 (abfd, buf);
+ break;
+ default:
+ internal_error (__FILE__, __LINE__,
+ _("read_address: bad switch, "
+ "unsigned [in module %s]"),
+ bfd_get_filename (abfd));
+ }
+ }
+
+ *bytes_read = addr_size;
+ return retval;
+}
diff --git a/gdb/dwarf2/comp-unit.h b/gdb/dwarf2/comp-unit.h
index e61b100..2dd8090 100644
--- a/gdb/dwarf2/comp-unit.h
+++ b/gdb/dwarf2/comp-unit.h
@@ -89,6 +89,10 @@ struct comp_unit_head
*bytes_read = offset_size;
return offset;
}
+
+ /* Read an address from BUF. BYTES_READ is updated. */
+ CORE_ADDR read_address (bfd *abfd, const gdb_byte *buf,
+ unsigned int *bytes_read) const;
};
/* Expected enum dwarf_unit_type for read_comp_unit_head. */
diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index 8ea0b60..d340906 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -1238,9 +1238,6 @@ static void read_attribute_reprocess (const struct die_reader_specs *reader,
static CORE_ADDR read_addr_index (struct dwarf2_cu *cu, unsigned int addr_index);
-static CORE_ADDR read_address (bfd *, const gdb_byte *ptr, struct dwarf2_cu *,
- unsigned int *);
-
static LONGEST read_checked_initial_length_and_offset
(bfd *, const gdb_byte *, const struct comp_unit_head *,
unsigned int *, unsigned int *);
@@ -13514,7 +13511,7 @@ dwarf2_rnglists_process (unsigned offset, struct dwarf2_cu *cu,
overflow = true;
break;
}
- base = read_address (obfd, buffer, cu, &bytes_read);
+ base = cu->header.read_address (obfd, buffer, &bytes_read);
found_base = 1;
buffer += bytes_read;
break;
@@ -13524,7 +13521,8 @@ dwarf2_rnglists_process (unsigned offset, struct dwarf2_cu *cu,
overflow = true;
break;
}
- range_beginning = read_address (obfd, buffer, cu, &bytes_read);
+ range_beginning = cu->header.read_address (obfd, buffer,
+ &bytes_read);
buffer += bytes_read;
range_end = (range_beginning
+ read_unsigned_leb128 (obfd, buffer, &bytes_read));
@@ -13557,9 +13555,10 @@ dwarf2_rnglists_process (unsigned offset, struct dwarf2_cu *cu,
overflow = true;
break;
}
- range_beginning = read_address (obfd, buffer, cu, &bytes_read);
+ range_beginning = cu->header.read_address (obfd, buffer,
+ &bytes_read);
buffer += bytes_read;
- range_end = read_address (obfd, buffer, cu, &bytes_read);
+ range_end = cu->header.read_address (obfd, buffer, &bytes_read);
buffer += bytes_read;
break;
default:
@@ -13662,9 +13661,9 @@ dwarf2_ranges_process (unsigned offset, struct dwarf2_cu *cu,
{
CORE_ADDR range_beginning, range_end;
- range_beginning = read_address (obfd, buffer, cu, &dummy);
+ range_beginning = cu->header.read_address (obfd, buffer, &dummy);
buffer += addr_size;
- range_end = read_address (obfd, buffer, cu, &dummy);
+ range_end = cu->header.read_address (obfd, buffer, &dummy);
buffer += addr_size;
offset += 2 * addr_size;
@@ -18446,7 +18445,8 @@ read_attribute_value (const struct die_reader_specs *reader,
{
case DW_FORM_ref_addr:
if (cu->header.version == 2)
- DW_UNSND (attr) = read_address (abfd, info_ptr, cu, &bytes_read);
+ DW_UNSND (attr) = cu->header.read_address (abfd, info_ptr,
+ &bytes_read);
else
DW_UNSND (attr) = cu->header.read_offset (abfd, info_ptr,
&bytes_read);
@@ -18457,7 +18457,7 @@ read_attribute_value (const struct die_reader_specs *reader,
info_ptr += bytes_read;
break;
case DW_FORM_addr:
- DW_ADDR (attr) = read_address (abfd, info_ptr, cu, &bytes_read);
+ DW_ADDR (attr) = cu->header.read_address (abfd, info_ptr, &bytes_read);
DW_ADDR (attr) = gdbarch_adjust_dwarf2_addr (gdbarch, DW_ADDR (attr));
info_ptr += bytes_read;
break;
@@ -18704,57 +18704,6 @@ read_attribute (const struct die_reader_specs *reader,
need_reprocess);
}
-static CORE_ADDR
-read_address (bfd *abfd, const gdb_byte *buf, struct dwarf2_cu *cu,
- unsigned int *bytes_read)
-{
- struct comp_unit_head *cu_header = &cu->header;
- CORE_ADDR retval = 0;
-
- if (cu_header->signed_addr_p)
- {
- switch (cu_header->addr_size)
- {
- case 2:
- retval = bfd_get_signed_16 (abfd, buf);
- break;
- case 4:
- retval = bfd_get_signed_32 (abfd, buf);
- break;
- case 8:
- retval = bfd_get_signed_64 (abfd, buf);
- break;
- default:
- internal_error (__FILE__, __LINE__,
- _("read_address: bad switch, signed [in module %s]"),
- bfd_get_filename (abfd));
- }
- }
- else
- {
- switch (cu_header->addr_size)
- {
- case 2:
- retval = bfd_get_16 (abfd, buf);
- break;
- case 4:
- retval = bfd_get_32 (abfd, buf);
- break;
- case 8:
- retval = bfd_get_64 (abfd, buf);
- break;
- default:
- internal_error (__FILE__, __LINE__,
- _("read_address: bad switch, "
- "unsigned [in module %s]"),
- bfd_get_filename (abfd));
- }
- }
-
- *bytes_read = cu_header->addr_size;
- return retval;
-}
-
/* Cover function for read_initial_length.
Returns the length of the object at BUF, and stores the size of the
initial length in *BYTES_READ and stores the size that offsets will be in
@@ -20204,7 +20153,7 @@ dwarf_decode_lines_1 (struct line_header *lh, struct dwarf2_cu *cu,
case DW_LNE_set_address:
{
CORE_ADDR address
- = read_address (abfd, line_ptr, cu, &bytes_read);
+ = cu->header.read_address (abfd, line_ptr, &bytes_read);
line_ptr += bytes_read;
state_machine.check_line_address (cu, line_ptr,
@@ -20525,10 +20474,10 @@ var_decode_location (struct attribute *attr, struct symbol *sym,
unsigned int dummy;
if (DW_BLOCK (attr)->data[0] == DW_OP_addr)
- SET_SYMBOL_VALUE_ADDRESS (sym,
- read_address (objfile->obfd,
- DW_BLOCK (attr)->data + 1,
- cu, &dummy));
+ SET_SYMBOL_VALUE_ADDRESS
+ (sym, cu->header.read_address (objfile->obfd,
+ DW_BLOCK (attr)->data + 1,
+ &dummy));
else
SET_SYMBOL_VALUE_ADDRESS
(sym, read_addr_index_from_leb128 (cu, DW_BLOCK (attr)->data + 1,
@@ -22994,8 +22943,8 @@ decode_locdesc (struct dwarf_block *blk, struct dwarf2_cu *cu)
break;
case DW_OP_addr:
- stack[++stacki] = read_address (objfile->obfd, &data[i],
- cu, &bytes_read);
+ stack[++stacki] = cu->header.read_address (objfile->obfd, &data[i],
+ &bytes_read);
i += bytes_read;
break;