[5/9] Restrict m68k_convert_register_p

Message ID 1492068373-4916-6-git-send-email-yao.qi@linaro.org
State New, archived
Headers

Commit Message

Yao Qi April 13, 2017, 7:26 a.m. UTC
  We need to convert register if the type is float.  Suppose we get a value
from float point register, but its type is integer, we don't have to convert.
This case may not exist in real code, but exist in my unit test case.

warning: Cannot convert floating-point register value to non-floating-point type.
Self test failed: arch m68k: self-test failed at gdb/git/gdb/findvar.c:1072

              ok = gdbarch_register_to_value (gdbarch, frame, regnum, type,
                                              buf.data (), &optim, &unavail);

1072:         SELF_CHECK (ok);

gdb:

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

	* m68k-tdep.c (m68k_convert_register_p): Check type's code is
	TYPE_CODE_FLT or not.
---
 gdb/m68k-tdep.c | 13 ++-----------
 1 file changed, 2 insertions(+), 11 deletions(-)
  

Comments

Simon Marchi April 15, 2017, 6 p.m. UTC | #1
On 2017-04-13 03:26, Yao Qi wrote:
> @@ -203,17 +205,6 @@ m68k_register_to_value (struct frame_info *frame,
> int regnum,
>    struct type *fpreg_type = register_type (get_frame_arch (frame),
>  					   M68K_FP0_REGNUM);
> 
> -  /* We only support floating-point values.  */
> -  if (TYPE_CODE (type) != TYPE_CODE_FLT)
> -    {
> -      warning (_("Cannot convert floating-point register value "
> -	       "to non-floating-point type."));
> -      *optimizedp = *unavailablep = 0;
> -      return 0;
> -    }

Perhaps that can be replaced with a gdb_assert (TYPE_CODE (type) == 
TYPE_CODE_FLT) ?  Or maybe it would be more appropriate to put such 
asserts on convert_typed_floating ?

Likewise in the following patches, the if (TYPE_LENGTH (valtype) == 4) 
check in alpha could be replaced with gdb_assert (TYPE_LENGTH (valtype) 
== 4).

Simon
  

Patch

diff --git a/gdb/m68k-tdep.c b/gdb/m68k-tdep.c
index 7c3bf4c..1486841 100644
--- a/gdb/m68k-tdep.c
+++ b/gdb/m68k-tdep.c
@@ -188,6 +188,8 @@  m68k_convert_register_p (struct gdbarch *gdbarch,
   if (!gdbarch_tdep (gdbarch)->fpregs_present)
     return 0;
   return (regnum >= M68K_FP0_REGNUM && regnum <= M68K_FP0_REGNUM + 7
+	  /* We only support floating-point values.  */
+	  && TYPE_CODE (type) == TYPE_CODE_FLT
 	  && type != register_type (gdbarch, M68K_FP0_REGNUM));
 }
 
@@ -203,17 +205,6 @@  m68k_register_to_value (struct frame_info *frame, int regnum,
   struct type *fpreg_type = register_type (get_frame_arch (frame),
 					   M68K_FP0_REGNUM);
 
-  /* We only support floating-point values.  */
-  if (TYPE_CODE (type) != TYPE_CODE_FLT)
-    {
-      warning (_("Cannot convert floating-point register value "
-	       "to non-floating-point type."));
-      *optimizedp = *unavailablep = 0;
-      return 0;
-    }
-
-  /* Convert to TYPE.  */
-
   /* Convert to TYPE.  */
   if (!get_frame_register_bytes (frame, regnum, 0, TYPE_LENGTH (type),
 				 from, optimizedp, unavailablep))