avrdis_opcode return type is unsigned short, but -1 at the end of
this function is returned. Additionally, print_insn_avr doesn't
handle when -1 (in case of memory error) is returned from
avrdis_opcode.
This patch changes avrdis_opcode returning int indicating the error,
and adds a new argument for instruction we got on success. The
opcode is 16-bit, so I change local variables type to uint16_t,
and include "bfd_stdint.h" as a result. On memory error,
print_insn_avr returns -1, which is a common convention among most
of print_insn_$ARCH functions.
opcodes:
2016-12-29 Yao Qi <yao.qi@linaro.org>
* avr-dis.c: Include "bfd_stdint.h"
(avrdis_opcode): Change return type to int, add argument
insn. Set *INSN on success.
(print_insn_avr): Check return value of avrdis_opcode, and
return -1 on error.
+2016-12-29 Yao Qi <yao.qi@linaro.org>
+
+ * avr-dis.c: Include "bfd_stdint.h"
+ (avrdis_opcode): Change return type to int, add argument
+ insn. Set *INSN on success.
+ (print_insn_avr): Check return value of avrdis_opcode, and
+ return -1 on error.
+
2016-12-28 Alan Modra <amodra@gmail.com>
* configure.ac: Revert 2016-12-23.
2016-12-28 Alan Modra <amodra@gmail.com>
* configure.ac: Revert 2016-12-23.
#include "dis-asm.h"
#include "opintl.h"
#include "libiberty.h"
#include "dis-asm.h"
#include "opintl.h"
#include "libiberty.h"
-static unsigned short
-avrdis_opcode (bfd_vma addr, disassemble_info *info)
+/* Read the opcode from ADDR. Return 0 in success and save opcode
+ in *INSN, otherwise, return -1. */
+
+static int
+avrdis_opcode (bfd_vma addr, disassemble_info *info, uint16_t *insn)
{
bfd_byte buffer[2];
int status;
{
bfd_byte buffer[2];
int status;
status = info->read_memory_func (addr, buffer, 2, info);
if (status == 0)
status = info->read_memory_func (addr, buffer, 2, info);
if (status == 0)
- return bfd_getl16 (buffer);
+ {
+ *insn = bfd_getl16 (buffer);
+ return 0;
+ }
info->memory_error_func (status, addr, info);
return -1;
info->memory_error_func (status, addr, info);
return -1;
int
print_insn_avr (bfd_vma addr, disassemble_info *info)
{
int
print_insn_avr (bfd_vma addr, disassemble_info *info)
{
- unsigned int insn, insn2;
const struct avr_opcodes_s *opcode;
static unsigned int *maskptr;
void *stream = info->stream;
const struct avr_opcodes_s *opcode;
static unsigned int *maskptr;
void *stream = info->stream;
- insn = avrdis_opcode (addr, info);
+ if (avrdis_opcode (addr, info, &insn) != 0)
+ return -1;
for (opcode = avr_opcodes, maskptr = avr_bin_masks;
opcode->name;
for (opcode = avr_opcodes, maskptr = avr_bin_masks;
opcode->name;
if (opcode->insn_size > 1)
{
if (opcode->insn_size > 1)
{
- insn2 = avrdis_opcode (addr + 2, info);
+ if (avrdis_opcode (addr + 2, info, &insn2) != 0)
+ return -1;