Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Yao Qi <qiyaoltc@gmail.com>
To: binutils@sourceware.org
Cc: gdb-patches@sourceware.org
Subject: [PATCH] Handle memory error in print_insn_rx
Date: Fri, 09 Dec 2016 17:02:00 -0000	[thread overview]
Message-ID: <1481302917-9477-1-git-send-email-yao.qi@linaro.org> (raw)

Nowadays, memory error in rx disassembly is not handled, so if I
start a fresh GDB, and disassemble,

(gdb) set architecture rx
The target architecture is assumed to be rx
(gdb) disassemble 0x0,+4
Dump of assembler code from 0x0 to 0x4:
   0x00000000:	brk
   0x00000001:	brk
   0x00000002:	brk
   0x00000003:	brk

the output is wrong.  This patch adds code to call dis->memory_error_func
on memory error, and longjmp to print_insn_rx.  With this patch applied,

(gdb) set architecture rx
The target architecture is assumed to be rx
(gdb) disassemble 0,+4
Dump of assembler code from 0x0 to 0x4:
   0x00000000:	Cannot access memory at address 0x0

Regression tested with all targets enabled.  Is it OK?

opcodes:

2016-12-09  Yao Qi  <yao.qi@linaro.org>

	* rx-dis.c: Include <setjmp.h>
	(struct private): New.
	(rx_get_byte): Check return value of read_memory_func, and
	call memory_error_func and OPCODES_SIGLONGJMP on error.
	(print_insn_rx): Call OPCODES_SIGSETJMP.
---
 opcodes/rx-dis.c | 32 ++++++++++++++++++++++++++++----
 1 file changed, 28 insertions(+), 4 deletions(-)

diff --git a/opcodes/rx-dis.c b/opcodes/rx-dis.c
index b0ff4b3..5f2bf35 100644
--- a/opcodes/rx-dis.c
+++ b/opcodes/rx-dis.c
@@ -27,22 +27,38 @@
 #include "dis-asm.h"
 #include "opcode/rx.h"
 
+#include <setjmp.h>
+
 typedef struct
 {
   bfd_vma pc;
   disassemble_info * dis;
 } RX_Data;
 
+struct private
+{
+  OPCODES_SIGJMP_BUF bailout;
+};
+
 static int
 rx_get_byte (void * vdata)
 {
   bfd_byte buf[1];
   RX_Data *rx_data = (RX_Data *) vdata;
+  int status;
+
+  status = rx_data->dis->read_memory_func (rx_data->pc,
+					   buf,
+					   1,
+					   rx_data->dis);
+  if (status != 0)
+    {
+      struct private *priv = (struct private *) rx_data->dis->private_data;
 
-  rx_data->dis->read_memory_func (rx_data->pc,
-				  buf,
-				  1,
-				  rx_data->dis);
+      rx_data->dis->memory_error_func (status, rx_data->pc,
+				       rx_data->dis);
+       OPCODES_SIGLONGJMP (priv->bailout, 1);
+    }
 
   rx_data->pc ++;
   return buf[0];
@@ -92,10 +108,18 @@ print_insn_rx (bfd_vma addr, disassemble_info * dis)
   RX_Data rx_data;
   RX_Opcode_Decoded opcode;
   const char * s;
+  struct private priv;
 
+  dis->private_data = (PTR) &priv;
   rx_data.pc = addr;
   rx_data.dis = dis;
 
+  if (OPCODES_SIGSETJMP (priv.bailout) != 0)
+    {
+      /* Error return.  */
+      return -1;
+    }
+
   rv = rx_decode_opcode (addr, &opcode, rx_get_byte, &rx_data);
 
   dis->bytes_per_line = 10;
-- 
1.9.1


             reply	other threads:[~2016-12-09 17:02 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-12-09 17:02 Yao Qi [this message]
2016-12-10  0:21 ` Alan Modra
2016-12-12  9:05   ` Yao Qi

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=1481302917-9477-1-git-send-email-yao.qi@linaro.org \
    --to=qiyaoltc@gmail.com \
    --cc=binutils@sourceware.org \
    --cc=gdb-patches@sourceware.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