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_rl78_common
Date: Fri, 09 Dec 2016 17:00:00 -0000	[thread overview]
Message-ID: <1481302775-8931-1-git-send-email-yao.qi@linaro.org> (raw)

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

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

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

(gdb) set architecture rl78
The target architecture is assumed to be rl78
(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-08  Yao Qi  <yao.qi@linaro.org>

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

diff --git a/opcodes/rl78-dis.c b/opcodes/rl78-dis.c
index a23999d..c2b36db 100644
--- a/opcodes/rl78-dis.c
+++ b/opcodes/rl78-dis.c
@@ -29,6 +29,8 @@
 #include "opcode/rl78.h"
 #include "elf/rl78.h"
 
+#include <setjmp.h>
+
 #define DEBUG_SEMANTICS 0
 
 typedef struct
@@ -37,16 +39,30 @@ typedef struct
   disassemble_info * dis;
 } RL78_Data;
 
+struct private
+{
+  OPCODES_SIGJMP_BUF bailout;
+};
+
 static int
 rl78_get_byte (void * vdata)
 {
   bfd_byte buf[1];
   RL78_Data *rl78_data = (RL78_Data *) vdata;
+  int status;
+
+  status = rl78_data->dis->read_memory_func (rl78_data->pc,
+					     buf,
+					     1,
+					     rl78_data->dis);
+  if (status != 0)
+    {
+      struct private *priv = (struct private *) rl78_data->dis->private_data;
 
-  rl78_data->dis->read_memory_func (rl78_data->pc,
-				  buf,
-				  1,
-				  rl78_data->dis);
+      rl78_data->dis->memory_error_func (status, rl78_data->pc,
+					 rl78_data->dis);
+      OPCODES_SIGLONGJMP (priv->bailout, 1);
+    }
 
   rl78_data->pc ++;
   return buf[0];
@@ -92,10 +108,18 @@ print_insn_rl78_common (bfd_vma addr, disassemble_info * dis, RL78_Dis_Isa isa)
 #if DEBUG_SEMANTICS
   static char buf[200];
 #endif
+  struct private priv;
 
+  dis->private_data = (PTR) &priv;
   rl78_data.pc = addr;
   rl78_data.dis = dis;
 
+  if (OPCODES_SIGSETJMP (priv.bailout) != 0)
+    {
+      /* Error return.  */
+      return -1;
+    }
+
   rv = rl78_decode_opcode (addr, &opcode, rl78_get_byte, &rl78_data, isa);
 
   dis->bytes_per_line = 10;
-- 
1.9.1


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

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-12-09 17:00 Yao Qi [this message]
2016-12-10  0:20 ` Alan Modra
2016-12-12  9:04   ` 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=1481302775-8931-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