Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Charlie Jenkins <charlie@rivosinc.com>
To: jiawei <jiawei@iscas.ac.cn>, Nelson Chu <nelson@rivosinc.com>,
	 Charlie Jenkins <charlie@rivosinc.com>,
	Jan Beulich <jbeulich@suse.com>,
	 Andrew Burgess <aburgess@redhat.com>
Cc: gdb-patches <gdb-patches@sourceware.org>,
	 Binutils <binutils@sourceware.org>
Subject: [PATCH v2 1/2] RISC-V: Fix abort when displaying .dword
Date: Tue, 18 Feb 2025 19:35:21 -0800	[thread overview]
Message-ID: <20250218-fix_gas_abort-v2-1-14457aa7387e@rivosinc.com> (raw)
In-Reply-To: <20250218-fix_gas_abort-v2-0-14457aa7387e@rivosinc.com>

In the normal case an instruction won't be split into 5, 6, or 7 byte
sections. However a .dword disassembled with -D can cause an instruction
to split across the 6 byte boundary. 6 byte instructions were not
supported so riscv_disassemble_data() would abort.

If data is encountered that is not a power of two, dump all of the data
with a .<N>byte directive.

Signed-off-by: Charlie Jenkins <charlie@rivosinc.com>
Fixes: 6a04e8230707 ("RISC-V: Fix display of partial instructions")
---
 opcodes/riscv-dis.c | 19 ++++++++++---------
 1 file changed, 10 insertions(+), 9 deletions(-)

diff --git a/opcodes/riscv-dis.c b/opcodes/riscv-dis.c
index 3956f588f8f749935b23e6a4dc4fab95ef66d013..d02723ed38ff368e9ce0a48e49d8f87820551a50 100644
--- a/opcodes/riscv-dis.c
+++ b/opcodes/riscv-dis.c
@@ -1317,14 +1317,6 @@ riscv_disassemble_data (bfd_vma memaddr ATTRIBUTE_UNUSED,
       (*info->fprintf_styled_func)
 	(info->stream, dis_style_immediate, "0x%04x", (unsigned) data);
       break;
-    case 3:
-      info->bytes_per_line = 7;
-      (*info->fprintf_styled_func)
-	(info->stream, dis_style_assembler_directive, ".word");
-      (*info->fprintf_styled_func) (info->stream, dis_style_text, "\t");
-      (*info->fprintf_styled_func)
-	(info->stream, dis_style_immediate, "0x%06x", (unsigned) data);
-      break;
     case 4:
       info->bytes_per_line = 8;
       (*info->fprintf_styled_func)
@@ -1344,7 +1336,16 @@ riscv_disassemble_data (bfd_vma memaddr ATTRIBUTE_UNUSED,
 	 (unsigned long long) data);
       break;
     default:
-      abort ();
+      /* Arbitrary data so just print the bits in the shape of an .<N>byte
+	 directive.  */
+      info->bytes_per_line = info->bytes_per_chunk;
+      (*info->fprintf_styled_func)
+	(info->stream, dis_style_assembler_directive, ".%dbyte", info->bytes_per_chunk);
+      (*info->fprintf_styled_func) (info->stream, dis_style_text, "\t");
+      (*info->fprintf_styled_func)
+	(info->stream, dis_style_immediate, "0x%0llx",
+	  (unsigned long long) data);
+      break;
     }
   return info->bytes_per_chunk;
 }

-- 
2.43.0


  reply	other threads:[~2025-02-19  3:42 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-02-19  3:35 [PATCH v2 0/2] RISC-V: Fix abort when displaying data and add test Charlie Jenkins
2025-02-19  3:35 ` Charlie Jenkins [this message]
2025-02-19  3:35 ` [PATCH v2 2/2] RISC-V: Add testcase for 6 byte instruction Charlie Jenkins
2025-02-19  9:25   ` Jan Beulich
2025-02-19 17:11     ` Charlie Jenkins

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250218-fix_gas_abort-v2-1-14457aa7387e@rivosinc.com \
    --to=charlie@rivosinc.com \
    --cc=aburgess@redhat.com \
    --cc=binutils@sourceware.org \
    --cc=gdb-patches@sourceware.org \
    --cc=jbeulich@suse.com \
    --cc=jiawei@iscas.ac.cn \
    --cc=nelson@rivosinc.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox