From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1726) id 881133858D1E; Wed, 10 Aug 2022 15:14:02 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 881133858D1E Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Andrew Burgess To: gdb-cvs@sourceware.org Subject: [binutils-gdb] gdb/riscv: implement cannot_store_register gdbarch method X-Act-Checkin: binutils-gdb X-Git-Author: mga-sc X-Git-Refname: refs/heads/master X-Git-Oldrev: e5f2f7d901ee735224b3a657c193f88c7ad79a07 X-Git-Newrev: f8053219836de69ceb8ff0e3e311b0585b1187b3 Message-Id: <20220810151402.881133858D1E@sourceware.org> Date: Wed, 10 Aug 2022 15:14:02 +0000 (GMT) X-BeenThere: gdb-cvs@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 10 Aug 2022 15:14:02 -0000 https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3Df8053219836d= e69ceb8ff0e3e311b0585b1187b3 commit f8053219836de69ceb8ff0e3e311b0585b1187b3 Author: mga-sc Date: Mon Aug 8 16:01:47 2022 +0300 gdb/riscv: implement cannot_store_register gdbarch method =20 The x0 (zero) register is read-only on RISC-V. Implement the cannot_store_register gdbarch method to tell GDB this. =20 Without this method GDB will try to write to x0, and relies on the target to ignore such writes. If you are using a target that complains (or throws an error) when writing to x0, this change will prevent this from happening. =20 The gdb.arch/riscv-reg-aliases.exp test exercises writing to x0, and will show the errors when using a suitable target. Diff: --- gdb/riscv-tdep.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/gdb/riscv-tdep.c b/gdb/riscv-tdep.c index 2d41be96b20..b9a51f7ae6a 100644 --- a/gdb/riscv-tdep.c +++ b/gdb/riscv-tdep.c @@ -933,6 +933,15 @@ riscv_register_name (struct gdbarch *gdbarch, int regn= um) return name; } =20 +/* Implement the cannot_store_register gdbarch method. The zero register + (x0) is read-only on RISC-V. */ + +static int +riscv_cannot_store_register (struct gdbarch *gdbarch, int regnum) +{ + return regnum =3D=3D RISCV_ZERO_REGNUM; +} + /* Construct a type for 64-bit FP registers. */ =20 static struct type * @@ -3822,6 +3831,9 @@ riscv_gdbarch_init (struct gdbarch_info info, registers, no matter what the target description called them. */ set_gdbarch_register_name (gdbarch, riscv_register_name); =20 + /* Tell GDB which RISC-V registers are read-only. */ + set_gdbarch_cannot_store_register (gdbarch, riscv_cannot_store_register); + /* Override the register group callback setup by the target description mechanism. This allows us to force registers into the groups we want, ignoring what the target tells us. */