Handle memory error in print_insn_rx
authorYao Qi <yao.qi@linaro.org>
Mon, 12 Dec 2016 09:03:34 +0000 (09:03 +0000)
committerYao Qi <yao.qi@linaro.org>
Mon, 12 Dec 2016 09:03:34 +0000 (09:03 +0000)
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

opcodes:

2016-12-12  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/ChangeLog
opcodes/rx-dis.c

index df17f550a974a28dbd18bacc73b9afa97d255093..2f5c6c918ac53a023a004afe68d0ec3c1cee78da 100644 (file)
@@ -1,3 +1,11 @@
+2016-12-12  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.
+
 2016-12-12  Yao Qi  <yao.qi@linaro.org>
 
        * rl78-dis.c: Include <setjmp.h>.
index b0ff4b36974b4bc1e87af0bb63754cd6217e38c5..5f2bf352ff57a4b3f4e56c6dc1d9f04d6cf4544e 100644 (file)
 #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;
This page took 0.032671 seconds and 4 git commands to generate.