From patchwork Sun Feb 19 21:28:11 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Kratochvil X-Patchwork-Id: 19300 Received: (qmail 114716 invoked by alias); 19 Feb 2017 21:28:17 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 114636 invoked by uid 89); 19 Feb 2017 21:28:16 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RP_MATCHES_RCVD, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy= X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sun, 19 Feb 2017 21:28:14 +0000 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 5A72F4E4D4; Sun, 19 Feb 2017 21:28:14 +0000 (UTC) Received: from host1.jankratochvil.net (ovpn-116-221.ams2.redhat.com [10.36.116.221]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v1JLSDJQ002822; Sun, 19 Feb 2017 16:28:13 -0500 Subject: [PATCH v2 2/8] Code cleanup: Split dwarf2_ranges_read to a callback From: Jan Kratochvil To: gdb-patches@sourceware.org Cc: Victor Leschuk Date: Sun, 19 Feb 2017 22:28:11 +0100 Message-ID: <148753969170.4016.895373138681946141.stgit@host1.jankratochvil.net> In-Reply-To: <148753968011.4016.6818202131640662529.stgit@host1.jankratochvil.net> References: <148753968011.4016.6818202131640662529.stgit@host1.jankratochvil.net> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-IsSubscribed: yes 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 * 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 9e07d20..e0ede18 100644 --- a/gdb/dwarf2read.c +++ b/gdb/dwarf2read.c @@ -11873,14 +11873,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 callback) { struct objfile *objfile = cu->objfile; struct gdbarch *gdbarch = get_objfile_arch (objfile); @@ -11893,9 +11892,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; @@ -11911,8 +11907,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) @@ -11977,6 +11971,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; @@ -12007,7 +12028,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 @@ -12259,79 +12282,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); + }); } }