From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id DF02739A0C31; Fri, 6 Aug 2021 14:23:45 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org DF02739A0C31 From: "vries at gcc dot gnu.org" To: gdb-prs@sourceware.org Subject: [Bug symtab/28200] DW_AT_ranges handling in partial_die_info::read does not handle discontinuous ranges Date: Fri, 06 Aug 2021 14:23:45 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gdb X-Bugzilla-Component: symtab X-Bugzilla-Version: HEAD X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: vries at gcc dot gnu.org X-Bugzilla-Status: NEW X-Bugzilla-Resolution: X-Bugzilla-Priority: P2 X-Bugzilla-Assigned-To: unassigned at sourceware dot org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://sourceware.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: gdb-prs@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-prs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 06 Aug 2021 14:23:46 -0000 https://sourceware.org/bugzilla/show_bug.cgi?id=3D28200 --- Comment #4 from Tom de Vries --- [ Refiling comment 0, a bit restructured for better readability, and the ability to refer to individual parts. Also a minor correction on cu_bounds_= kind in case IV. Also added the initial, unmodified case as starting point. ] I. Consider test-case dw2-ranges-psym/dw2-ranges-psym.exp, unmodified. When printing the partial symbols: ... $ gdb -q -batch outputs/gdb.dwarf2/dw2-ranges-psym/dw2-ranges-psym -ex "mai= nt print psymbols" ... we find for CU dw-ranges-psym.c the address map, a single range: ... Address map: 0x4004b2 0x383f140 0x4004e7 ... II. 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, we get the same, a single range: ... Address map: 0x4004b2 0x383f140 0x4004e7 ... III. Now say we remove the range range "$foo_low_start + 1" $foo_low_end from th= e cu ranges: ... diff --git a/gdb/testsuite/gdb.dwarf2/dw2-ranges-psym.exp b/gdb/testsuite/gdb.dwarf2/dw2-ranges- psym.exp index 84c9d87adfd..61014f288fe 100644 --- a/gdb/testsuite/gdb.dwarf2/dw2-ranges-psym.exp +++ b/gdb/testsuite/gdb.dwarf2/dw2-ranges-psym.exp @@ -115,7 +115,6 @@ Dwarf::assemble $asm_file { cu_ranges_label: sequence { range $foo_start $foo_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 } ... Consequently the CU address map changes: ... Address map: 0x4004b2 0x2c65140 0x4004ba 0x4004c5 0x2c65140 0x4004e7 ... and there's a hole at [0x4004ba - 0x4004c5). IV. Now say we remove the DW_AT_ranges for the CU: ... diff --git a/gdb/testsuite/gdb.dwarf2/dw2-ranges-psym.exp b/gdb/testsuite/gdb.dwarf2/dw2-ranges- psym.exp index 61014f288fe..4e3c848e279 100644 --- a/gdb/testsuite/gdb.dwarf2/dw2-ranges-psym.exp +++ b/gdb/testsuite/gdb.dwarf2/dw2-ranges-psym.exp @@ -75,7 +75,6 @@ Dwarf::assemble $asm_file { {language @DW_LANG_C} {name dw-ranges-psym.c} {low_pc 0 addr} - {ranges ${cu_ranges_label} DW_FORM_sec_offset} } { integer_label: DW_TAG_base_type { {DW_AT_byte_size $int_size DW_FORM_sdata} ... We get back: ... Address map: 0x4004b2 0x391df20 0x4004e7 ... 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 =3D=3D PC_BOUNDS_NOT_PRESENT (and not PC_BOUNDS_= INVALID as I said mistakingly in comment 0), which sets the set_addrmap argument to= 1: ... scan_partial_symbols (first_die, &lowpc, &highpc, cu_bounds_kind <=3D PC_BOUNDS_INVALID, cu); ... V. Now say we remove the same range from the ranges for the function someother= name (an alias for foo): ... diff --git a/gdb/testsuite/gdb.dwarf2/dw2-ranges-psym.exp b/gdb/testsuite/gdb.dwarf2/dw2-ranges- psym.exp index 4e3c848e279..7b628bceceb 100644 --- a/gdb/testsuite/gdb.dwarf2/dw2-ranges-psym.exp +++ b/gdb/testsuite/gdb.dwarf2/dw2-ranges-psym.exp @@ -109,7 +109,6 @@ Dwarf::assemble $asm_file { func_ranges_label: sequence { range $foo_start $foo_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 ... We get the address map: ... Address map: 0x4004b2 0x3b69140 0x4004e7 ... 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 =3D 1; ... which pretends that the function is located at addresses lowpc...highpc, wh= ich is indeed not the case. VI. 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). --=20 You are receiving this mail because: You are on the CC list for the bug.=