From patchwork Sun Nov 20 02:23:29 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tsukasa OI X-Patchwork-Id: 23370 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp945431wrr; Sat, 19 Nov 2022 18:25:10 -0800 (PST) X-Google-Smtp-Source: AA0mqf7N5AHIipiiEd00W/n16CKLM9yEasgRp1DK1oif1DnMrvntgoDTYPc6eDcatRS9oqWDPOJc X-Received: by 2002:a17:906:3792:b0:7aa:97c7:2bfe with SMTP id n18-20020a170906379200b007aa97c72bfemr10869264ejc.196.1668911110579; Sat, 19 Nov 2022 18:25:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668911110; cv=none; d=google.com; s=arc-20160816; b=lR+DMhLIrNLlR1qxyUH9x/x3D1IYO09Tu6VOS2NBUhbW1aNBONA0f4nqpWrDWAxTAF G2yabShltT9xX174bvv8U2Og/6i6tO8peHm6G5uMsH/uqPZ9IVpb5i4dtEU9qESzTR7h L7FKa0+XLIMn21s8wDrumVrIOaer2q6yVW5g+8wSEapSsnO/2+pa8d7tDBZ2UPNmYmX1 9a8PPpZEf9viDB4Je9fqdRcVJMAsdzKDsW4GmKVQC6yszpQOJP9pyxPPs68IEddpF1Va P2UW4rm75gJCMFKkFrxHVqu9sXyj03w0TEOfVhw+gbiECzYZJr3Vy4mDeL9BGOUn5hh7 PjOQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:dmarc-filter:delivered-to :dkim-signature:dkim-filter; bh=JaJBVhZ8mV4vtN4bz/lG4FB8PjFnD3ypvajKIjkEdXQ=; b=xo2HVtNXkgO9nQbkoVsvJDZO/hn2HweRGK+20vfHaG4miKLDioD75PwD78aSzsklM8 zneBD/ANQUXJIFQTHnW8VoAnk2xAKj2zgIbYw++7UCHxW4oCsQw8GXIUO4xjL4ujC+c8 elIq215SarWlTCcX3dJmO4yyugXwsEYgMSwg3cOKP0/kuoOAcTBMdWUhZ3ob5xHyBx9D xIdWlNlTajmPjY+57NPm1hfswMvpf/uVdo5vwqaz8GbM5tZS2CIHob4yZ6IBYBo9yDhy FwfxwfOynPcPUEuv3HSl2Hi4IdDitMbCoeH01t3iPTTMJolFB88dYMBbuTCmNH89nWL+ inXQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=HBBvWRE6; spf=pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="binutils-bounces+ouuuleilei=gmail.com@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=sourceware.org Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id hc42-20020a17090716aa00b007ae814af68dsi8377489ejc.355.2022.11.19.18.25.10 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 19 Nov 2022 18:25:10 -0800 (PST) Received-SPF: pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=HBBvWRE6; spf=pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="binutils-bounces+ouuuleilei=gmail.com@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 97E813899016 for ; Sun, 20 Nov 2022 02:25:08 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 97E813899016 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1668911108; bh=JaJBVhZ8mV4vtN4bz/lG4FB8PjFnD3ypvajKIjkEdXQ=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=HBBvWRE6+U1t8KbomUBdt1qukYY2VajyyvGZbyBXekYFnIP3Jqnsurs6wtkoZ1uQU fSqtI3/DveEKWM8diAlXm8fafNb73F5JUGGypMgA0kdcFM7OTGrVOjD0uUGKPAJtSW 4BaqiH9etk/GT2vAY36rKfDmus323twwEsRT0ZSc= X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org Received: from mail-sender-0.a4lg.com (mail-sender.a4lg.com [153.120.152.154]) by sourceware.org (Postfix) with ESMTPS id 40B30389851D; Sun, 20 Nov 2022 02:24:26 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 40B30389851D Received: from [127.0.0.1] (localhost [127.0.0.1]) by mail-sender-0.a4lg.com (Postfix) with ESMTPSA id 7F3C430008C; Sun, 20 Nov 2022 02:24:24 +0000 (UTC) To: Tsukasa OI , Nelson Chu , Kito Cheng , Palmer Dabbelt Cc: binutils@sourceware.org, gdb-patches@sourceware.org Subject: [PATCH v3 3/3] gdb/testsuite: RISC-V disassembler option tests Date: Sun, 20 Nov 2022 02:23:29 +0000 Message-Id: <70a4ac1ba8c12101de56c24d3a47939a2f5ee542.1668910970.git.research_trasio@irq.a4lg.com> In-Reply-To: References: Mime-Version: 1.0 X-Spam-Status: No, score=-12.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, GIT_PATCH_0, KAM_SHORT, SPF_HELO_NONE, SPF_PASS, 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: binutils@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Binutils mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Tsukasa OI via Binutils From: Tsukasa OI Reply-To: Tsukasa OI Errors-To: binutils-bounces+ouuuleilei=gmail.com@sourceware.org Sender: "Binutils" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1749980136490811395?= X-GMAIL-MSGID: =?utf-8?q?1749980136490811395?= From: Tsukasa OI This commit adds RISC-V disassembler option tests for: - "no-aliases" and "numeric" options - overridable "priv-spec" option - new "arch" option and makes sure that option override correctly works and they can be unset thereafter (with "set disassembler-options" with no options). --- .../gdb.arch/riscv-disassembler-options.exp | 129 ++++++++++++++++++ .../gdb.arch/riscv-disassembler-options.s | 29 ++++ 2 files changed, 158 insertions(+) create mode 100644 gdb/testsuite/gdb.arch/riscv-disassembler-options.exp create mode 100644 gdb/testsuite/gdb.arch/riscv-disassembler-options.s diff --git a/gdb/testsuite/gdb.arch/riscv-disassembler-options.exp b/gdb/testsuite/gdb.arch/riscv-disassembler-options.exp new file mode 100644 index 000000000000..e5548eb426d3 --- /dev/null +++ b/gdb/testsuite/gdb.arch/riscv-disassembler-options.exp @@ -0,0 +1,129 @@ +# Copyright 2022 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 RISC-V disassembler options. + +if {![istarget "riscv*-*-*"]} { + verbose "Skipping ${gdb_test_file_name}." + return +} + +standard_testfile .s +set objfile [standard_output_file ${testfile}.o] + +set compile_flags { \ + "additional_flags=-march=rv64i_zicsr -mabi=lp64" \ + "additional_flags=-Xassembler -mpriv-spec=1.11" \ + } + +if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${objfile}" object \ + ${compile_flags}] != "" } { + untested "could not compile test program" + return +} + +clean_restart ${objfile} + +proc riscv_set_disassembler_options { opts } { + gdb_test_no_output "set disassembler-options $opts" + gdb_test "show disassembler-options" \ + "The current disassembler options are '$opts'\r\n.*" \ + "show disassembler-options: $opts" +} + +# We can disable disassembly using alias instructions. +riscv_set_disassembler_options "no-aliases" +gdb_test_sequence "disassemble test_func" "option: no-aliases" { + "Dump of assembler code for function test_func:\r\n" + "\[^:\]+:\taddi\ta0,zero,1\r\n" + "\[^:\]+:\tcsrrs\ta0,0x3d0,zero\r\n" + "\[^:\]+:\t\\.4byte\t0x62000073\r\n" + "\[^:\]+:\tjalr\tzero,0\\(ra\\)\r\n" + "End of assembler dump\." +} + +# We can disassemble using numeric register names. +riscv_set_disassembler_options "numeric" +gdb_test_sequence "disassemble test_func" "option: numeric" { + "Dump of assembler code for function test_func:\r\n" + "\[^:\]+:\tli\tx10,1\r\n" + "\[^:\]+:\tcsrr\tx10,0x3d0\r\n" + "\[^:\]+:\t\\.4byte\t0x62000073\r\n" + "\[^:\]+:\tret\r\n" + "End of assembler dump\." +} + +# We can switch to the privileged specification 1.11. +riscv_set_disassembler_options "priv-spec=1.11" +gdb_test_sequence "disassemble test_func" "privileged specification 1.11 CSRs" { + "Dump of assembler code for function test_func:\r\n" + "\[^:\]+:\tli\ta0,1\r\n" + "\[^:\]+:\tcsrr\ta0,0x3d0\r\n" + "\[^:\]+:\t\\.4byte\t0x62000073\r\n" + "\[^:\]+:\tret\r\n" + "End of assembler dump\." +} + +# We can switch to the privileged specification 1.12. +riscv_set_disassembler_options "priv-spec=1.12" +gdb_test_sequence "disassemble test_func" "privileged specification 1.12 CSRs" { + "Dump of assembler code for function test_func:\r\n" + "\[^:\]+:\tli\ta0,1\r\n" + "\[^:\]+:\tcsrr\ta0,pmpaddr32\r\n" + "\[^:\]+:\t\\.4byte\t0x62000073\r\n" + "\[^:\]+:\tret\r\n" + "End of assembler dump\." +} + +# We can enable the 'H'-extension support. +riscv_set_disassembler_options "arch=rv64gch" +gdb_test_sequence "disassemble test_func" "'H'-extension" { + "Dump of assembler code for function test_func:\r\n" + "\[^:\]+:\tli\ta0,1\r\n" + "\[^:\]+:\tcsrr\ta0,0x3d0\r\n" + "\[^:\]+:\thfence\\.gvma\r\n" + "\[^:\]+:\tret\r\n" + "End of assembler dump\." +} + +# We can set multiple comma-separated options +riscv_set_disassembler_options "arch=rv64gch,priv-spec=1.12,no-aliases,numeric" +gdb_test_sequence "disassemble test_func" "multiple options" { + "Dump of assembler code for function test_func:\r\n" + "\[^:\]+:\taddi\tx10,x0,1\r\n" + "\[^:\]+:\tcsrrs\tx10,pmpaddr32,x0\r\n" + "\[^:\]+:\thfence\\.gvma\tx0,x0\r\n" + "\[^:\]+:\tjalr\tx0,0\\(x1\\)\r\n" + "End of assembler dump\." +} + +# Once we set empty disassembler option, we can restore the default one. +# Defaults: +# - enable aliases +# - ABI register names +# - priv-spec=1.11 +# - arch=rv64i_zicsr +gdb_test_no_output "set disassembler-options" "set NULL disassembler-options" +gdb_test "show disassembler-options" \ + "The current disassembler options are ''\r\n.*" \ + "show NULL disassembler-options" +gdb_test_sequence "disassemble test_func" "restore to default" { + "Dump of assembler code for function test_func:\r\n" + "\[^:\]+:\tli\ta0,1\r\n" + "\[^:\]+:\tcsrr\ta0,0x3d0\r\n" + "\[^:\]+:\t\\.4byte\t0x62000073\r\n" + "\[^:\]+:\tret\r\n" + "End of assembler dump\." +} diff --git a/gdb/testsuite/gdb.arch/riscv-disassembler-options.s b/gdb/testsuite/gdb.arch/riscv-disassembler-options.s new file mode 100644 index 000000000000..fc33b03b0c00 --- /dev/null +++ b/gdb/testsuite/gdb.arch/riscv-disassembler-options.s @@ -0,0 +1,29 @@ +/* Copyright 2022 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 . */ + + .attribute arch, "rv64i_zicsr" + .option nopic + .text + + .align 1 + .globl test_func + .type test_func, @function +test_func: + li a0, 1 + csrr a0, 0x3d0 + # hfence.gvma (an alias of hfence.gvma zero,zero) + .insn 0x62000073 + ret + .size test_func, .-test_func