Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Simon Marchi via Gdb-patches <gdb-patches@sourceware.org>
To: gdb-patches@sourceware.org
Cc: Simon Marchi <simon.marchi@efficios.com>
Subject: [PATCH 07/13] gdb/dwarf: read DW_AT_ranges value as unsigned in partial_die_info::read
Date: Wed, 20 Jan 2021 00:39:19 -0500	[thread overview]
Message-ID: <20210120053925.142862-8-simon.marchi@polymtl.ca> (raw)
In-Reply-To: <20210120053925.142862-1-simon.marchi@polymtl.ca>

From: Simon Marchi <simon.marchi@efficios.com>

While writing a test for this series, I made a function
(DW_AT_subprogram) with a DW_AT_ranges attribute using the
DW_FORM_rnglistx form:

0x00000012:   DW_TAG_subprogram
                DW_AT_name [DW_FORM_string]     ("foo")
                DW_AT_ranges [DW_FORM_rnglistx] (indexed (0x0) rangelist = 0x00000036
                   [0x0000000000004000, 0x0000000000005000))

And strangely I couldn't print it:

    (gdb) p foo
    No symbol "foo" in current context.

This is because of the `attr.constant_value (0)` in the DW_AT_ranges
handling of partial_die_info::read.  Since DW_FORM_rnglistx is not
recognized as a constant value by attribute::constant_value, the default
value (0) is returned.  Down the line, this causes
dwarf2_rnglists_process to try read a range list at offset 0 in the
.debug_rnglists section, which is obviously wrong.  In the end, no
symbol is created for foo because we didn't find an address range.

Use attr->as_unsigned instead.  This is what is done for the equivalent
code in dwarf2_get_pc_bounds.  With this, GDB processes the subprogram
DIE and we are able to print the function symbol:

    (gdb) p foo
    $1 = {void (void)} 0x4000

Note that I didn't see an actual compiler use DW_FORM_rnglistx for a
subprogram's range.  However, in the binary attached to PR 26813, there
are some lexical blocks with it:

0x0000d34a:       DW_TAG_lexical_block
                    DW_AT_ranges [DW_FORM_rnglistx]     (indexed (0x2) rangelist = 0x000000d4
                       [0x0000000000005db1, 0x0000000000005e36)
                       [0x0000000000005e48, 0x0000000000005f3c)
                       [0x0000000000006045, 0x0000000000006053))

Their ranges are read incorrectly just like the ranges of the
subprograms.  With this patch applied, they are read correctly.

gdb/ChangeLog:

	* dwarf2/read.c (partial_die_info::read): Use
	attribute::as_unsigned instead of attribute::constant_value
	for DW_AT_ranges.

Change-Id: I285381a15588574058d934bbc88f06029e8a3bd1
---
 gdb/dwarf2/read.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index 9701d422a338..5277e2a09e3f 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -19805,7 +19805,7 @@ partial_die_info::read (const struct die_reader_specs *reader,
 	    /* It would be nice to reuse dwarf2_get_pc_bounds here,
 	       but that requires a full DIE, so instead we just
 	       reimplement it.  */
-	    unsigned int ranges_offset = (attr.constant_value (0)
+	    unsigned int ranges_offset = (attr.as_unsigned ()
 					  + (need_ranges_base
 					     ? cu->ranges_base
 					     : 0));
-- 
2.30.0


  parent reply	other threads:[~2021-01-20  5:39 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-20  5:39 [PATCH 00/13] DWARF 5 rnglists & loclists fixes (PR 26813) Simon Marchi via Gdb-patches
2021-01-20  5:39 ` [PATCH 01/13] gdb/dwarf: change read_loclist_index complaints into errors Simon Marchi via Gdb-patches
2021-01-28 15:17   ` Zoran Zaric via Gdb-patches
2021-01-28 15:42     ` Simon Marchi via Gdb-patches
2021-02-25 19:20       ` Tom Tromey
2021-01-20  5:39 ` [PATCH 02/13] gdb/dwarf: fix bound check in read_rnglist_index Simon Marchi via Gdb-patches
2021-01-28 15:22   ` Zoran Zaric via Gdb-patches
2021-01-20  5:39 ` [PATCH 03/13] gdb/dwarf: add missing bound check to read_loclist_index Simon Marchi via Gdb-patches
2021-01-20  5:39 ` [PATCH 04/13] gdb/dwarf: remove unnecessary check in read_{rng, loc}list_index Simon Marchi via Gdb-patches
2021-01-20  5:39 ` [PATCH 05/13] gdb/dwarf: few fixes for handling DW_FORM_{rng, loc}listx Simon Marchi via Gdb-patches
2021-01-28 15:30   ` [PATCH 05/13] gdb/dwarf: few fixes for handling DW_FORM_{rng,loc}listx Zoran Zaric via Gdb-patches
2021-01-20  5:39 ` [PATCH 06/13] gdb/dwarf: read correct rnglist/loclist header in read_{rng, loc}list_index Simon Marchi via Gdb-patches
2021-01-28 15:39   ` [PATCH 06/13] gdb/dwarf: read correct rnglist/loclist header in read_{rng,loc}list_index Zoran Zaric via Gdb-patches
2021-01-28 15:49     ` Simon Marchi via Gdb-patches
2021-01-28 15:54       ` Zoran Zaric via Gdb-patches
2021-01-20  5:39 ` Simon Marchi via Gdb-patches [this message]
2021-01-28 15:41   ` [PATCH 07/13] gdb/dwarf: read DW_AT_ranges value as unsigned in partial_die_info::read Zoran Zaric via Gdb-patches
2021-01-28 15:51     ` Simon Marchi via Gdb-patches
2021-01-20  5:39 ` [PATCH 08/13] gdb/testsuite: add .debug_rnglists tests Simon Marchi via Gdb-patches
2021-01-28 16:24   ` Zoran Zaric via Gdb-patches
2021-01-20  5:39 ` [PATCH 09/13] gdb/testsuite: DWARF assembler: add context parameters to _location Simon Marchi via Gdb-patches
2021-01-28 16:30   ` Zoran Zaric via Gdb-patches
2021-01-20  5:39 ` [PATCH 10/13] gdb/testsuite: add .debug_loclists tests Simon Marchi via Gdb-patches
2021-01-28 16:52   ` Zoran Zaric via Gdb-patches
2021-01-28 17:47     ` Simon Marchi via Gdb-patches
2021-01-29 10:13       ` Zoran Zaric via Gdb-patches
2021-01-29 15:57         ` Simon Marchi via Gdb-patches
2021-01-29 16:58           ` Zoran Zaric via Gdb-patches
2021-01-29 17:37             ` Simon Marchi via Gdb-patches
2021-01-20  5:39 ` [PATCH 11/13] gdb/dwarf: split dwarf2_cu::ranges_base in two Simon Marchi via Gdb-patches
2021-01-20  5:39 ` [PATCH 12/13] gdb/dwarf: make read_{loc, rng}list_index return sect_offset Simon Marchi via Gdb-patches
2021-02-25 19:26   ` Tom Tromey
2021-01-20  5:39 ` [PATCH 13/13] gdb/testsuite: add test for .debug_{rng, loc}lists section without offset array Simon Marchi via Gdb-patches
2021-02-02 15:43 ` [PATCH 00/13] DWARF 5 rnglists & loclists fixes (PR 26813) Simon Marchi via Gdb-patches

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=20210120053925.142862-8-simon.marchi@polymtl.ca \
    --to=gdb-patches@sourceware.org \
    --cc=simon.marchi@efficios.com \
    --cc=simon.marchi@polymtl.ca \
    /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