From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id iNXyJQiaK2dkzCcAWB0awg (envelope-from ) for ; Wed, 06 Nov 2024 11:32:08 -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=bb5GwrDI; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 8D35C1E5FC; Wed, 6 Nov 2024 11:32:08 -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 40A781E5CD for ; Wed, 6 Nov 2024 11:32:07 -0500 (EST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id DE9C33858C50 for ; Wed, 6 Nov 2024 16:32:06 +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 DF8943858D20 for ; Wed, 6 Nov 2024 16:31:41 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org DF8943858D20 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 DF8943858D20 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=1730910707; cv=none; b=dIHX+Hx7ZsrGqDLlKspng+Sz6cZwG3h1IWUSlwq+l49XRzPWw9s+HAv7jhTPtlcqcWJ05YUAECbavW9Gdk3ngv+Cty8Vhd/Hsp1SBZmGniuUFLGY8FpPO9RglZXRr+mO6c+pf/BewUPXxZWNTHuAyguNdwdqfR8DgO9JMSiCmX8= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1730910707; c=relaxed/simple; bh=24e/kkjxEQ0HtoLQCErmgAqVHOCOi+xVBt7XaXXZWto=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=PzSxBJVE+c4+o6aeHGBOT4gm2rwtmAZHakyUmZjCnqvc/563DVNfw4H1leGVcrj6EZN2Prk9C/ttI8aBaDlpOc1bgCOs17X5OJ4RgdkCE5Gs41aS5R1YKjNpo4i/G0YofWv+dh1Wmj8u6EaDCHgWjimWPkDI5yjtHH5lGRTI8Q8= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1730910701; 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=gueDJGcgzpgn2thTfOTtOk4BSenZw2aiU696WMwFQHE=; b=bb5GwrDIcnGlWk4r/Po4NXdjjyUl+VQgfKycfyIbuco3R8/psR/hdcg95MhmmzUfhiljRJ e6L3tmrPleHKJIhBYhmWJQKplo8BOhmCLpEPotbtPS/Z5wRUuLFR1PevlfUHNbAlhRMBuy E+kTJ6OPN6W4guXT80KwQSZvF3jXSwk= Received: from mx-prod-mc-04.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-375-Oqai7wmLM7CVMCRu5-R2nQ-1; Wed, 06 Nov 2024 11:31:40 -0500 X-MC-Unique: Oqai7wmLM7CVMCRu5-R2nQ-1 X-Mimecast-MFC-AGG-ID: Oqai7wmLM7CVMCRu5-R2nQ Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (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-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 996891955F4A for ; Wed, 6 Nov 2024 16:31:39 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.45.242.4]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 9639B300018D; Wed, 6 Nov 2024 16:31:38 +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:31:36 +0100 Message-ID: <20241106163136.2618597-1-ahajkova@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: qmwl71VEV6qMZ4nm8pYHST7VtyQxlfiNliVriKdIyOc_1730910699 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 | 45 ++++++++++++++++++++++++ gdb/testsuite/lib/dwarf.exp | 15 ++++++-- 3 files changed, 82 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..b9174cad14f --- /dev/null +++ b/gdb/testsuite/gdb.dwarf2/dw2-aranges.exp @@ -0,0 +1,45 @@ +# 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 { + arange {} 0 0 + } +} + +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..e5823c7b646 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 i 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 0 } } set _seg_size $seg_size @@ -2806,6 +2810,10 @@ namespace eval Dwarf { set _addr_size 4 } + if { $addr_zero == true } { + 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