From patchwork Fri Jan 20 05:08:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Marchi X-Patchwork-Id: 63437 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id D65B638582A4 for ; Fri, 20 Jan 2023 05:08:53 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D65B638582A4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1674191333; bh=cWW+ESUCqvWO0WAtFONhRRr2UHhUFM6xOCq701oP23Q=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=fALy38fT94BZld+1ds+C6yvjVbzNl3s7h953c7nzQv45Lexg7BkLYa0Qti1JvPLqj e+4rSQJPsPyFyrIysQ1YRj8IDnDdJZJZhwFLUWT/S/WQNfFxbyEooC0x40BnGgAgNq B0y/hdz3btnosUoSlQQWTZojyWGtCf4r990e+3oY= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from barracuda.ebox.ca (barracuda.ebox.ca [96.127.255.19]) by sourceware.org (Postfix) with ESMTPS id 951183858C53 for ; Fri, 20 Jan 2023 05:08:27 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 951183858C53 X-ASG-Debug-ID: 1674191305-0c856e762b6bf760001-fS2M51 Received: from smtp.ebox.ca (smtp.ebox.ca [96.127.255.82]) by barracuda.ebox.ca with ESMTP id IHpJGqauVBHi1vUN (version=TLSv1 cipher=AES128-SHA bits=128 verify=NO); Fri, 20 Jan 2023 00:08:25 -0500 (EST) X-Barracuda-Envelope-From: simon.marchi@efficios.com X-Barracuda-RBL-Trusted-Forwarder: 96.127.255.82 Received: from epycamd.internal.efficios.com (192-222-180-24.qc.cable.ebox.net [192.222.180.24]) by smtp.ebox.ca (Postfix) with ESMTP id 236B9441B21; Fri, 20 Jan 2023 00:08:25 -0500 (EST) X-Barracuda-RBL-IP: 192.222.180.24 X-Barracuda-Effective-Source-IP: 192-222-180-24.qc.cable.ebox.net[192.222.180.24] X-Barracuda-Apparent-Source-IP: 192.222.180.24 To: gdb-patches@sourceware.org Cc: Simon Marchi Subject: [PATCH 1/2] gdb/testsuite: add test for negative subrange bounds with unsigned form Date: Fri, 20 Jan 2023 00:08:23 -0500 X-ASG-Orig-Subj: [PATCH 1/2] gdb/testsuite: add test for negative subrange bounds with unsigned form Message-Id: <20230120050824.306976-1-simon.marchi@efficios.com> X-Mailer: git-send-email 2.39.1 MIME-Version: 1.0 X-Barracuda-Connect: smtp.ebox.ca[96.127.255.82] X-Barracuda-Start-Time: 1674191305 X-Barracuda-Encrypted: AES128-SHA X-Barracuda-URL: https://96.127.255.19:443/cgi-mod/mark.cgi X-Barracuda-BRTS-Status: 1 X-Virus-Scanned: by bsmtpd at ebox.ca X-Barracuda-Scan-Msg-Size: 3490 X-Barracuda-Spam-Score: 0.00 X-Barracuda-Spam-Status: No, SCORE=0.00 using global scores of TAG_LEVEL=1000.0 QUARANTINE_LEVEL=1000.0 KILL_LEVEL=5.0 tests= X-Barracuda-Spam-Report: Code version 3.2, rules version 3.2.3.103676 Rule breakdown below pts rule name description ---- ---------------------- -------------------------------------------------- X-Spam-Status: No, score=-3498.2 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_NONE, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_SOFTFAIL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) 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-Patchwork-Original-From: Simon Marchi via Gdb-patches From: Simon Marchi Reply-To: Simon Marchi Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" I am looking at this code [1]: /* Normally, the DWARF producers are expected to use a signed constant form (Eg. DW_FORM_sdata) to express negative bounds. But this is unfortunately not always the case, as witnessed with GCC, for instance, where the ambiguous DW_FORM_dataN form is used instead. To work around that ambiguity, we treat the bounds as signed, and thus sign-extend their values, when the base type is signed. */ negative_mask = -((ULONGEST) 1 << (base_type->length () * TARGET_CHAR_BIT - 1)); if (low.kind () == PROP_CONST && !base_type->is_unsigned () && (low.const_val () & negative_mask)) low.set_const_val (low.const_val () | negative_mask); if (high.kind () == PROP_CONST && !base_type->is_unsigned () && (high.const_val () & negative_mask)) high.set_const_val (high.const_val () | negative_mask); Nothing in the testsuite seems to exercise it, as when I remove it, all of gdb.dwarf2 still passes. And tests in other directories would be compiler-dependent, so would rely on having a buggy compiler. Update gdb.dwarf2/subrange.exp to have a test for it. When removing the code above, the new test fails with: ptype array_with_buggy_negative_bounds_type^M type = array [240..244] of signed_byte^M (gdb) FAIL: gdb.dwarf2/subrange.exp: ptype array_with_buggy_negative_bounds_type instead of the expected: ptype array_with_buggy_negative_bounds_type^M type = array [-16..-12] of signed_byte^M (gdb) PASS: gdb.dwarf2/subrange.exp: ptype array_with_buggy_negative_bounds_type [1] https://gitlab.com/gnutools/binutils-gdb/-/blob/5ea14aa4e53fa37f4ba4517497ed2c1e4c60dee2/gdb/dwarf2/read.c#L17681-17695 Change-Id: I1992a3ff0cb1e90fa8a9114dae6c591792f059c2 --- gdb/testsuite/gdb.dwarf2/subrange.exp | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/gdb/testsuite/gdb.dwarf2/subrange.exp b/gdb/testsuite/gdb.dwarf2/subrange.exp index 72d7babc88e..8a8443f31a8 100644 --- a/gdb/testsuite/gdb.dwarf2/subrange.exp +++ b/gdb/testsuite/gdb.dwarf2/subrange.exp @@ -28,6 +28,7 @@ Dwarf::assemble $asm_file { compile_unit {{language @DW_LANG_Pascal83}} { declare_labels byte_label typedef_label array_label + # A subrange's underlying type that is a typedef. byte_label: base_type { {name byte} {encoding @DW_ATE_unsigned} @@ -54,6 +55,28 @@ Dwarf::assemble $asm_file { {name TByteArray} {type :$array_label} } + + # This subrange's underlying type is signed, but the bounds are + # specified using a non-signed form. + declare_labels signed_byte_label subrange_with_buggy_negative_bounds_label + + signed_byte_label: base_type { + {name signed_byte} + {encoding @DW_ATE_signed} + {byte_size 1 DW_FORM_sdata} + } + + # The bounds mean -16 to -12. + subrange_with_buggy_negative_bounds_label: subrange_type { + {lower_bound 0xf0 DW_FORM_udata} + {upper_bound 0xf4 DW_FORM_udata} + {type :$signed_byte_label} + } + + DW_TAG_variable { + {name subrange_with_buggy_negative_bounds_variable} + {type :$subrange_with_buggy_negative_bounds_label} + } } } } @@ -67,3 +90,5 @@ gdb_test_no_output "set language pascal" gdb_test "ptype TByteArray" \ "type = array \\\[0\\.\\.191\\\] of byte" +gdb_test "ptype subrange_with_buggy_negative_bounds_variable" \ + "type = -16..-12"