From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2126) id 0E2473857C6F; Thu, 14 Apr 2022 18:27:01 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0E2473857C6F Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Tom Tromey To: gdb-cvs@sourceware.org Subject: [binutils-gdb] Ignore 0,0 entries in .debug_aranges X-Act-Checkin: binutils-gdb X-Git-Author: Tom Tromey X-Git-Refname: refs/heads/master X-Git-Oldrev: 8bbdbd6985d8d7615bab69f97f07e8bb78fb98f8 X-Git-Newrev: 1a7c41d5ece7d0d1aa77d8019ee46f03181854fa Message-Id: <20220414182701.0E2473857C6F@sourceware.org> Date: Thu, 14 Apr 2022 18:27:01 +0000 (GMT) X-BeenThere: gdb-cvs@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 14 Apr 2022 18:27:01 -0000 https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3D1a7c41d5ece7= d0d1aa77d8019ee46f03181854fa commit 1a7c41d5ece7d0d1aa77d8019ee46f03181854fa Author: Tom Tromey Date: Thu Apr 14 09:36:09 2022 -0600 Ignore 0,0 entries in .debug_aranges =20 When running the internal AdaCore test suite against the new DWARF indexer, I found one regression on RISC-V. The test in question uses --gc-sections, and winds up with an entry in the middle of a .debug_aranges that has both address and length of 0. In this scenario, gdb assumes the entries are terminated and then proceeds to reject the section because it reads a subsequent entry as if it were a header. =20 It seems to me that, because each header describes the size of each .debug_aranges CU, it's better to simply ignore 0,0 entries and simply read to the end. That is what this patch does. =20 I've patched an existing test to provide a regression test for this. Diff: --- gdb/dwarf2/read.c | 11 +++++++++-- gdb/testsuite/gdb.dwarf2/locexpr-data-member-location.exp | 3 +++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c index 698720276a9..6dcd446e5f4 100644 --- a/gdb/dwarf2/read.c +++ b/gdb/dwarf2/read.c @@ -2469,7 +2469,7 @@ read_addrmap_from_aranges (dwarf2_per_objfile *per_ob= jfile, bytes. */ addr +=3D (entry_end - addr) % (2 * address_size); =20 - for (;;) + while (addr < entry_end) { if (addr + 2 * address_size > entry_end) { @@ -2487,7 +2487,14 @@ read_addrmap_from_aranges (dwarf2_per_objfile *per_o= bjfile, dwarf5_byte_order); addr +=3D address_size; if (start =3D=3D 0 && length =3D=3D 0) - break; + { + /* This can happen on some targets with --gc-sections. + This pair of values is also used to mark the end of + the entries for a given CU, but we ignore it and + instead handle termination using the check at the top + of the loop. */ + continue; + } if (start =3D=3D 0 && !per_bfd->has_section_at_zero) { /* Symbol was eliminated due to a COMDAT group. */ diff --git a/gdb/testsuite/gdb.dwarf2/locexpr-data-member-location.exp b/gd= b/testsuite/gdb.dwarf2/locexpr-data-member-location.exp index 67e96fb1128..adb4e0a4c21 100644 --- a/gdb/testsuite/gdb.dwarf2/locexpr-data-member-location.exp +++ b/gdb/testsuite/gdb.dwarf2/locexpr-data-member-location.exp @@ -296,6 +296,9 @@ Dwarf::assemble ${asm_file} { } =20 aranges {} cu_label { + # This 0,0 entry tests that the .debug_aranges reader can + # handle an apparent terminator before the end of the ranges. + arange {} 0 0 arange {} $foo_start $foo_end arange {} $bar_start $bar_end }