From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-io1-xd29.google.com (mail-io1-xd29.google.com [IPv6:2607:f8b0:4864:20::d29]) by sourceware.org (Postfix) with ESMTPS id BB7E83857342 for ; Thu, 14 Apr 2022 15:39:19 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org BB7E83857342 Received: by mail-io1-xd29.google.com with SMTP id p21so5803132ioj.4 for ; Thu, 14 Apr 2022 08:39:19 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=/OXu41hUS1dclgaCGD0Hkwyz+/4ScJeHeYQIQpLz2Xc=; b=KtZZgIuSbnWQjp96Co1whYa+6yyKq32WpNUWw+y0EiQrFp8Gk97V4PuS9RxHY2szwE K1etmWnN1JJgSro+aQLvU1NBvQz5o3cmZK1yqV2IeIEwouBmRc+X3D9hl+Tphi9IhXK3 XT/BV3KiYx18pHLsnULzUyxwqKwyQ/2hKsQeSl6OMJAcRMp1auiDOf5Ezi2CVkMGJZpG IV8kaxJeWHCJRusUR3FYR0IspYnV1zpg03zvGG8f7WiQjPSwNwa7T9CGpagWJjRZIwhO yAXbNI2XlkPj/MtvLNEvEVx1esdeJoUOrvYZurgzN+OgeZabDqvSFWUgLU0OpYSAae5k 6Z9g== X-Gm-Message-State: AOAM532O89F+bv4dCWd73k+eQzbzFyMZtxI5Sztc9Kdi00qC/XmscbJ2 sA+rcmvA1BSSCnNC/1ryQsrDw9RV/I3S1w== X-Google-Smtp-Source: ABdhPJyKtnyBifEF6z8Pi1f4IAYFWJXmfE/Uk2rq+cGnBevRwlJPi+qQ+oSM8gkuPJ1lFrt8p52BsA== X-Received: by 2002:a5d:8855:0:b0:651:fe8:47a8 with SMTP id t21-20020a5d8855000000b006510fe847a8mr211313ios.84.1649950759122; Thu, 14 Apr 2022 08:39:19 -0700 (PDT) Received: from murgatroyd.Home (71-211-154-204.hlrn.qwest.net. [71.211.154.204]) by smtp.gmail.com with ESMTPSA id g14-20020a92dd8e000000b002ca7bbf5179sm1171454iln.53.2022.04.14.08.39.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Apr 2022 08:39:18 -0700 (PDT) From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH] Ignore 0,0 entries in .debug_aranges Date: Thu, 14 Apr 2022 09:39:16 -0600 Message-Id: <20220414153916.3468409-1-tromey@adacore.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-11.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 14 Apr 2022 15:39:21 -0000 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. 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. I've patched an existing test to provide a regression test for this. --- gdb/dwarf2/read.c | 11 +++++++++-- .../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_objfile, bytes. */ addr += (entry_end - addr) % (2 * address_size); - for (;;) + while (addr < entry_end) { if (addr + 2 * address_size > entry_end) { @@ -2487,7 +2487,14 @@ read_addrmap_from_aranges (dwarf2_per_objfile *per_objfile, dwarf5_byte_order); addr += address_size; if (start == 0 && length == 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 == 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/gdb/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} { } 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 } -- 2.34.1