public inbox for gdb-prs@sourceware.org
help / color / mirror / Atom feed
* [Bug symtab/28200] New: DW_AT_ranges handling in partial_die_info::read does not handle discontinuous ranges
@ 2021-08-06 11:03 vries at gcc dot gnu.org
  2021-08-06 11:04 ` [Bug symtab/28200] " vries at gcc dot gnu.org
                   ` (15 more replies)
  0 siblings, 16 replies; 17+ messages in thread
From: vries at gcc dot gnu.org @ 2021-08-06 11:03 UTC (permalink / raw)
  To: gdb-prs

https://sourceware.org/bugzilla/show_bug.cgi?id=28200

            Bug ID: 28200
           Summary: DW_AT_ranges handling in partial_die_info::read does
                    not handle discontinuous ranges
           Product: gdb
           Version: HEAD
            Status: NEW
          Severity: normal
          Priority: P2
         Component: symtab
          Assignee: unassigned at sourceware dot org
          Reporter: vries at gcc dot gnu.org
  Target Milestone: ---

Created attachment 13596
  --> https://sourceware.org/bugzilla/attachment.cgi?id=13596&action=edit
Test-case patch

[ Spinoff from PR28004. ]

Consider test-case dw2-ranges-psym/dw2-ranges-psym.exp.

Say we split up the range $foo_low_start $foo_low_end in two ranges:
...
diff --git a/gdb/testsuite/gdb.dwarf2/dw2-ranges-psym.exp
b/gdb/testsuite/gdb.dwarf2/dw2-ranges-
psym.exp
index 3ad2d1c567c..84c9d87adfd 100644
--- a/gdb/testsuite/gdb.dwarf2/dw2-ranges-psym.exp
+++ b/gdb/testsuite/gdb.dwarf2/dw2-ranges-psym.exp
@@ -109,11 +109,13 @@ Dwarf::assemble $asm_file {
     ranges {is_64 [is_64_target]} {
        func_ranges_label: sequence {
            range $foo_start $foo_end
-           range $foo_low_start $foo_low_end
+           range $foo_low_start "$foo_low_start + 1"
+           range "$foo_low_start + 1" $foo_low_end
        }
        cu_ranges_label: sequence {
            range $foo_start $foo_end
-           range $foo_low_start $foo_low_end
+           range $foo_low_start "$foo_low_start + 1"
+           range "$foo_low_start + 1" $foo_low_end
            range $bar_start $bar_end
            range $baz_start $baz_end
        }
...

When printing the partial symbols:
...
$ gdb -q -batch outputs/gdb.dwarf2/dw2-ranges-psym/dw2-ranges-psym -ex "maint
print psymbols"
...
we find for CU dw-ranges-psym.c the address map, a single range:
...
  Address map:
    0x4004b2 0x383f140
    0x4004e7 <ends here>
...

Now say we remove the range range "$foo_low_start + 1" $foo_low_end from the cu
ranges.  Consequently the CU address map changes:
...
  Address map:
    0x4004b2 0x2c65140
    0x4004ba <ends here>
    0x4004c5 0x2c65140
    0x4004e7 <ends here>
...
and there's a hole at [0x4004ba - 0x4004c5).

Now say we remove the DW_AT_ranges for the CU, we get back:
...
  Address map:
    0x4004b2 0x391df20
    0x4004e7 <ends here>
...
What happens here, is that gdb puts together the address map from the
functions, triggered by this code in process_psymtab_comp_unit_reader being
called with cu_bounds_kind == PC_BOUNDS_INVALID, which sets the set_addrmap
argument to 1:
...
          scan_partial_symbols (first_die, &lowpc, &highpc,
                                cu_bounds_kind <= PC_BOUNDS_INVALID, cu);
...

Now say we remove the same range from the ranges for the function someothername
(an alias for foo). We get the address map:
...
  Address map:
    0x4004b2 0x3b69140
    0x4004e7 <ends here>
...

This is incorrect, the hole is missing.

This is caused by this code in partial_die_info::read:
...
            if (dwarf2_ranges_read (ranges_offset, &lowpc, &highpc, cu,
                                    nullptr, tag))
              has_pc_info = 1;
...
which pretends that the function is located at addresses lowpc...highpc, which
is indeed not the case.

Using attached test-case patch, we modify the test-case a bit more to get:
...
(gdb) bt
warning: (Internal error: pc 0x4004c6 in read in psymtab, but not in symtab.)

warning: (Internal error: pc 0x4004c6 in read in psymtab, but not in symtab.)

warning: (Internal error: pc 0x4004c6 in read in psymtab, but not in symtab.)

warning: (Internal error: pc 0x4004c6 in read in psymtab, but not in symtab.)

#0  0x00000000004004bb in baz ()
warning: (Internal error: pc 0x4004c6 in read in psymtab, but not in symtab.)

warning: (Internal error: pc 0x4004c6 in read in psymtab, but not in symtab.)

#1  0x00000000004004c7 in foo_low (warning: (Internal error: pc 0x4004c6 in
read in psymtab, but not in symtab.)

)
#2  0x00000000004004e9 in someothername ()
#3  0x00000000004004b0 in main ()
(gdb) PASS: gdb.dwarf2/dw2-ranges-psym.exp: bt
...

The warning complains about the fact that a pc in the range that was removed
can be found in the psymtab (due to the bug described above) but cannot be
found in the corresponding symtab (because that one accurately handles
discontinuous ranges).

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 17+ messages in thread

end of thread, other threads:[~2021-09-14 12:56 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-06 11:03 [Bug symtab/28200] New: DW_AT_ranges handling in partial_die_info::read does not handle discontinuous ranges vries at gcc dot gnu.org
2021-08-06 11:04 ` [Bug symtab/28200] " vries at gcc dot gnu.org
2021-08-06 11:18 ` vries at gcc dot gnu.org
2021-08-06 11:57 ` vries at gcc dot gnu.org
2021-08-06 13:18 ` simark at simark dot ca
2021-08-06 14:23 ` vries at gcc dot gnu.org
2021-08-06 14:28 ` vries at gcc dot gnu.org
2021-08-06 15:44 ` simark at simark dot ca
2021-08-06 15:57 ` vries at gcc dot gnu.org
2021-08-06 16:46 ` simark at simark dot ca
2021-08-10 13:38 ` vries at gcc dot gnu.org
2021-08-10 15:06 ` vries at gcc dot gnu.org
2021-08-10 15:06 ` vries at gcc dot gnu.org
2021-08-24 14:29 ` brobecker at gnat dot com
2021-08-24 14:58 ` vries at gcc dot gnu.org
2021-09-14 12:41 ` cvs-commit at gcc dot gnu.org
2021-09-14 12:56 ` vries at gcc dot gnu.org

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).