Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: <jaydeep.patil@imgtec.com>
To: <gdb-patches@sourceware.org>
Cc: <aburgess@redhat.com>, <vapier@gentoo.org>,
	<joseph.faulls@imgtec.com>, <bhushan.attarde@imgtec.com>,
	<jaydeep.patil@imgtec.com>
Subject: [PATCH v5 1/2] [sim/riscv] Fix crash during instruction decoding
Date: Fri, 22 Dec 2023 05:26:57 +0000	[thread overview]
Message-ID: <20231222052658.2102802-2-jaydeep.patil@imgtec.com> (raw)
In-Reply-To: <20231222052658.2102802-1-jaydeep.patil@imgtec.com>

From: Jaydeep Patil <jaydeep.patil@imgtec.com>

The match_never() function has been removed and thus step_once() crashes
during instruction decoding. Fixed it by checking for null pointer before
invoking function attached to match_func member of riscv_opcode structure.
---
 opcodes/riscv-dis.c  | 2 +-
 sim/riscv/sim-main.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/opcodes/riscv-dis.c b/opcodes/riscv-dis.c
index 68674380797..a89ebdd32ac 100644
--- a/opcodes/riscv-dis.c
+++ b/opcodes/riscv-dis.c
@@ -818,7 +818,7 @@ riscv_disassemble_insn (bfd_vma memaddr,
 	  if (op->pinfo == INSN_MACRO)
 	    continue;
 	  /* Does the opcode match?  */
-	  if (! (op->match_func) (op, word))
+	  if (! op->match_func || ! (op->match_func) (op, word))
 	    continue;
 	  /* Is this a pseudo-instruction and may we print it as such?  */
 	  if (no_aliases && (op->pinfo & INSN_ALIAS))
diff --git a/sim/riscv/sim-main.c b/sim/riscv/sim-main.c
index 4d205345395..65c0ea245b2 100644
--- a/sim/riscv/sim-main.c
+++ b/sim/riscv/sim-main.c
@@ -1042,7 +1042,7 @@ void step_once (SIM_CPU *cpu)
   for (; op->name; op++)
     {
       /* Does the opcode match?  */
-      if (! op->match_func (op, iw))
+      if (! op->match_func || ! op->match_func (op, iw))
 	continue;
       /* Is this a pseudo-instruction and may we print it as such?  */
       if (op->pinfo & INSN_ALIAS)
-- 
2.25.1


  reply	other threads:[~2023-12-22  5:27 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-12-22  5:26 [PATCH v5 0/2] sim: riscv: Compressed instruction simulation jaydeep.patil
2023-12-22  5:26 ` jaydeep.patil [this message]
2024-01-10 10:22   ` [PATCH v5 1/2] [sim/riscv] Fix crash during instruction decoding Andrew Burgess
2024-01-10 11:34     ` [EXTERNAL] " Jaydeep Patil
2023-12-22  5:26 ` [PATCH v5 2/2] [sim/riscv] Add support for compressed integer instructions jaydeep.patil
2024-01-04  4:24 ` [PATCH v5 0/2] sim: riscv: Compressed instruction simulation Jaydeep Patil
2024-01-05  5:41   ` Mike Frysinger

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=20231222052658.2102802-2-jaydeep.patil@imgtec.com \
    --to=jaydeep.patil@imgtec.com \
    --cc=aburgess@redhat.com \
    --cc=bhushan.attarde@imgtec.com \
    --cc=gdb-patches@sourceware.org \
    --cc=joseph.faulls@imgtec.com \
    --cc=vapier@gentoo.org \
    /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