From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id yMXQN1+aK2dkzCcAWB0awg (envelope-from ) for ; Wed, 06 Nov 2024 11:33:35 -0500 Authentication-Results: simark.ca; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=fSU4/zF9; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id E1A871E5FC; Wed, 6 Nov 2024 11:33:35 -0500 (EST) X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-6.4 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham autolearn_force=no version=4.0.0 Received: from server2.sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 2FBBA1E5CD for ; Wed, 6 Nov 2024 11:33:35 -0500 (EST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id CD2533858CD1 for ; Wed, 6 Nov 2024 16:33:34 +0000 (GMT) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTP id 0327C3858401 for ; Wed, 6 Nov 2024 16:32:59 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 0327C3858401 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 0327C3858401 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1730910786; cv=none; b=yAwWAbXRWwLEvtNc03PoPJGD79K1g4gm5g87I2PW+clz5YLKuVpfkscCXiMekJddQx4Tj4cBcqCoZKFvZCYePdq8vNOEF75FrIE69B9xXYgjwtJCEaMXpBbed8qhusQtdoco10zEU+FQZCYVAd8yCM55pSrzyDWkhvI2kdcrnJo= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1730910786; c=relaxed/simple; bh=J0pD2BryKHu2Kit6Pv7kmjp1Fji1vX0oMA/T9MDam/Q=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=sdGwBInOzDzeg46M1Kz35O0vddAJToQkdssmofcJj2AIrOCXfxCGKk5xbZVwIMeCqT+YeywEtPmHW1+HyEPsBaKYYradQhX/RBlRC24canhN4+qgqh+DVrJ0AZEDrY7FCvdq/CExhaT0C0U+fsEc/TcSIpsr5T7eQH1bK1VwdMU= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1730910779; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=orFZZQ0eDgo6IM7tA2JFr/Ilss5EwqWgER99SuvPRQs=; b=fSU4/zF9r7dkksuiRvfwUcLQZMZ4ZgmofsumXvJo2EZd/F9tnvlVijjClqgdcq6740b7Yv klV5+9ByeAbEiRwKxntJ2GndNgv6EqGv04DA5aXXQ8NfrxZaVxlR0ZbD34mKwTz4QmFojm qBC+tUiXHG2mz8Q6zrDcG8rE2FNWMLc= Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-15-1BhzWDsFN5axrE2zXaXkyA-1; Wed, 06 Nov 2024 11:32:58 -0500 X-MC-Unique: 1BhzWDsFN5axrE2zXaXkyA-1 X-Mimecast-MFC-AGG-ID: 1BhzWDsFN5axrE2zXaXkyA Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id BAFCE1955F42 for ; Wed, 6 Nov 2024 16:32:57 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.45.242.4]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id C129019541A5; Wed, 6 Nov 2024 16:32:56 +0000 (UTC) From: =?UTF-8?q?Alexandra=20H=C3=A1jkov=C3=A1?= To: gdb-patches@sourceware.org Cc: ahajkova@redhat.com Subject: [PATCH] Add dw2-aranges.exp Date: Wed, 6 Nov 2024 17:32:55 +0100 Message-ID: <20241106163255.2619114-1-ahajkova@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: nq0CxU7GoxjCNmQQGfyH4-z8j7lSU_zvvt1cRsJjiNU_1730910778 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII"; x-default=true X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces~public-inbox=simark.ca@sourceware.org This test tests GDB is able to load a file with the .debug_aranges section Address size set to 0. The test was originally written by Jan Kratochvil to test commit 927aa2e778dce440f4de5de8fc37ead1683a804e Author: Jan Kratochvil Date: Fri Dec 8 22:44:12 2017 +0000 DWARF-5: .debug_names index consumer The test was passing from the beginning. This test has been living in the Fedora tree for a long time, it seems to be a reasonable some bad debug information. If dwarf2/aranges.c is modified to turn off the address_size check, GDB will crash with SIGPE when loading the executable with the address size set to zero. I modified the DWARF assembler to make it possible to set the Addres size to zero in a .debug_aranges section and used a DWARF assembler to produce the assembly file. Co-Authored-By: Jan Kratochvil --- gdb/testsuite/gdb.dwarf2/dw2-aranges.c | 24 +++++++++++++ gdb/testsuite/gdb.dwarf2/dw2-aranges.exp | 44 ++++++++++++++++++++++++ gdb/testsuite/lib/dwarf.exp | 15 ++++++-- 3 files changed, 81 insertions(+), 2 deletions(-) create mode 100644 gdb/testsuite/gdb.dwarf2/dw2-aranges.c create mode 100644 gdb/testsuite/gdb.dwarf2/dw2-aranges.exp diff --git a/gdb/testsuite/gdb.dwarf2/dw2-aranges.c b/gdb/testsuite/gdb.dwarf2/dw2-aranges.c new file mode 100644 index 00000000000..28025188495 --- /dev/null +++ b/gdb/testsuite/gdb.dwarf2/dw2-aranges.c @@ -0,0 +1,24 @@ +/* This testcase is part of GDB, the GNU debugger. + + Copyright 2024 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +/* Dummy main function. */ + +int +main (void) +{ + return 0; +} diff --git a/gdb/testsuite/gdb.dwarf2/dw2-aranges.exp b/gdb/testsuite/gdb.dwarf2/dw2-aranges.exp new file mode 100644 index 00000000000..59e7e27ac96 --- /dev/null +++ b/gdb/testsuite/gdb.dwarf2/dw2-aranges.exp @@ -0,0 +1,44 @@ +# Copyright 2004-2024 Free Software Foundation, Inc. + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +# Test .debug_aranges containing zero address_size. + +# This test can only be run on targets which support DWARF-2 and use gas. +# For now pick a sampling of likely targets. +load_lib dwarf.exp + +if {![dwarf2_support]} { + verbose "Skipping $gdb_test_file_name." + return 0 +} + +standard_testfile .c -2.S +set asm_file [standard_output_file $srcfile2] + +Dwarf::assemble $asm_file { + cu { label cu_start } { + compile_unit {{language @DW_LANG_C}} { + } + } + aranges { addr_zero true } cu_start { + } +} + +if { [prepare_for_testing "failed to prepare" $binfile [list $asm_file $srcfile ]] } { + return -1 +} + +# Failed gdb_load would abort the testcase execution earlier. +pass "file loaded" diff --git a/gdb/testsuite/lib/dwarf.exp b/gdb/testsuite/lib/dwarf.exp index 6a5afec3fc8..1002c75dd09 100644 --- a/gdb/testsuite/lib/dwarf.exp +++ b/gdb/testsuite/lib/dwarf.exp @@ -2759,8 +2759,11 @@ namespace eval Dwarf { set addr_op .4byte } - _op $addr_op $arange_start "Address range start$comment" - _op $addr_op $arange_length "Address range length$comment" + # Do not emit address ranges when the Address size is set to 0. + if { $_addr_size > 0 } { + _op $addr_op $arange_start "Address range start$comment" + _op $addr_op $arange_length "Address range length$comment" + } } # Emit a DWARF .debug_aranges unit. @@ -2797,6 +2800,7 @@ namespace eval Dwarf { { cu_is_64 0 } { section_version 2 } { seg_size 0 } + { addr_zero false } } set _seg_size $seg_size @@ -2806,6 +2810,10 @@ namespace eval Dwarf { set _addr_size 4 } + if { $addr_zero } { + set _addr_size 0 + } + # Switch to .debug_aranges section. _section .debug_aranges @@ -2853,6 +2861,9 @@ namespace eval Dwarf { # Padding. set tuple_size [expr 2 * $_addr_size + $_seg_size] + if {$tuple_size == 0} { + set tuple_size 1 + } while { 1 } { if { [expr $offset % $tuple_size] == 0 } { break -- 2.46.2