From: Jan Kratochvil <jan.kratochvil@redhat.com>
To: gdb-patches@sourceware.org
Cc: Victor Leschuk <vleschuk@accesssoftek.com>
Subject: [PATCH 3/8] Code cleanup: Split dwarf2_ranges_read to a callback
Date: Sun, 12 Feb 2017 20:23:00 -0000 [thread overview]
Message-ID: <148693098804.9024.9905586065345063380.stgit@host1.jankratochvil.net> (raw)
In-Reply-To: <148693097396.9024.2288256732840761882.stgit@host1.jankratochvil.net>
Hi,
DWARF-5 has .debug_rnglists which is somehow similar to .debug_ranges.
This patch converts dwarf2_ranges_read to dwarf2_ranges_process which can work
with both DWARF kinds of range lists through a callback.
It also simplifies dwarf2_record_block_ranges which can benefit from it.
Jan
gdb/ChangeLog
2017-02-11 Jan Kratochvil <jan.kratochvil@redhat.com>
* dwarf2read.c (dwarf2_ranges_process): New function from
dwarf2_ranges_read.
(dwarf2_ranges_read, dwarf2_record_block_ranges): Use
dwarf2_ranges_process.
---
gdb/dwarf2read.c | 127 ++++++++++++++++++------------------------------------
1 file changed, 42 insertions(+), 85 deletions(-)
diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c
index 7c74718..1137541 100644
--- a/gdb/dwarf2read.c
+++ b/gdb/dwarf2read.c
@@ -11874,14 +11874,13 @@ read_call_site_scope (struct die_info *die, struct dwarf2_cu *cu)
}
}
-/* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET.
- Return 1 if the attributes are present and valid, otherwise, return 0.
- If RANGES_PST is not NULL we should setup `objfile->psymtabs_addrmap'. */
+/* Call CALLBACK from DW_AT_ranges attribute value OFFSET.
+ Return 1 if the attributes are present and valid, otherwise, return 0. */
static int
-dwarf2_ranges_read (unsigned offset, CORE_ADDR *low_return,
- CORE_ADDR *high_return, struct dwarf2_cu *cu,
- struct partial_symtab *ranges_pst)
+dwarf2_ranges_process (unsigned offset, struct dwarf2_cu *cu,
+ std::function<void (CORE_ADDR range_beginning,
+ CORE_ADDR range_end)> callback)
{
struct objfile *objfile = cu->objfile;
struct gdbarch *gdbarch = get_objfile_arch (objfile);
@@ -11894,9 +11893,6 @@ dwarf2_ranges_read (unsigned offset, CORE_ADDR *low_return,
int found_base;
unsigned int dummy;
const gdb_byte *buffer;
- int low_set;
- CORE_ADDR low = 0;
- CORE_ADDR high = 0;
CORE_ADDR baseaddr;
found_base = cu->base_known;
@@ -11912,8 +11908,6 @@ dwarf2_ranges_read (unsigned offset, CORE_ADDR *low_return,
}
buffer = dwarf2_per_objfile->ranges.buffer + offset;
- low_set = 0;
-
baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
while (1)
@@ -11978,6 +11972,33 @@ dwarf2_ranges_read (unsigned offset, CORE_ADDR *low_return,
continue;
}
+ callback (range_beginning, range_end);
+ }
+
+ return 1;
+}
+
+/* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET.
+ Return 1 if the attributes are present and valid, otherwise, return 0.
+ If RANGES_PST is not NULL we should setup `objfile->psymtabs_addrmap'. */
+
+static int
+dwarf2_ranges_read (unsigned offset, CORE_ADDR *low_return,
+ CORE_ADDR *high_return, struct dwarf2_cu *cu,
+ struct partial_symtab *ranges_pst)
+{
+ struct objfile *objfile = cu->objfile;
+ struct gdbarch *gdbarch = get_objfile_arch (objfile);
+ const CORE_ADDR baseaddr = ANOFFSET (objfile->section_offsets,
+ SECT_OFF_TEXT (objfile));
+ int low_set = 0;
+ CORE_ADDR low = 0;
+ CORE_ADDR high = 0;
+ int retval;
+
+ retval = dwarf2_ranges_process (offset, cu,
+ [&] (CORE_ADDR range_beginning, CORE_ADDR range_end)
+ {
if (ranges_pst != NULL)
{
CORE_ADDR lowpc;
@@ -12008,7 +12029,9 @@ dwarf2_ranges_read (unsigned offset, CORE_ADDR *low_return,
if (range_end > high)
high = range_end;
}
- }
+ });
+ if (!retval)
+ return 0;
if (! low_set)
/* If the first entry is an end-of-list marker, the range
@@ -12260,79 +12283,13 @@ dwarf2_record_block_ranges (struct die_info *die, struct block *block,
CORE_ADDR base = cu->base_address;
int base_known = cu->base_known;
- dwarf2_read_section (objfile, &dwarf2_per_objfile->ranges);
- if (offset >= dwarf2_per_objfile->ranges.size)
- {
- complaint (&symfile_complaints,
- _("Offset %lu out of bounds for DW_AT_ranges attribute"),
- offset);
- return;
- }
- buffer = dwarf2_per_objfile->ranges.buffer + offset;
-
- for (;;)
- {
- unsigned int bytes_read;
- CORE_ADDR start, end;
-
- start = read_address (obfd, buffer, cu, &bytes_read);
- buffer += bytes_read;
- end = read_address (obfd, buffer, cu, &bytes_read);
- buffer += bytes_read;
-
- /* Did we find the end of the range list? */
- if (start == 0 && end == 0)
- break;
-
- /* Did we find a base address selection entry? */
- else if ((start & base_select_mask) == base_select_mask)
- {
- base = end;
- base_known = 1;
- }
-
- /* We found an ordinary address range. */
- else
- {
- if (!base_known)
- {
- complaint (&symfile_complaints,
- _("Invalid .debug_ranges data "
- "(no base address)"));
- return;
- }
-
- if (start > end)
- {
- /* Inverted range entries are invalid. */
- complaint (&symfile_complaints,
- _("Invalid .debug_ranges data "
- "(inverted range)"));
- return;
- }
-
- /* Empty range entries have no effect. */
- if (start == end)
- continue;
-
- start += base + baseaddr;
- end += base + baseaddr;
-
- /* A not-uncommon case of bad debug info.
- Don't pollute the addrmap with bad data. */
- if (start == 0 && !dwarf2_per_objfile->has_section_at_zero)
- {
- complaint (&symfile_complaints,
- _(".debug_ranges entry has start address of zero"
- " [in module %s]"), objfile_name (objfile));
- continue;
- }
-
- start = gdbarch_adjust_dwarf2_addr (gdbarch, start);
- end = gdbarch_adjust_dwarf2_addr (gdbarch, end);
- record_block_range (block, start, end - 1);
- }
- }
+ dwarf2_ranges_process (offset, cu,
+ [&] (CORE_ADDR start, CORE_ADDR end)
+ {
+ start = gdbarch_adjust_dwarf2_addr (gdbarch, start);
+ end = gdbarch_adjust_dwarf2_addr (gdbarch, end);
+ record_block_range (block, start, end - 1);
+ });
}
}
next prev parent reply other threads:[~2017-02-12 20:23 UTC|newest]
Thread overview: 32+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-02-12 20:23 [PATCH 1/8] Rename read_unsigned_leb128 to gdb_read_unsigned_leb128 Jan Kratochvil
2017-02-12 20:23 ` Jan Kratochvil [this message]
2017-02-17 1:19 ` [PATCH 3/8] Code cleanup: Split dwarf2_ranges_read to a callback Pedro Alves
2017-02-19 21:26 ` Jan Kratochvil
2017-02-20 11:11 ` Pedro Alves
2017-02-12 20:23 ` [PATCH 2/8] Code cleanup: Split create_debug_types_hash_table Jan Kratochvil
2017-02-16 19:33 ` Pedro Alves
2017-02-12 20:23 ` [PATCH 8/8] DWARF-5: DW_FORM_data16 Jan Kratochvil
2017-02-17 12:09 ` Pedro Alves
2017-02-19 21:26 ` Jan Kratochvil
2017-02-20 11:44 ` Pedro Alves
2017-02-17 12:24 ` Pedro Alves
2017-02-12 20:23 ` [PATCH 5/8] DWARF-5 basic functionality Jan Kratochvil
2017-02-17 11:41 ` Pedro Alves
2017-02-19 21:26 ` Jan Kratochvil
2017-02-20 11:41 ` Pedro Alves
2017-02-20 19:52 ` Jan Kratochvil
2017-02-20 20:07 ` [commit] " Jan Kratochvil
2017-02-12 20:23 ` [PATCH 7/8] DWARF-5: Macros Jan Kratochvil
2017-02-17 11:59 ` Pedro Alves
2017-02-12 20:23 ` [PATCH 4/8] Code cleanup: Refactor abbrev_table_read_table cycle Jan Kratochvil
2017-02-17 1:21 ` Pedro Alves
2017-02-12 20:23 ` [PATCH 6/8] DWARF-5: call sites Jan Kratochvil
2017-02-12 20:41 ` Eli Zaretskii
2017-02-17 11:57 ` Pedro Alves
2017-02-19 21:26 ` Jan Kratochvil
2017-02-16 15:23 ` [PATCH 1/8] Rename read_unsigned_leb128 to gdb_read_unsigned_leb128 Pedro Alves
2017-02-16 19:40 ` Jan Kratochvil
2017-02-16 20:01 ` Pedro Alves
2017-02-16 22:54 ` Pedro Alves
2017-02-17 1:28 ` Pedro Alves
2017-02-19 21:25 ` Jan Kratochvil
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=148693098804.9024.9905586065345063380.stgit@host1.jankratochvil.net \
--to=jan.kratochvil@redhat.com \
--cc=gdb-patches@sourceware.org \
--cc=vleschuk@accesssoftek.com \
/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).