From 99dc97091be000ad4d724d677b361e7af7d35db8 Mon Sep 17 00:00:00 2001 From: Aditya Vidyadhar Kamath Date: Fri, 25 Aug 2023 11:30:02 -0500 Subject: [PATCH] Fix for call feature having 9th function parameter and beyond corrupt values. In AIX the first eight function parameters are stored from R3 to R10. If there are more than eight parameters in a function then we store the 9th parameter onwards in the stack. While doing so, in 64 bit mode the words were not zero extended and was coming like 32 bit mode. This patch is a fix to the same. --- gdb/rs6000-aix-tdep.c | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/gdb/rs6000-aix-tdep.c b/gdb/rs6000-aix-tdep.c index 1894f60d014..c5446db2c1e 100644 --- a/gdb/rs6000-aix-tdep.c +++ b/gdb/rs6000-aix-tdep.c @@ -649,7 +649,7 @@ ran_out_of_registers_for_arguments: if (argbytes) { - space += ((len - argbytes + 3) & -4); + space += ((len - argbytes + wordsize -1) & -wordsize); jj = argno + 1; } else @@ -658,7 +658,7 @@ ran_out_of_registers_for_arguments: for (; jj < nargs; ++jj) { struct value *val = args[jj]; - space += ((val->type ()->length ()) + 3) & -4; + space += ((val->type ()->length () + wordsize -1) & -wordsize); } /* Add location required for the rest of the parameters. */ @@ -679,11 +679,11 @@ ran_out_of_registers_for_arguments: if (argbytes) { - write_memory (sp + 24 + (ii * 4), + write_memory (sp + 6 * wordsize + (ii * wordsize), arg->contents ().data () + argbytes, len - argbytes); ++argno; - ii += ((len - argbytes + 3) & -4) / 4; + ii += ((len - argbytes + wordsize - 1) & -wordsize) / wordsize; } /* Push the rest of the arguments into stack. */ @@ -707,8 +707,20 @@ ran_out_of_registers_for_arguments: ++f_argno; } - write_memory (sp + 24 + (ii * 4), arg->contents ().data (), len); - ii += ((len + 3) & -4) / 4; + if (type->code () == TYPE_CODE_INT + || type->code () == TYPE_CODE_ENUM + || type->code () == TYPE_CODE_BOOL + || type->code () == TYPE_CODE_CHAR ) + { + gdb_byte word[PPC_MAX_REGISTER_SIZE]; + memset (word, 0, PPC_MAX_REGISTER_SIZE); + store_unsigned_integer (word, tdep->wordsize, byte_order, + unpack_long (type, arg->contents ().data ())); + write_memory (sp + 6 * wordsize + (ii * wordsize), word, PPC_MAX_REGISTER_SIZE); + } + else + write_memory (sp + 6 * wordsize + (ii * wordsize), arg->contents ().data (), len); + ii += ((len + wordsize -1) & -wordsize) / wordsize; } } -- 2.30.2