From: Aditya Kamath1 via Gdb-patches <gdb-patches@sourceware.org>
To: Ulrich Weigand <Ulrich.Weigand@de.ibm.com>,
"gdb-patches@sourceware.org" <gdb-patches@sourceware.org>
Cc: Sangamesh Mallayya <sangamesh.swamy@in.ibm.com>
Subject: Re: [PATCH] Fix for call feature having nine parameters or more in AIX
Date: Fri, 25 Aug 2023 16:36:34 +0000 [thread overview]
Message-ID: <CH2PR15MB354479A8B1E49EBC0ECC2DEAD6E3A@CH2PR15MB3544.namprd15.prod.outlook.com> (raw)
In-Reply-To: <c9807cd0375ebf70c831eb3295dcd110ddc0e7c3.camel@de.ibm.com>
[-- Attachment #1: Type: text/plain, Size: 3969 bytes --]
Hi Ulrich and GDB community members,
Thank you for the feedback. Please find attached the patch. See:- 0001-Fix-for-call-feature-having-9th-function-parameter-a.patch
>>+ write_memory (sp + 24 + (ii * wordsize),
>I think this needs to be 6 * wordsize instead of 24 here too.
This is done. Thanks.
>>+ if (wordsize == 8 &&
>+ (type->code () == TYPE_CODE_INT
>I'm not sure the "wordsize == 8" check is correct here. It's of course
>a question of how the 32-bit AIX ABI is defined, but for parameters in
>registers, we do the extension on 32-bit too. So it seems likely to me
>that we need to do it for parameters in memory as well.
This also done.
Hope all is good now. Kindly push the patch if there are not more changes. Let me know if any more.
Have a nice day ahead.
By the way, pasted the outputs below.
Thanks and regards,
Aditya.
32 bit output with patch:-
Reading symbols from /home/aditya/gdb_tests/nine_parameter_func...
(gdb) b main
Breakpoint 1 at 0x1000078c: file /home/aditya/gdb_tests/nine_parameter_func.c, line 27.
(gdb) r
Starting program: /home/aditya/gdb_tests/nine_parameter_func
Breakpoint 1, main () at /home/aditya/gdb_tests/nine_parameter_func.c:27
27 const float register f3 = 19.0;
(gdb) list
22 printf ("j = %d \n", j);
23 return (int)(d);
24 }
25 int main ()
26 {
27 const float register f3 = 19.0;
28 const int register i1 = 700;
29 printf("%f \n", f3 + i1);
30 b ();
31 a (1, 2, 3, 4, 5, 6, 7, 8, 9, 983, 19);
(gdb) call a (1, 2, 3, 4, 5, 6, 7, 8, 9, 983, 19)
812.000000
9th para = 9 , 10th para = 983
j = 9
$1 = 1041
(gdb) call a (1, 2, 3, 4, 5, 6, 7, 8, 9, 983, 25)
812.000000
9th para = 9 , 10th para = 983
j = 9
$2 = 1047
(gdb)
64 bit output with patch:-
Breakpoint 1, main () at /home/aditya/gdb_tests/nine_parameter_func.c:27
27 const float register f3 = 19.0;
(gdb) lsit
Undefined command: "lsit". Try "help".
(gdb) list
22 printf ("j = %d \n", j);
23 return (int)(d);
24 }
25 int main ()
26 {
27 const float register f3 = 19.0;
28 const int register i1 = 700;
29 printf("%f \n", f3 + i1);
30 b ();
31 a (1, 2, 3, 4, 5, 6, 7, 8, 9, 983, 19);
(gdb) call a (1, 2, 3, 4, 5, 6, 7, 8, 9, 983, 19)
812.000000
9th para = 9 , 10th para = 983
j = 9
$1 = 1041
(gdb) call a (1, 2, 3, 4, 5, 6, 7, 8, 9, 983, 25)
812.000000
9th para = 9 , 10th para = 983
j = 9
$2 = 1047
(gdb) call a (1, 2, 3, 4, 5, 6, 7, 8, 9, 983, 30)
812.000000
9th para = 9 , 10th para = 983
j = 9
$3 = 1052
(gdb)
From: Ulrich Weigand <Ulrich.Weigand@de.ibm.com>
Date: Friday, 25 August 2023 at 9:27 PM
To: gdb-patches@sourceware.org <gdb-patches@sourceware.org>, Aditya Kamath1 <Aditya.Kamath1@ibm.com>
Cc: Sangamesh Mallayya <sangamesh.swamy@in.ibm.com>
Subject: Re: [PATCH] Fix for call feature having nine parameters or more in AIX
Aditya Kamath1 <Aditya.Kamath1@ibm.com> wrote:
>Hope this looks good now. Kindly let me know. If not kindly push these changes.
Just a few comments remaining:
>+ space += ((len - argbytes + wordsize -1) & -wordsize);
Please use "- 1" instead of "-1" everywhere here.
>+ write_memory (sp + 24 + (ii * wordsize),
I think this needs to be 6 * wordsize instead of 24 here too.
>+ if (wordsize == 8 &&
>+ (type->code () == TYPE_CODE_INT
>+ || type->code () == TYPE_CODE_ENUM
>+ || type->code () == TYPE_CODE_BOOL
>+ || type->code () == TYPE_CODE_CHAR ))
>+ {
I'm not sure the "wordsize == 8" check is correct here. It's of course
a question of how the 32-bit AIX ABI is defined, but for parameters in
registers, we do the extension on 32-bit too. So it seems likely to me
that we need to do it for parameters in memory as well.
Bye,
Ulrich
[-- Attachment #2: 0001-Fix-for-call-feature-having-9th-function-parameter-a.patch --]
[-- Type: application/octet-stream, Size: 2806 bytes --]
From e590c888d0d4cb9309abf14c12f5617a6a5de2b2 Mon Sep 17 00:00:00 2001
From: Aditya Vidyadhar Kamath <Aditya.Kamath1@ibm.com>
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 829f55981ca..8c3a23788b3 100644
--- a/gdb/rs6000-aix-tdep.c
+++ b/gdb/rs6000-aix-tdep.c
@@ -649,7 +649,7 @@ rs6000_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
if (argbytes)
{
- space += ((len - argbytes + 3) & -4);
+ space += ((len - argbytes + wordsize -1) & -wordsize);
jj = argno + 1;
}
else
@@ -658,7 +658,7 @@ rs6000_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
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 @@ rs6000_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
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 @@ rs6000_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
++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.38.3
next prev parent reply other threads:[~2023-08-25 16:37 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-08-25 9:21 Aditya Kamath1 via Gdb-patches
2023-08-25 11:19 ` Ulrich Weigand via Gdb-patches
2023-08-25 13:35 ` Aditya Kamath1 via Gdb-patches
2023-08-25 14:13 ` Ulrich Weigand via Gdb-patches
2023-08-25 15:35 ` Aditya Kamath1 via Gdb-patches
2023-08-25 15:57 ` Ulrich Weigand via Gdb-patches
2023-08-25 16:36 ` Aditya Kamath1 via Gdb-patches [this message]
2023-08-25 16:49 ` Ulrich Weigand via Gdb-patches
2023-08-25 17:47 ` Aditya Kamath1 via Gdb-patches
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=CH2PR15MB354479A8B1E49EBC0ECC2DEAD6E3A@CH2PR15MB3544.namprd15.prod.outlook.com \
--to=gdb-patches@sourceware.org \
--cc=Aditya.Kamath1@ibm.com \
--cc=Ulrich.Weigand@de.ibm.com \
--cc=sangamesh.swamy@in.ibm.com \
/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