public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Aditya Kamath1 <Aditya.Kamath1@ibm.com>
To: Ulrich Weigand <Ulrich.Weigand@de.ibm.com>,
	"gdb-patches@sourceware.org" <gdb-patches@sourceware.org>,
	"simon.marchi@efficios.com" <simon.marchi@efficios.com>
Cc: Sangamesh Mallayya <sangamesh.swamy@in.ibm.com>,
	Sanket Rathi <sanrathi@in.ibm.com>
Subject: Re: [PATCH] Fix call functions command bug in 64-bit programs for AIX
Date: Wed, 16 Nov 2022 18:07:44 +0000	[thread overview]
Message-ID: <BY5PR15MB3540464A747BB9A3BC13C81DD6079@BY5PR15MB3540.namprd15.prod.outlook.com> (raw)
In-Reply-To: <d561747939cec27270b38f5b029498587ea4898e.camel@de.ibm.com>


[-- Attachment #1.1: Type: text/plain, Size: 7402 bytes --]

Hi Ulrich,

Please find attached the new patch. See 0001-Fix-call-functions-command-bug-in-64-bit-programs.patch.

>It might not really be necessary to handle pointer and reference
>types if those are always guaranteed to be word sized.  But I
>think enum, bool, and char types should be handled.

You were right. Thank you for pointing out. I have attached the outputs below. It works fine now.

>Also, it would probably be preferable to use reg_size instead
>of tdep->wordsize to be consistent.
This is changed..

>Finally, there are still white space issues (use tabs instead
>of 8 spaces, if there's just a single statement inside an if
>it is indented only 2 spaces, not 4).

I took care of it. Kindly check..

If all is fine, kindly push this patch to the community. Let me know in case I missed something otherwise.

Have a nice day ahead.

Thanks and regards,
Aditya.

--------------------------------
PROGRAM


#include "stdio.h"

#include <stdbool.h>

enum week {Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday} w;

int num2print(long num, float num2, int num3, double num4, enum week w, char c1, bool b1, char *mystring) {

  printf("R%ld\n",num);

  printf("R%f\n",num2);

  printf("R%d\n",num3);

  printf("R%lf\n",num4);

  printf ("Day number passed is %d\n",w);

  printf ("R%c\n", c1);

  printf ("R%d\n", b1);

  printf ("FIFA winner is %s \n", mystring);

  return num;

}


int main(int argc, char** argv)


{

  enum week today = Wednesday;

  char fifaWinner[] = "Germany";

  bool x = false;

  printf("Hi Bangalore %x\n",num2print(27, 16, 13, 9.9, today, 'a', x, fifaWinner));

  return 0;

}

--------------------------------------
32 bit output before patch..


Reading symbols from /home/XYZ/gdb_tests...

(gdb) b main

Breakpoint 1 at 0x1000067c: file /home/XYZ/gdb_tests.c, line 19.

(gdb) r

Starting program: /home/XYZ/gdb_tests


Breakpoint 1, main (argc=1, argv=0x2ff22bf0)

    at /home/aditya/XYZ.c:19

19        enum week today = Wednesday;

(gdb) n

20        char fifaWinner[] = "Germany";

(gdb)

21        bool x = false;

(gdb) call num2print

$1 = {int (long, float, int, double, enum week, char, _Bool,

    char *)} 0x10000518 <num2print>

(gdb) call num2print (2, 3.4, 5, 6.7, Wednesday, 'c', 1, fifaWinner)

R2

R3.400000

R5

R6.700000

Day number passed is 3

Rc

R1

FIFA winner is Germany

warning: (Internal error: pc 0x10000290 in read in psymtab, but not in symtab.)


$2 = 2

-----------------------------------------------------------

64 bit output before patch


Reading symbols from /home/XYZ/gdb_tests...

(gdb) b main

Breakpoint 1 at 0x10000818: file /home/XYZ/gdb_tests.c, line 19.

(gdb) r

Starting program: /home/XYZ/gdb_tests

BFD: /usr/lib/libc.a(/usr/lib/libc.a(shr_64.o)): wrong auxtype 0xff for storage class 0x2

BFD: /usr/lib/libc.a(/usr/lib/libc.a(shr_64.o)): wrong auxtype 0xff for storage class 0x6b


Breakpoint 1, main (argc=1, argv=0xffffffffffffad0)

    at /home/XYZ/gdb_tests.c:19

19        enum week today = Wednesday;

(gdb) n

20        char fifaWinner[] = "Germany";

(gdb)

21        bool x = false;

(gdb) call num2print (2, 3.4, 5, 6.7, Wednesday, 'c', 1, fifaWinner)

R2

R3.400000

R0

R6.700000

Day number passed is 0

R

R0

FIFA winner is Germany

$1 = 2

(gdb)

-------------------------------------------------------------------------

32-bit output after patch


Reading symbols from /home/XYZ/gdb_tests...

(gdb) b main

Breakpoint 1 at 0x1000067c: file /home/XYZ/gdb_tests.c, line 19.

(gdb) r

Starting program: /home/XYZ/gdb_tests


Breakpoint 1, main (argc=1, argv=0x2ff22bf0)

    at /home/XYZ/gdb_tests.c:19

19        enum week today = Wednesday;

(gdb) n

20        char fifaWinner[] = "Germany";

(gdb)

21        bool x = false;

(gdb) call num2print (2, 3.4, 5, 6.7, Wednesday, 'c', 1, fifaWinner)

R2

R3.400000

R5

R6.700000

Day number passed is 3

Rc

R1

FIFA winner is Germany

$1 = 2

(gdb)


-----------------------------------------------------


64-bit output after patch


Reading symbols from /home/XYZ/gdb_tests...

(gdb) b main

Breakpoint 1 at 0x10000818: file /home/XYZ/gdb_tests.c, line 19.

(gdb) r

Starting program: /home/XYZ/gdb_tests

BFD: /usr/lib/libc.a(/usr/lib/libc.a(shr_64.o)): wrong auxtype 0xff for storage class 0x2

BFD: /usr/lib/libc.a(/usr/lib/libc.a(shr_64.o)): wrong auxtype 0xff for storage class 0x6b


Breakpoint 1, main (argc=1, argv=0xffffffffffffad0)

    at /home/XYZ/gdb_tests.c:19

19        enum week today = Wednesday;

(gdb) n

20        char fifaWinner[] = "Germany";

(gdb) n

21        bool x = false;

(gdb) call num2print (2, 3.4, 5, 6.7, Wednesday, 'c', 1, fifaWinner)

R2

R3.400000

R5

R6.700000

Day number passed is 3

Rc

R1

FIFA winner is Germany

$1 = 2

(gdb) call num2print (2, 3.4, 5, 6.7, Wednesday, 'e', 0, fifaWinner)

R2

R3.400000

R5

R6.700000

Day number passed is 3

Re

R0

FIFA winner is Germany

warning: (Internal error: pc 0x100000480 in read in psymtab, but not in symtab.)


$2 = 2

(gdb)






________________________________
From: Ulrich Weigand <Ulrich.Weigand@de.ibm.com>
Sent: 16 November 2022 20:45
To: gdb-patches@sourceware.org <gdb-patches@sourceware.org>; Aditya Kamath1 <Aditya.Kamath1@ibm.com>; simon.marchi@efficios.com <simon.marchi@efficios.com>
Cc: Sangamesh Mallayya <sangamesh.swamy@in.ibm.com>; Sanket Rathi <sanrathi@in.ibm.com>
Subject: Re: [PATCH] Fix call functions command bug in 64-bit programs for AIX

Aditya Kamath1 <Aditya.Kamath1@ibm.com> wrote:

>In AIX for 64-bit programs, we need to zero extend variables of integer data type.

This looks much more reasonable, thanks!

Just a couple of remaining questions:

>          memset (word, 0, reg_size);
>-         memcpy (word, value_contents (arg).data (), len);
>+          if (type->code () == TYPE_CODE_INT)
>+                /* Sign or zero extend the "int" into a "word".  */
>+                store_unsigned_integer (word, tdep->wordsize, byte_order,
>+                                        unpack_long (type, value_contents (arg).data ()));
>+          else
>+               memcpy (word, value_contents (arg).data (), len);
>          regcache->cooked_write (tdep->ppc_gp0_regnum + 3 +ii, word);

Is it correct to handle *only* TYPE_CODE_INT here?

The corresponding code in the Linux ABI code has:
  else if ((type->code () == TYPE_CODE_INT
            || type->code () == TYPE_CODE_ENUM
            || type->code () == TYPE_CODE_BOOL
            || type->code () == TYPE_CODE_CHAR
            || type->code () == TYPE_CODE_PTR
            || TYPE_IS_REFERENCE (type))

It might not really be necessary to handle pointer and reference
types if those are always guaranteed to be word sized.  But I
think enum, bool, and char types should be handled.

Also, it would probably be preferable to use reg_size instead
of tdep->wordsize to be consistent.

Finally, there are still white space issues (use tabs instead
of 8 spaces, if there's just a single statement inside an if
it is indented only 2 spaces, not 4).

Bye,
Ulrich


[-- Attachment #2: 0001-Fix-call-functions-command-bug-in-64-bit-programs.patch --]
[-- Type: application/octet-stream, Size: 1483 bytes --]

From d9a8e43d93db669b3f6324549edc7620e6422951 Mon Sep 17 00:00:00 2001
From: Aditya Vidyadhar Kamath <Aditya.Kamath1@ibm.com>
Date: Wed, 16 Nov 2022 12:02:38 -0600
Subject: [PATCH] Fix call functions command bug in 64 bits programs for AIX

In AIX for 64 bit programs we need to zero extend variables of integer or enum or char data type.

Otherwise a zero will get dumped in the register as we memset our word to 0 and we copy non zero extended contents to the cache

This patch is a fix for the same.
---
 gdb/rs6000-aix-tdep.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/gdb/rs6000-aix-tdep.c b/gdb/rs6000-aix-tdep.c
index d47974b51d1..5e670721d29 100644
--- a/gdb/rs6000-aix-tdep.c
+++ b/gdb/rs6000-aix-tdep.c
@@ -400,7 +400,15 @@ rs6000_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
 	  gdb_byte word[PPC_MAX_REGISTER_SIZE];
 
 	  memset (word, 0, reg_size);
-	  memcpy (word, value_contents (arg).data (), len);
+	  if (type->code () == TYPE_CODE_INT
+	     || type->code () == TYPE_CODE_ENUM
+	     || type->code () == TYPE_CODE_BOOL
+	     || type->code () == TYPE_CODE_CHAR)
+	    /* Sign or zero extend the "int" into a "word".  */
+	    store_unsigned_integer (word, reg_size, byte_order,
+				    unpack_long (type, value_contents (arg).data ()));
+          else
+	    memcpy (word, value_contents (arg).data (), len);
 	  regcache->cooked_write (tdep->ppc_gp0_regnum + 3 +ii, word);
 	}
       ++argno;
-- 
2.31.1


  reply	other threads:[~2022-11-16 18:07 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-07 11:00 Aditya Kamath1
2022-11-08 13:30 ` Ulrich Weigand
2022-11-11 17:53   ` Aditya Kamath1
2022-11-14 15:54     ` Ulrich Weigand
2022-11-14 17:32       ` Aditya Kamath1
2022-11-14 18:19         ` Ulrich Weigand
2022-11-14 18:28           ` Aditya Kamath1
2022-11-14 18:43             ` Ulrich Weigand
2022-11-14 18:52               ` Aditya Kamath1
2022-11-14 19:10                 ` Ulrich Weigand
2022-11-16 11:27                   ` Aditya Kamath1
2022-11-16 15:15                     ` Ulrich Weigand
2022-11-16 18:07                       ` Aditya Kamath1 [this message]
2022-11-16 18:30                         ` Tom Tromey
2022-11-17 12:54                         ` Ulrich Weigand
2022-11-24 17:56                           ` Aditya Kamath1
2022-11-24 18:15                             ` Tom Tromey
2023-04-14  7:38                               ` [PATCH] Fix call functions command bug in 64-bit programs for AIX and PC read in psymtab-symtab warning Aditya Kamath1
2023-04-14 14:45                                 ` Tom Tromey
2023-04-17 13:08                                   ` Aditya Kamath1
2023-04-17 13:16                                     ` Aditya Kamath1
2023-04-18 10:12                                       ` Ulrich Weigand
2023-04-21 13:00                                         ` Aditya Kamath1
2023-04-24 15:44                                           ` Ulrich Weigand
2023-04-27 10:13                                             ` Aditya Kamath1
2023-04-27 12:23                                               ` Ulrich Weigand
2023-04-27 10:14                                   ` Aditya Kamath1

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=BY5PR15MB3540464A747BB9A3BC13C81DD6079@BY5PR15MB3540.namprd15.prod.outlook.com \
    --to=aditya.kamath1@ibm.com \
    --cc=Ulrich.Weigand@de.ibm.com \
    --cc=gdb-patches@sourceware.org \
    --cc=sangamesh.swamy@in.ibm.com \
    --cc=sanrathi@in.ibm.com \
    --cc=simon.marchi@efficios.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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).