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 4/8] Return -1 on memory error in print_insn_msp430
Date: Thu, 12 Jan 2017 09:43:00 -0000	[thread overview]
Message-ID: <20170112094256.GA31406@E107787-LIN> (raw)
In-Reply-To: <20170111215446.GG32333@bubble.grove.modra.org>

On 17-01-12 08:24:46, Alan Modra wrote:
> On Tue, Jan 10, 2017 at 12:26:14PM +0000, Yao Qi wrote:
> > 	* msp430-dis.c (msp430_singleoperand): Return -1 if
> > 	msp430dis_opcode_signed returns false.
> > 	(msp430_doubleoperand): Likewise.
> > 	(msp430_branchinstr): Return -1 if
> > 	msp430dis_opcode_unsigned returns false.
> > 	(msp430x_calla_instr): Likewise.
> > 	(print_insn_msp430): Likewise.
> 
> You missed nine msp430dis_opcode_signed calls.  OK with those done too.
> 

Looks cscope missed some "Functions calling this function: msp430dis_opcode_signed"
but "C symbol: msp430dis_opcode_signed" can capture all of them.  Fixed.

Patch below is what I pushed in.

-- 
Yao (齐尧)

From d95014a2ef6e9aee927c13960fa37e509d46eb32 Mon Sep 17 00:00:00 2001
From: Yao Qi <yao.qi@linaro.org>
Date: Thu, 12 Jan 2017 09:40:41 +0000
Subject: [PATCH] Return -1 on memory error in print_insn_msp430

Disassemblers in opcodes return -1 on memory error, but msp430 doesn't
follow this convention.  If I change GDB not to throw exception in
disassemble_info.memory_error_func and rely on the return value of
disassembler, I'll get the following output.

(gdb) disassemble 0x0,+8
Dump of assembler code from 0x0 to 0x8:
   0x00000000:  .word   0xffff; ????
   0x00000002:  .word   0xffff; ????
   0x00000004:  .word   0xffff; ????
   0x00000006:  .word   0xffff; ????
End of assembler dump.

This patch teaches print_insn_msp430 and its callees to return -1
on memory error.

opcodes:

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

	* msp430-dis.c (msp430_singleoperand): Return -1 if
	msp430dis_opcode_signed returns false.
	(msp430_doubleoperand): Likewise.
	(msp430_branchinstr): Return -1 if
	msp430dis_opcode_unsigned returns false.
	(msp430x_calla_instr): Likewise.
	(print_insn_msp430): Likewise.

diff --git a/opcodes/ChangeLog b/opcodes/ChangeLog
index 8494c51..5d670f6 100644
--- a/opcodes/ChangeLog
+++ b/opcodes/ChangeLog
@@ -1,3 +1,13 @@
+2017-01-12  Yao Qi  <yao.qi@linaro.org>
+
+	* msp430-dis.c (msp430_singleoperand): Return -1 if
+	msp430dis_opcode_signed returns false.
+	(msp430_doubleoperand): Likewise.
+	(msp430_branchinstr): Return -1 if
+	msp430dis_opcode_unsigned returns false.
+	(msp430x_calla_instr): Likewise.
+	(print_insn_msp430): Likewise.
+
 2017-01-05  Nick Clifton  <nickc@redhat.com>
 
 	PR 20946
diff --git a/opcodes/msp430-dis.c b/opcodes/msp430-dis.c
index 9c62193..58d31df 100644
--- a/opcodes/msp430-dis.c
+++ b/opcodes/msp430-dis.c
@@ -270,6 +270,8 @@ msp430_singleoperand (disassemble_info *info,
 			       (long)((addr + 2 + dst) & 0xfffff));
 		    }
 		}
+	      else
+		return -1;
 	    }
 	  else if (regd == 2)
 	    {
@@ -285,6 +287,8 @@ msp430_singleoperand (disassemble_info *info,
 		      sprintf (op, "&0x%05x", dst & 0xfffff);
 		    }
 		}
+	      else
+		return -1;
 	    }
 	  else
 	    {
@@ -300,6 +304,8 @@ msp430_singleoperand (disassemble_info *info,
 		    }
 		  sprintf (op, "%d(r%d)", dst, regd);
 		}
+	      else
+		return -1;
 	    }
 	}
       break;
@@ -346,6 +352,8 @@ msp430_singleoperand (disassemble_info *info,
 			sprintf (comm, "#0x%05x", dst);
 		    }
 		}
+	      else
+		return -1;
 	    }
 	  else
 	    * cycles = print_as3_reg_name (regd, op, comm, 1, 1, 3);
@@ -370,6 +378,8 @@ msp430_singleoperand (disassemble_info *info,
 			       (long)((addr + 2 + dst) & 0xfffff));
 		    }
 		}
+	      else
+		return -1;
 	    }
 	  else if (regd == 2)
 	    {
@@ -384,6 +394,8 @@ msp430_singleoperand (disassemble_info *info,
 		      sprintf (op, "&0x%05x", dst & 0xfffff);
 		    }
 		}
+	      else
+		return -1;
 	    }
 	  else if (regd == 3)
 	    {
@@ -407,6 +419,8 @@ msp430_singleoperand (disassemble_info *info,
 		  if (dst > 9 || dst < 0)
 		    sprintf (comm, "%05x", dst);
 		}
+	      else
+		return -1;
 	    }
 	}
       break;
@@ -511,6 +525,8 @@ msp430_doubleoperand (disassemble_info *info,
 			       (long)((addr + 2 + dst) & 0xfffff));
 		    }
 		}
+	      else
+		return -1;
 	    }
 	  else if (regd == 2)
 	    {
@@ -526,6 +542,8 @@ msp430_doubleoperand (disassemble_info *info,
 		      if (src != dst)
 			return 0;
 		    }
+		  else
+		    return -1;
 		  cmd_len += 4;
 		  *cycles = 6;
 		  sprintf (op1, "&0x%04x", PS (dst));
@@ -535,6 +553,8 @@ msp430_doubleoperand (disassemble_info *info,
 		      sprintf (op1, "&0x%05x", dst & 0xfffff);
 		    }
 		}
+	      else
+		return -1;
 	    }
 	  else
 	    {
@@ -553,6 +573,8 @@ msp430_doubleoperand (disassemble_info *info,
 		  if (dst > 9 || dst < -9)
 		    sprintf (comm1, "#0x%05x", dst);
 		}
+	      else
+		return -1;
 	    }
 	}
 
@@ -613,6 +635,8 @@ msp430_doubleoperand (disassemble_info *info,
 		    sprintf (comm1, "0x%05x", dst & 0xfffff);
 		}
 	    }
+	  else
+	    return -1;
 	}
       else
 	* cycles = print_as3_reg_name (regs, op1, comm1, 1, 1, 2);
@@ -640,6 +664,8 @@ msp430_doubleoperand (disassemble_info *info,
 			   (long) ((addr + 2 + dst) & 0xfffff));
 		}
 	    }
+	  else
+	    return -1;
 	}
       else if (regs == 2)
 	{
@@ -658,6 +684,8 @@ msp430_doubleoperand (disassemble_info *info,
 		  * comm1 = 0;
 		}
 	    }
+	  else
+	    return -1;
 	}
       else if (regs == 3)
 	{
@@ -683,6 +711,8 @@ msp430_doubleoperand (disassemble_info *info,
 	      if (dst > 9 || dst < -9)
 		sprintf (comm1, "0x%05x", dst);
 	    }
+	  else
+	    return -1;
 	}
     }
 
@@ -728,6 +758,8 @@ msp430_doubleoperand (disassemble_info *info,
 			   (long)((addr + cmd_len + dst) & 0xfffff));
 		}
 	    }
+	  else
+	    return -1;
 	  cmd_len += 2;
 	}
       else if (regd == 2)
@@ -743,6 +775,8 @@ msp430_doubleoperand (disassemble_info *info,
 		  sprintf (op2, "&0x%05x", dst & 0xfffff);
 		}
 	    }
+	  else
+	    return -1;
 	}
       else
 	{
@@ -761,6 +795,8 @@ msp430_doubleoperand (disassemble_info *info,
 		}
 	      sprintf (op2, "%d(r%d)", dst, regd);
 	    }
+	  else
+	    return -1;
 	}
     }
 
@@ -821,6 +857,8 @@ msp430_branchinstr (disassemble_info *info,
 	      cmd_len += 2;
 	      sprintf (op1, "#0x%04x", PS (udst));
 	    }
+	  else
+	    return -1;
 	}
       else
 	* cycles = print_as3_reg_name (regs, op1, comm1, 1, 1, 2);
@@ -840,6 +878,8 @@ msp430_branchinstr (disassemble_info *info,
 	      sprintf (comm1, "PC rel. 0x%04x",
 		       PS ((short) addr + 2 + dst));
 	    }
+	  else
+	    return -1;
 	}
       else if (regs == 2)
 	{
@@ -849,6 +889,8 @@ msp430_branchinstr (disassemble_info *info,
 	      cmd_len += 2;
 	      sprintf (op1, "&0x%04x", PS (udst));
 	    }
+	  else
+	    return -1;
 	}
       else if (regs == 3)
 	{
@@ -864,6 +906,8 @@ msp430_branchinstr (disassemble_info *info,
 	      cmd_len += 2;
 	      sprintf (op1, "%d(r%d)", dst, regs);
 	    }
+	  else
+	    return -1;
 	}
     }
 
@@ -903,6 +947,8 @@ msp430x_calla_instr (disassemble_info * info,
 	  else
 	    sprintf (comm1, "0x%05x", dst);
 	}
+      else
+	return -1;
       break;
 
     case 6: /* CALLA @Rdst */
@@ -923,6 +969,8 @@ msp430x_calla_instr (disassemble_info * info,
 	  sprintf (op1, "&%d", (ureg << 16) + udst);
 	  sprintf (comm1, "0x%05x", (ureg << 16) + udst);
 	}
+      else
+	return -1;
       break;
 
     case 9: /* CALLA pcrel-sym */
@@ -934,6 +982,8 @@ msp430x_calla_instr (disassemble_info * info,
 	  sprintf (comm1, "PC rel. 0x%05lx",
 		   (long) (addr + 2 + dst + (reg << 16)));
 	}
+      else
+	return -1;
       break;
 
     case 11: /* CALLA #imm20 */
@@ -944,6 +994,8 @@ msp430x_calla_instr (disassemble_info * info,
 	  sprintf (op1, "#%d", (ureg << 16) + udst);
 	  sprintf (comm1, "0x%05x", (ureg << 16) + udst);
 	}
+      else
+	return -1;
       break;
 
     default:
@@ -969,10 +1021,7 @@ print_insn_msp430 (bfd_vma addr, disassemble_info *info)
   unsigned short bits;
 
   if (! msp430dis_opcode_unsigned (addr, info, &insn, NULL))
-    {
-      prin (stream, ".word	0xffff;	????");
-      return 2;
-    }
+    return -1;
 
   if (((int) addr & 0xffff) > 0xffdf)
     {
@@ -989,11 +1038,7 @@ print_insn_msp430 (bfd_vma addr, disassemble_info *info)
       extension_word = insn;
       addr += 2;
       if (! msp430dis_opcode_unsigned (addr, info, &insn, NULL))
-	{
-	  prin (stream, ".word	0x%04x, 0xffff;	????",
-		extension_word);
-	  return 4;
-	}
+	return -1;
    }
 
   for (opcode = msp430_opcodes; opcode->name; opcode++)
@@ -1011,9 +1056,13 @@ print_insn_msp430 (bfd_vma addr, disassemble_info *info)
 	      && (insn & 0x000f) == 0
 	      && (insn & 0x0080) == 0)
 	    {
-	      cmd_len +=
+	      int ret =
 		msp430_branchinstr (info, opcode, addr, insn, op1, comm1,
 				    &cycles);
+
+	      if (ret == -1)
+		return -1;
+	      cmd_len += ret;
 	      if (cmd_len)
 		break;
 	    }
@@ -1022,10 +1071,14 @@ print_insn_msp430 (bfd_vma addr, disassemble_info *info)
 	    {
 	      int n;
 	      int reg;
+	      int ret;
 
 	    case 4:
-	      cmd_len += msp430x_calla_instr (info, addr, insn,
-					      op1, comm1, & cycles);
+	      ret = msp430x_calla_instr (info, addr, insn,
+					 op1, comm1, & cycles);
+	      if (ret == -1)
+		return -1;
+	      cmd_len += ret;
 	      break;
 
 	    case 5: /* PUSHM/POPM */
@@ -1080,6 +1133,8 @@ print_insn_msp430 (bfd_vma addr, disassemble_info *info)
 		      if (n > 9 || n < 0)
 			sprintf (comm1, "0x%05x", n);
 		    }
+		  else
+		    return -1;
 		  cmd_len = 4;
 		}
 	      sprintf (op2, "r%d", reg);
@@ -1120,6 +1175,8 @@ print_insn_msp430 (bfd_vma addr, disassemble_info *info)
 		      if (strcmp (opcode->name, "bra") != 0)
 			sprintf (op2, "r%d", reg);
 		    }
+		  else
+		    return -1;
 		  break;
 
 		case 3: /* MOVA x(Rsrc), Rdst */
@@ -1139,6 +1196,8 @@ print_insn_msp430 (bfd_vma addr, disassemble_info *info)
 			    sprintf (comm1, "0x%05x", n);
 			}
 		    }
+		  else
+		    return -1;
 		  break;
 
 		case 6: /* MOVA Rsrc, &abs20 */
@@ -1152,6 +1211,8 @@ print_insn_msp430 (bfd_vma addr, disassemble_info *info)
 		      if (reg > 9 || reg < 0)
 			sprintf (comm2, "0x%05x", reg);
 		    }
+		  else
+		    return -1;
 		  break;
 
 		case 7: /* MOVA Rsrc, x(Rdst) */
@@ -1169,6 +1230,8 @@ print_insn_msp430 (bfd_vma addr, disassemble_info *info)
 			    sprintf (comm2, "0x%05x", n);
 			}
 		    }
+		  else
+		    return -1;
 		  break;
 
 		case 8: /* MOVA #imm20, Rdst */
@@ -1185,6 +1248,8 @@ print_insn_msp430 (bfd_vma addr, disassemble_info *info)
 		      if (strcmp (opcode->name, "bra") != 0)
 			sprintf (op2, "r%d", reg);
 		    }
+		  else
+		    return -1;
 		  break;
 
 		case 12: /* MOVA Rsrc, Rdst */
@@ -1206,15 +1271,21 @@ print_insn_msp430 (bfd_vma addr, disassemble_info *info)
 
 	  switch (opcode->insn_opnumb)
 	    {
+	      int ret;
+
 	    case 0:
 	      cmd_len += msp430_nooperands (opcode, addr, insn, comm1, &cycles);
 	      break;
 	    case 2:
-	      cmd_len +=
+	      ret =
 		msp430_doubleoperand (info, opcode, addr, insn, op1, op2,
 				      comm1, comm2,
 				      extension_word,
 				      &cycles);
+
+	      if (ret == -1)
+		return -1;
+	      cmd_len += ret;
 	      if (insn & BYTE_OPERATION)
 		{
 		  if (extension_word != 0 && ((extension_word & BYTE_OPERATION) == 0))
@@ -1235,10 +1306,14 @@ print_insn_msp430 (bfd_vma addr, disassemble_info *info)
 
 	      break;
 	    case 1:
-	      cmd_len +=
+	      ret =
 		msp430_singleoperand (info, opcode, addr, insn, op1, comm1,
 				      extension_word,
 				      &cycles);
+
+	      if (ret == -1)
+		return -1;
+	      cmd_len += ret;
 	      if (extension_word
 		  && (strcmp (opcode->name, "swpb") == 0
 		      || strcmp (opcode->name, "sxt") == 0))


  reply	other threads:[~2017-01-12  9:43 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 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 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
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 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 [this message]
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 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 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 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 4/6] Disassembly unit test: disassemble one instruction 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 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 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=20170112094256.GA31406@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