Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Yao Qi <qiyaoltc@gmail.com>
To: Alan Modra <amodra@gmail.com>
Cc: binutils@sourceware.org, gdb-patches@sourceware.org
Subject: Re: [PATCH 6/8] Return -1 on  memory error in print_insn_m68k
Date: Thu, 12 Jan 2017 11:50:00 -0000	[thread overview]
Message-ID: <20170112115021.GB31406@E107787-LIN> (raw)
In-Reply-To: <20170111221514.GI32333@bubble.grove.modra.org>

On 17-01-12 08:45:14, Alan Modra wrote:
> On Tue, Jan 10, 2017 at 12:26:16PM +0000, Yao Qi wrote:
> > 	* m68k-dis.c (match_insn_m68k): Extend comments.  Return -1
> > 	if FETCH_DATA returns 0.
> > 	(m68k_scan_mask): Likewise.
> > 	(print_insn_m68k): Update code to handle -1 return value.
> 
> This misses one FETCH_DATA call, in m68k_scan_mask.
> 

I can't remember the reason I didn't change it.  Sorry.

What about the patch below?  Regression tested on x86_64-linux
with all targets enabled.

-- 
Yao (齐尧)

From 926e74e41c2f0248d18821c2ac83adbd6c13d544 Mon Sep 17 00:00:00 2001
From: Yao Qi <yao.qi@linaro.org>
Date: Thu, 8 Dec 2016 17:16:39 +0000
Subject: [PATCH] Return -1 on  memory error in print_insn_m68k

m68k-dis.c:print_insn_m68k doesn't return -1 on memory error, but GDB
expects it returning -1 on memory error.

FETCH_DATA is used in m68k_scan_mask to fetch the next two bytes and
match instruction in the buffer if opcode is four-byte long.  That
makes difficult to check the return value of FETCH_DATA, so this
patch moves FETCH_DATA before matching instruction, so FETCH_DATA
is called if we know the opcode is four-byte long by
((0xffff & match) != 0).

opcodes:

2017-01-12  Yao Qi  <yao.qi@linaro.org>

	* m68k-dis.c (match_insn_m68k): Extend comments.  Return -1
	if FETCH_DATA returns 0.
	(m68k_scan_mask): Likewise.  Call FETCH_DATA before matching
	instructions.
	(print_insn_m68k): Update code to handle -1 return value.

diff --git a/opcodes/m68k-dis.c b/opcodes/m68k-dis.c
index a14db9a..2871ad8 100644
--- a/opcodes/m68k-dis.c
+++ b/opcodes/m68k-dis.c
@@ -1331,7 +1331,8 @@ print_insn_arg (const char *d,
 }
 
 /* Try to match the current instruction to best and if so, return the
-   number of bytes consumed from the instruction stream, else zero.  */
+   number of bytes consumed from the instruction stream, else zero.
+   Return -1 on memory error.  */
 
 static int
 match_insn_m68k (bfd_vma memaddr,
@@ -1415,12 +1416,14 @@ match_insn_m68k (bfd_vma memaddr,
 	 this because we know exactly what the second word is, and we
 	 aren't going to print anything based on it.  */
       p = buffer + 6;
-      FETCH_DATA (info, p);
+      if (!FETCH_DATA (info, p))
+	return -1;
       buffer[2] = buffer[4];
       buffer[3] = buffer[5];
     }
 
-  FETCH_DATA (info, p);
+  if (!FETCH_DATA (info, p))
+    return -1;
 
   save_p = p;
   info->print_address_func = dummy_print_address;
@@ -1439,7 +1442,7 @@ match_insn_m68k (bfd_vma memaddr,
 	{
 	  info->fprintf_func = save_printer;
 	  info->print_address_func = save_print_address;
-	  return 0;
+	  return eaten == PRINT_INSN_ARG_MEMORY_ERROR ? -1 : 0;
 	}
       else
 	{
@@ -1481,7 +1484,8 @@ match_insn_m68k (bfd_vma memaddr,
 /* Try to interpret the instruction at address MEMADDR as one that
    can execute on a processor with the features given by ARCH_MASK.
    If successful, print the instruction to INFO->STREAM and return
-   its length in bytes.  Return 0 otherwise.  */
+   its length in bytes.  Return 0 otherwise.  Return -1 on memory
+   error.  */
 
 static int
 m68k_scan_mask (bfd_vma memaddr, disassemble_info *info,
@@ -1523,7 +1527,8 @@ m68k_scan_mask (bfd_vma memaddr, disassemble_info *info,
 	*opc_pointer[(m68k_opcodes[i].opcode >> 28) & 15]++ = &m68k_opcodes[i];
     }
 
-  FETCH_DATA (info, buffer + 2);
+  if (!FETCH_DATA (info, buffer + 2))
+    return -1;
   major_opcode = (buffer[0] >> 4) & 15;
 
   for (i = 0; i < numopcodes[major_opcode]; i++)
@@ -1536,14 +1541,19 @@ m68k_scan_mask (bfd_vma memaddr, disassemble_info *info,
       if (*args == '.')
 	args++;
 
+      /* Fetch the next two bytes if opcode is four-bytes long.  */
+      if ((0xffff & match) != 0)
+	{
+	  if (!FETCH_DATA (info, buffer + 4))
+	    return -1;
+	}
+
       if (((0xff & buffer[0] & (match >> 24)) == (0xff & (opcode >> 24)))
 	  && ((0xff & buffer[1] & (match >> 16)) == (0xff & (opcode >> 16)))
-	  /* Only fetch the next two bytes if we need to.  */
 	  && (((0xffff & match) == 0)
-	      ||
-	      (FETCH_DATA (info, buffer + 4)
-	       && ((0xff & buffer[2] & (match >> 8)) == (0xff & (opcode >> 8)))
-	       && ((0xff & buffer[3] & match) == (0xff & opcode)))
+	      /* Match the next two bytes if opcode is four-bytes long.  */
+	      || (((0xff & buffer[2] & (match >> 8)) == (0xff & (opcode >> 8)))
+		  && ((0xff & buffer[3] & match) == (0xff & opcode)))
 	      )
 	  && (opc->arch & arch_mask) != 0)
 	{
@@ -1628,7 +1638,7 @@ print_insn_m68k (bfd_vma memaddr, disassemble_info *info)
       /* First try printing an m680x0 instruction.  Try printing a Coldfire
 	 one if that fails.  */
       val = m68k_scan_mask (memaddr, info, m68k_mask);
-      if (val == 0)
+      if (val <= 0)
 	val = m68k_scan_mask (memaddr, info, mcf_mask);
     }
   else


  reply	other threads:[~2017-01-12 11:50 UTC|newest]

Thread overview: 79+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-01-10 12:26 [PATCH 0/8] Handle memory error on disassemble Yao Qi
2017-01-10 12:26 ` [PATCH 3/8] Disassembly unit test: disassemble one instruction Yao Qi
2017-01-11 21:15   ` Simon Marchi
2017-01-12 13:06   ` Pedro Alves
2017-01-12 17:03     ` Yao Qi
2017-01-12 17:43       ` Pedro Alves
2017-01-12 21:04         ` Yao Qi
2017-01-12 14:35   ` Pedro Alves
2017-01-12 15:15   ` Pedro Alves
2017-01-12 15:35     ` Yao Qi
2017-01-12 15:44       ` Pedro Alves
2017-01-12 16:06     ` Pedro Alves
2017-01-10 12:26 ` [PATCH 6/8] Return -1 on memory error in print_insn_m68k Yao Qi
2017-01-11 22:15   ` Alan Modra
2017-01-12 11:50     ` Yao Qi [this message]
2017-01-12 14:38       ` Alan Modra
2017-01-12 14:52         ` Yao Qi
2017-01-13  1:54           ` Alan Modra
2017-01-13 12:29             ` Yao Qi
2017-01-10 12:26 ` [PATCH 7/8] Disassembly unit test: memory error Yao Qi
2017-01-10 12:26 ` [PATCH 5/8] Remove magic numbers in m68k-dis.c:print_insn_arg Yao Qi
2017-01-11 22:14   ` Alan Modra
2017-01-13 12:23     ` Yao Qi
2017-01-10 12:26 ` [PATCH 4/8] Return -1 on memory error in print_insn_msp430 Yao Qi
2017-01-11 21:54   ` Alan Modra
2017-01-12  9:43     ` Yao Qi
2017-01-10 12:27 ` [PATCH 8/8] Don't throw exception in dis_asm_memory_error Yao Qi
2017-01-12 16:40   ` Pedro Alves
2017-01-12 21:09     ` Yao Qi
2017-01-10 12:27 ` [PATCH 2/8] Call print_insn_mep in mep_gdb_print_insn Yao Qi
2017-01-11 20:50   ` Simon Marchi
2017-01-12 12:21     ` Yao Qi
2017-01-10 12:27 ` [PATCH 1/8] Refactor disassembly code Yao Qi
2017-01-11 20:43   ` Simon Marchi
2017-01-12 12:19     ` Yao Qi
2017-01-12 12:36       ` Pedro Alves
2017-01-12 15:29         ` Simon Marchi
2017-01-16 10:03 ` [PATCH 0/6 v2] Handle memory error on disassemble Yao Qi
2017-01-16 10:03   ` [PATCH 4/6] Disassembly unit test: disassemble one instruction Yao Qi
2017-01-20  0:04     ` Pedro Alves
2017-01-24 15:23       ` Yao Qi
2017-02-02 16:46         ` Pedro Alves
2017-02-02 22:12           ` Yao Qi
2017-02-02 23:39             ` [pushed] Fix "maintenance selftest" printing stray instructions (Re: [PATCH 4/6] Disassembly unit test: disassemble one instruction) Pedro Alves
2017-01-16 10:03   ` [PATCH 5/6] Disassembly unit test: memory error Yao Qi
2017-01-17 14:38     ` Luis Machado
2017-01-24 15:33       ` Yao Qi
2017-01-20  0:08     ` Pedro Alves
2017-01-16 10:03   ` [PATCH 1/6] New function null_stream Yao Qi
2017-01-17 13:49     ` Luis Machado
2017-01-18 14:45       ` Yao Qi
2017-01-18 14:53         ` Luis Machado
2017-01-18 14:57           ` Simon Marchi
2017-01-18 15:02             ` Luis Machado
2017-01-18 15:18               ` Simon Marchi
2017-01-18 15:29                 ` Luis Machado
2017-01-18 15:54                   ` Simon Marchi
2017-01-18 16:36                     ` Luis Machado
2017-01-16 10:03   ` [PATCH 2/6] Refactor disassembly code Yao Qi
2017-01-17 14:14     ` Luis Machado
2017-01-18 16:34       ` Yao Qi
2017-01-18 16:53         ` Luis Machado
2017-01-16 10:03   ` [PATCH 6/6] Don't throw exception in dis_asm_memory_error Yao Qi
2017-01-17 14:42     ` Luis Machado
2017-01-18 14:54       ` Yao Qi
2017-01-18 14:58         ` Luis Machado
2017-01-16 10:03   ` [PATCH 3/6] Call print_insn_mep in mep_gdb_print_insn Yao Qi
2017-01-17 14:19     ` Luis Machado
2017-01-24 10:08       ` Yao Qi
2017-01-24 13:41         ` Luis Machado
2017-01-25  8:38   ` [PATCH 0/6 v3] Handle memory error on disassembly Yao Qi
2017-01-25  8:38     ` [PATCH 5/6] Disassembly unit test: memory error Yao Qi
2017-01-25  8:38     ` [PATCH 1/6] New function null_stream Yao Qi
2017-01-25  8:38     ` [PATCH 6/6] Don't throw exception in dis_asm_memory_error Yao Qi
2017-01-25  8:38     ` [PATCH 3/6] Call print_insn_mep in mep_gdb_print_insn Yao Qi
2017-01-25  8:38     ` [PATCH 4/6] Disassembly unit test: disassemble one instruction Yao Qi
2017-01-25  8:38     ` [PATCH 2/6] Refactor disassembly code Yao Qi
2017-01-26 11:34     ` [PATCH 0/6 v3] Handle memory error on disassembly Pedro Alves
2017-01-26 15:00       ` 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=20170112115021.GB31406@E107787-LIN \
    --to=qiyaoltc@gmail.com \
    --cc=amodra@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