Handle memory error in print_insn_rl78_common

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

opcodes:

2016-12-12  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.
This commit is contained in:
Yao Qi 2016-12-12 09:03:34 +00:00
parent cc90de4973
commit 3a0b8f7ddb
2 changed files with 36 additions and 4 deletions

View File

@ -1,3 +1,11 @@
2016-12-12 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.
2016-12-09 Maciej W. Rozycki <macro@imgtec.com>
* mips16-opc.c (decode_mips16_operand) <'>'>: Remove cases.

View File

@ -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;
rl78_data->dis->read_memory_func (rl78_data->pc,
buf,
1,
rl78_data->dis);
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->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;