[0/1] riscv: Ensure LE instruction fetching

Message ID AM6PR03MB49848E63E54AAB7B7C0D80E4985CA@AM6PR03MB4984.eurprd03.prod.outlook.com
State Repeat Merge
Headers

Checks

Context Check Description
snail/binutils-gdb-check warning Git am fail log

Commit Message

Branislav Brzak June 20, 2023, 11:43 a.m. UTC
  Currently riscv gdb code looks at arch byte order
when fetching instructions. This works when the
target is LE, but on BE arch it will byte swap the
instruction, while the riscv spec defines all
instructions are LE encoded regardless of
system memory endianess.

Branislav Brzak (1):
gdb/riscv: Ensure LE instruction fetching

gdb/riscv-tdep.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
  

Comments

Jan Beulich June 20, 2023, 11:44 a.m. UTC | #1
On 20.06.2023 13:43, Branislav Brzak wrote:
> Currently riscv gdb code looks at arch byte order
> when fetching instructions. This works when the
> target is LE, but on BE arch it will byte swap the
> instruction, while the riscv spec defines all
> instructions are LE encoded regardless of
> system memory endianess.
> 
> Branislav Brzak (1):
> gdb/riscv: Ensure LE instruction fetching
> 
> gdb/riscv-tdep.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)

Looks like you meant to send this to gdb-patches@sourceware.org?

Jan
  
Branislav Brzak June 20, 2023, 11:46 a.m. UTC | #2
I have, I apologize for this.

Regards,
Branislav
  

Patch

From 391716c3138697a0b8a1836c1ffdb44b1b6b9da4 Mon Sep 17 00:00:00 2001
From: Branislav Brzak <branislav.brzak@syrmia.com>
Date: Tue, 20 Jun 2023 13:20:40 +0200
Subject: [PATCH] * riscv-tdep.c (riscv_insn::fetch_instruction): Always fetch
 instructions as LE

---
 gdb/riscv-tdep.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gdb/riscv-tdep.c b/gdb/riscv-tdep.c
index 500279e1ae9..b4f98089937 100644
--- a/gdb/riscv-tdep.c
+++ b/gdb/riscv-tdep.c
@@ -1812,7 +1812,7 @@  ULONGEST
 riscv_insn::fetch_instruction (struct gdbarch *gdbarch,
 			       CORE_ADDR addr, int *len)
 {
-  enum bfd_endian byte_order = gdbarch_byte_order_for_code (gdbarch);
+  enum bfd_endian byte_order = BFD_ENDIAN_LITTLE;
   gdb_byte buf[RISCV_MAX_INSN_LEN];
   int instlen, status;
 
-- 
2.34.1