gdb/riscv: Fix assertion in inferior call code
authorAndrew Burgess <andrew.burgess@embecosm.com>
Sun, 8 Apr 2018 10:08:32 +0000 (11:08 +0100)
committerAndrew Burgess <andrew.burgess@embecosm.com>
Tue, 10 Jul 2018 11:46:56 +0000 (12:46 +0100)
An assertion when setting up arguments for an inferior call checks the
size of the argument against xlen.  However, if xlen and flen are
different sizes, and the argument is being placed into a floating
pointer register then we should be comparing against flen not xlen.

This issue shows up as an assertion failure when running on an rv32g
target with a binary compiled using the rv32f abi and making an
inferior call involving large floating point arguments, for example
the test gdb.base/infcall-nested-structs.exp.

gdb/ChangeLog:

* riscv-tdep.c (riscv_is_fp_regno_p): New function.
(riscv_register_reggroup_p): Use new function, remove unneeded
parenthesis.
(riscv_push_dummy_call): Extend assert to compare against xlen or
flen based on register type.

gdb/ChangeLog
gdb/riscv-tdep.c

index bae1d91987738a07fd434724f30a459172e5dfd3..fb0612c42c6cc43aa3f588325a777ed6ec22da26 100644 (file)
@@ -1,3 +1,11 @@
+2018-07-10  Andrew Burgess  <andrew.burgess@embecosm.com>
+
+       * riscv-tdep.c (riscv_is_fp_regno_p): New function.
+       (riscv_register_reggroup_p): Use new function, remove unneeded
+       parenthesis.
+       (riscv_push_dummy_call): Extend assert to compare against xlen or
+       flen based on register type.
+
 2018-07-10  Andrew Burgess  <andrew.burgess@embecosm.com>
 
        * riscv-tdep.c (riscv_print_arg_location): Use TYPE_SAFE_NAME.
index e2be993eaf0e4f77e52d1e13c27ff8c2dfa316d0..25a8fda29c4aff4d9a05c8f675d1bb9652189b15 100644 (file)
@@ -413,6 +413,15 @@ riscv_has_fp_abi (struct gdbarch *gdbarch)
   return (gdbarch_tdep (gdbarch)->abi.fields.float_abi != 0);
 }
 
+/* Return true if REGNO is a floating pointer register.  */
+
+static bool
+riscv_is_fp_regno_p (int regno)
+{
+  return (regno >= RISCV_FIRST_FP_REGNUM
+         && regno <= RISCV_LAST_FP_REGNUM);
+}
+
 /* Implement the breakpoint_kind_from_pc gdbarch method.  */
 
 static int
@@ -787,10 +796,10 @@ riscv_register_reggroup_p (struct gdbarch  *gdbarch, int regnum,
       return 0;
     }
   else if (reggroup == float_reggroup)
-    return ((regnum >= RISCV_FIRST_FP_REGNUM && regnum <= RISCV_LAST_FP_REGNUM)
-           || (regnum == RISCV_CSR_FCSR_REGNUM
-               || regnum == RISCV_CSR_FFLAGS_REGNUM
-               || regnum == RISCV_CSR_FRM_REGNUM));
+    return (riscv_is_fp_regno_p (regnum)
+           || regnum == RISCV_CSR_FCSR_REGNUM
+           || regnum == RISCV_CSR_FFLAGS_REGNUM
+           || regnum == RISCV_CSR_FRM_REGNUM);
   else if (reggroup == general_reggroup)
     return regnum < RISCV_FIRST_FP_REGNUM;
   else if (reggroup == restore_reggroup || reggroup == save_reggroup)
@@ -2154,7 +2163,9 @@ riscv_push_dummy_call (struct gdbarch *gdbarch,
              {
                gdb_byte tmp [sizeof (ULONGEST)];
 
-               gdb_assert (second_arg_length <= call_info.xlen);
+               gdb_assert ((riscv_is_fp_regno_p (info->argloc[1].loc_data.regno)
+                            && second_arg_length <= call_info.flen)
+                           || second_arg_length <= call_info.xlen);
                memset (tmp, 0, sizeof (tmp));
                memcpy (tmp, second_arg_data, second_arg_length);
                regcache->cooked_write (info->argloc[1].loc_data.regno, tmp);