[9/11] Add MN10300_MAX_REGISTER_SIZE (2)

Message ID 8A16DE9D-BE32-4CEF-9144-8D78F3A803B4@arm.com
State New, archived
Headers

Commit Message

Alan Hayward May 4, 2017, 3:17 p.m. UTC
  > On 4 Apr 2017, at 11:15, Alan Hayward <Alan.Hayward@arm.com> wrote:
> 
> Max size set to 32bits, which I determined using mn10300_register_type()
> 
> Tested on a --enable-targets=all build using make check with board files
> unix and native-gdbserver.
> 
> I do not have a MN10300 machine to test on.
> 
> Ok to commit?
> 
> Alan.

Split this into two patches.
This patch adds MN10300_MAX_REGISTER_SIZE.
Added some asserts to check the new define is big enough.

For mn10300_push_dummy_call I could have created a MN10300_PC_REGISTER_SIZE, but
it would only be used the once. Also, I could use sizeof(int) instead of adding
any defines, but it is probably clearer using MN10300_MAX_REGISTER_SIZE.

Tested on a --enable-targets=all build using make check with board files
unix and native-gdbserver.

I do not have a MN10300 machine to test on.

Ok to commit?

Alan.

2017-05-04  Alan Hayward  <alan.hayward@arm.com>

	* mn10300-tdep.c (MN10300_MAX_REGISTER_SIZE): Add.
        (mn10300_extract_return_value): Use MN10300_MAX_REGISTER_SIZE.
	(mn10300_push_dummy_call): Likewise.
  

Patch

diff --git a/gdb/mn10300-tdep.c b/gdb/mn10300-tdep.c
index 0f5e10fccc54efc9275511bb06e9b27636d0565f..2072e736270cc70f36f1305eb426e9ecb3def7fa 100644
--- a/gdb/mn10300-tdep.c
+++ b/gdb/mn10300-tdep.c
@@ -40,6 +40,9 @@ 
 /* The am33-2 has 64 registers.  */
 #define MN10300_MAX_NUM_REGS 64

+/* Big enough to hold the size of the largest register in bytes.  */
+#define MN10300_MAX_REGISTER_SIZE      4
+
 /* This structure holds the results of a prologue analysis.  */
 struct mn10300_prologue
 {
@@ -196,7 +199,7 @@  static void
 mn10300_extract_return_value (struct gdbarch *gdbarch, struct type *type,
 			      struct regcache *regcache, void *valbuf)
 {
-  gdb_byte buf[MAX_REGISTER_SIZE];
+  gdb_byte buf[MN10300_MAX_REGISTER_SIZE];
   int len = TYPE_LENGTH (type);
   int reg, regsz;

@@ -206,6 +209,7 @@  mn10300_extract_return_value (struct gdbarch *gdbarch, struct type *type,
     reg = 0;

   regsz = register_size (gdbarch, reg);
+  gdb_assert (regsz <= MN10300_MAX_REGISTER_SIZE);
   if (len <= regsz)
     {
       regcache_raw_read (regcache, reg, buf);
@@ -1224,7 +1228,9 @@  mn10300_push_dummy_call (struct gdbarch *gdbarch,
   int stack_offset = 0;
   int argnum;
   const gdb_byte *val;
-  gdb_byte valbuf[MAX_REGISTER_SIZE];
+  gdb_byte valbuf[MN10300_MAX_REGISTER_SIZE];
+
+  gdb_assert (push_size <= MN10300_MAX_REGISTER_SIZE);

   /* This should be a nop, but align the stack just in case something
      went wrong.  Stacks are four byte aligned on the mn10300.  */