From: Tom Tromey <tom@tromey.com>
To: gdb-patches@sourceware.org
Cc: Tom Tromey <tom@tromey.com>
Subject: [PATCH 35/38] Convert read_address to a method on comp_unit_head
Date: Thu, 23 Jan 2020 00:57:00 -0000 [thread overview]
Message-ID: <20200123005710.7978-36-tom@tromey.com> (raw)
In-Reply-To: <20200123005710.7978-1-tom@tromey.com>
This changes read_address to be a method on comp_unit_head.
2020-01-22 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
---
gdb/ChangeLog | 11 ++++++
gdb/dwarf2/comp-unit.c | 50 ++++++++++++++++++++++++
gdb/dwarf2/comp-unit.h | 4 ++
gdb/dwarf2/read.c | 87 +++++++++---------------------------------
4 files changed, 83 insertions(+), 69 deletions(-)
diff --git a/gdb/dwarf2/comp-unit.c b/gdb/dwarf2/comp-unit.c
index 847a148cbd2..0b6629f14ce 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 e61b1000b9e..2dd80901b8f 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 7c0d1d21cb6..e47f7443a58 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -1243,9 +1243,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 *);
@@ -13559,7 +13556,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;
@@ -13569,7 +13566,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));
@@ -13602,9 +13600,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:
@@ -13707,9 +13706,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;
@@ -18491,7 +18490,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);
@@ -18502,7 +18502,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;
@@ -18749,57 +18749,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
@@ -20247,7 +20196,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,
@@ -20568,10 +20517,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,
@@ -23037,8 +22986,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;
--
2.17.2
next prev parent reply other threads:[~2020-01-23 0:57 UTC|newest]
Thread overview: 48+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-01-23 0:57 [PATCH 00/38] Start reorganization of DWARF code Tom Tromey
2020-01-23 0:57 ` [PATCH 30/38] Unify read_initial_length implementations Tom Tromey
2020-01-27 13:31 ` Christian Biesinger via gdb-patches
2020-01-28 0:54 ` Tom Tromey
2020-01-23 0:57 ` [PATCH 20/38] Minor cleanups in abbrev_table Tom Tromey
2020-01-23 0:57 ` [PATCH 24/38] Move dwarf_always_disassemble to dwarf2/loc.c Tom Tromey
2020-01-23 0:57 ` [PATCH 17/38] Don't allocate DWO file hash on obstack Tom Tromey
2020-01-23 0:57 ` [PATCH 09/38] Don't declare die_info in dwarf2read.h Tom Tromey
2020-01-23 0:57 ` [PATCH 25/38] Change file_full_name and file_file_name methods Tom Tromey
2020-01-27 13:31 ` Christian Biesinger via gdb-patches
2020-01-23 0:57 ` [PATCH 14/38] Change dwarf2_per_objfile::signatured_types to be htab_up Tom Tromey
2020-02-08 16:55 ` Simon Marchi
2020-01-23 0:57 ` [PATCH 18/38] Change dwp_file to use htab_up Tom Tromey
2020-01-23 0:57 ` [PATCH 12/38] Introduce die_info::has_children Tom Tromey
2020-01-23 0:57 ` [PATCH 04/38] Create dwarf2/abbrev.[ch] Tom Tromey
2020-01-23 0:57 ` [PATCH 28/38] Move dwarf2_per_cu_data::imported_symtabs earlier Tom Tromey
2020-01-23 0:57 ` [PATCH 10/38] Remove die_reader_specs::comp_dir Tom Tromey
2020-01-23 0:57 ` [PATCH 15/38] Change dwarf2_per_objfile::type_unit_groups to htab_up Tom Tromey
2020-01-23 0:57 ` [PATCH 36/38] Move two more functions to dwarf2/leb.h Tom Tromey
2020-01-23 0:57 ` [PATCH 34/38] Convert read_offset to method on comp_unit_head Tom Tromey
2020-01-23 0:57 ` [PATCH 21/38] Use htab_up in abbrev_table Tom Tromey
2020-01-23 0:57 ` [PATCH 02/38] Create dwarf2/section.[ch] Tom Tromey
2020-01-23 0:57 ` [PATCH 33/38] Create dwarf2/comp-unit.[ch] Tom Tromey
2020-01-23 0:57 ` [PATCH 23/38] Change dwarf2_per_objfile::quick_file_names_table to htab_up Tom Tromey
2020-01-23 0:57 ` [PATCH 01/38] Create dwarf2/leb.[ch] Tom Tromey
2020-01-23 0:57 ` [PATCH 08/38] Remove die_info_ptr typedef Tom Tromey
2020-01-23 0:57 ` [PATCH 11/38] Move DWARF code to dwarf2/ subdirectory Tom Tromey
2020-01-27 13:41 ` Christian Biesinger via gdb-patches
2020-01-28 3:12 ` Tom Tromey
2020-01-23 0:57 ` [PATCH 26/38] Change line_table methods to return unique_xmalloc_ptr Tom Tromey
2020-01-23 0:57 ` [PATCH 06/38] Change some attribute functions to be methods Tom Tromey
2020-01-23 0:57 ` [PATCH 16/38] Change dwarf2_per_objfile::line_header_hash to htab_up Tom Tromey
2020-01-23 0:57 ` [PATCH 07/38] Change attr_form_is_block to be a method Tom Tromey
2020-01-23 0:57 ` Tom Tromey [this message]
2020-01-23 0:57 ` [PATCH 19/38] Change dwarf2_per_objfile::die_type_hash to htab_up Tom Tromey
2020-01-23 0:57 ` [PATCH 31/38] Convert dwarf2_section_size to a method Tom Tromey
2020-01-23 0:57 ` [PATCH 05/38] Create dwarf2/attribute.[ch] Tom Tromey
2020-01-23 0:57 ` [PATCH 38/38] Remove "keep" parameter from cutu_reader constructor Tom Tromey
2020-02-08 17:36 ` Simon Marchi
2020-01-23 0:57 ` [PATCH 27/38] Move DWARF line_header to new file Tom Tromey
2020-01-23 0:57 ` [PATCH 13/38] Remove DWARF queue-related globals Tom Tromey
2020-01-23 0:57 ` [PATCH 22/38] Minor simplification in abbrev_table::read Tom Tromey
2020-01-23 0:57 ` [PATCH 32/38] Move read_offset_1 to leb.c Tom Tromey
2020-01-23 1:12 ` [PATCH 03/38] Change section functions to be methods of dwarf2_section_info Tom Tromey
2020-01-23 1:21 ` [PATCH 29/38] Add some methods to dwarf2_per_cu_data Tom Tromey
2020-01-23 2:34 ` [PATCH 37/38] Simplify "want_partial_unit" handling Tom Tromey
2020-02-08 17:38 ` [PATCH 00/38] Start reorganization of DWARF code Simon Marchi
2020-02-08 20:45 ` Tom Tromey
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=20200123005710.7978-36-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).