* [PATCH] Fix to step instruction due to P10 prefix instruction in AIX
@ 2023-09-26 7:01 Aditya Kamath1
2023-09-26 13:15 ` Ulrich Weigand
0 siblings, 1 reply; 3+ messages in thread
From: Aditya Kamath1 @ 2023-09-26 7:01 UTC (permalink / raw)
To: Ulrich Weigand, Aditya Kamath1 via Gdb-patches; +Cc: Sangamesh Mallayya
[-- Attachment #1.1: Type: text/plain, Size: 8651 bytes --]
Respected GDB community members,
Hi,
Please find attached a patch. {See: 0001-Fix-to-step-instruction-due-to-P10-prefix-instructio.patch}
This is a patch to fix the SIGILL instruction coming in AIX running on a power 10 machine.
Consider a program p10-test.c
cat ~/p10_test.c
#include <stdio.h>
int global_variable = 2;
unsigned long
add (unsigned long a)
{
printf ("%ld is the num \n", a + 0x12345U);
return a + 0x12345U;
}
int main(){
unsigned long local_variable = 1;
add (local_variable);
printf ("Simple print statement \n");
printf ("Hello Bengaluru \n");
return 0;
}
The disassembly equivalent of the a + 0x12345U has a paddi instruction. This instruction is 8 bytes as shown in the GDB output of the disassemble of add () in the above code.
Breakpoint 2, add (a=1) at /home/buildusr/p10_test.c:6
6 printf ("%ld is the num \n", a + 0x12345U);
(gdb) disassemble
Dump of assembler code for function add:
0x10000538 <+0>: mflr r0
0x1000053c <+4>: stw r0,8(r1)
0x10000540 <+8>: stw r31,-4(r1)
0x10000544 <+12>: stwu r1,-80(r1)
0x10000548 <+16>: mr r31,r1
0x1000054c <+20>: stw r3,104(r31)
=> 0x10000550 <+24>: lwz r9,104(r31)
0x10000554 <+28>: paddi r9,r9,74565
0x1000055c <+36>: mr r4,r9
0x10000560 <+40>: lwz r3,64(r2)
0x10000564 <+44>: bl 0x10000648 <printf>
0x10000568 <+48>: lwz r2,20(r1)
0x1000056c <+52>: lwz r9,104(r31)
0x10000570 <+56>: paddi r9,r9,74565
0x10000578 <+64>: mr r3,r9
0x1000057c <+68>: addi r1,r31,80
0x10000580 <+72>: lwz r0,8(r1)
Since during a stepi we are stepping 4 bytes and once we press stepi after we execute instruction at 0x10000554 we get
(gdb) si
0x10000554 6 printf ("%ld is the num \n", a + 0x12345U);
(gdb)
Program received signal SIGILL, Illegal instruction.
0x10000554 in add (a=1) at /home/buildusr/p10_test.c:6
6 printf ("%ld is the num \n", a + 0x12345U);
The reason being we stepped into an illegal instruction.
In this patch we use (insn & 0xfc000000) == 1 << 26 to check for the p10 instruction and then calculate the location at which stepi needs to be done.
The output after we apply this patch is.
In 32 bit mode:- stepi jumps 8 bytes when required.
Breakpoint 2, add (a=1) at /home/buildusr/p10_test.c:6
6 printf ("%ld is the num \n", a + 0x12345U);
(gdb) disassemble
Dump of assembler code for function add:
0x10000538 <+0>: mflr r0
0x1000053c <+4>: stw r0,8(r1)
0x10000540 <+8>: stw r31,-4(r1)
0x10000544 <+12>: stwu r1,-80(r1)
0x10000548 <+16>: mr r31,r1
0x1000054c <+20>: stw r3,104(r31)
=> 0x10000550 <+24>: lwz r9,104(r31)
0x10000554 <+28>: paddi r9,r9,74565
0x1000055c <+36>: mr r4,r9
0x10000560 <+40>: lwz r3,64(r2)
0x10000564 <+44>: bl 0x10000648 <printf>
0x10000568 <+48>: lwz r2,20(r1)
0x1000056c <+52>: lwz r9,104(r31)
0x10000570 <+56>: paddi r9,r9,74565
0x10000578 <+64>: mr r3,r9
0x1000057c <+68>: addi r1,r31,80
0x10000580 <+72>: lwz r0,8(r1)
0x10000584 <+76>: mtlr r0
0x10000588 <+80>: lwz r31,-4(r1)
0x1000058c <+84>: blr
0x10000590 <+88>: .long 0x0
0x10000594 <+92>: .long 0x2061
0x10000598 <+96>: lwz r0,257(r1)
0x1000059c <+100>: .long 0x0
0x100005a0 <+104>: .long 0x58
0x100005a4 <+108>: .long 0x36164
0x100005a8 <+112>: oris r31,r0,0
End of assembler dump.
(gdb) si
0x10000554 6 printf ("%ld is the num \n", a + 0x12345U);
(gdb)
0x1000055c 6 printf ("%ld is the num \n", a + 0x12345U);
(gdb)
0x10000560 6 printf ("%ld is the num \n", a + 0x12345U);
In 64 bit mode:- stepi jumps 8 bytes when required.
Breakpoint 1, add (a=1) at /home/buildusr/p10_test.c:6
6 printf ("%ld is the num \n", a + 0x12345U);
(gdb) disassemble
Dump of assembler code for function add:
0x00000001000006c0 <+0>: mflr r0
0x00000001000006c4 <+4>: std r0,16(r1)
0x00000001000006c8 <+8>: std r31,-8(r1)
0x00000001000006cc <+12>: stdu r1,-128(r1)
0x00000001000006d0 <+16>: mr r31,r1
0x00000001000006d4 <+20>: std r3,176(r31)
=> 0x00000001000006d8 <+24>: ld r9,176(r31)
0x00000001000006dc <+28>: paddi r9,r9,74565
0x00000001000006e4 <+36>: mr r4,r9
0x00000001000006e8 <+40>: ld r3,120(r2)
0x00000001000006ec <+44>: bl 0x1000007a4 <printf>
0x00000001000006f0 <+48>: ld r2,40(r1)
0x00000001000006f4 <+52>: ld r9,176(r31)
0x00000001000006f8 <+56>: paddi r9,r9,74565
0x0000000100000700 <+64>: mr r3,r9
0x0000000100000704 <+68>: addi r1,r31,128
0x0000000100000708 <+72>: ld r0,16(r1)
0x000000010000070c <+76>: mtlr r0
0x0000000100000710 <+80>: ld r31,-8(r1)
0x0000000100000714 <+84>: blr
0x0000000100000718 <+88>: .long 0x0
0x000000010000071c <+92>: .long 0x2061
0x0000000100000720 <+96>: lwz r0,257(r1)
0x0000000100000724 <+100>: .long 0x0
0x0000000100000728 <+104>: .long 0x58
0x000000010000072c <+108>: .long 0x36164
0x0000000100000730 <+112>: oris r31,r0,0
End of assembler dump.
(gdb) si
0x00000001000006dc 6 printf ("%ld is the num \n", a + 0x12345U);
(gdb)
0x00000001000006e4 6 printf ("%ld is the num \n", a + 0x12345U);
(gdb) q
Setting a breakpoint at that instruction
(gdb) b add
Breakpoint 1 at 0x100006d8: file /home/buildusr/p10_test.c, line 6.
(gdb) r
Starting program: /home/buildusr/p10_test_64
Breakpoint 1, add (a=1) at /home/buildusr/p10_test.c:6
6 printf ("%ld is the num \n", a + 0x12345U);
(gdb) disassemble
Dump of assembler code for function add:
0x00000001000006c0 <+0>: mflr r0
0x00000001000006c4 <+4>: std r0,16(r1)
0x00000001000006c8 <+8>: std r31,-8(r1)
0x00000001000006cc <+12>: stdu r1,-128(r1)
0x00000001000006d0 <+16>: mr r31,r1
0x00000001000006d4 <+20>: std r3,176(r31)
=> 0x00000001000006d8 <+24>: ld r9,176(r31)
0x00000001000006dc <+28>: paddi r9,r9,74565
0x00000001000006e4 <+36>: mr r4,r9
0x00000001000006e8 <+40>: ld r3,120(r2)
0x00000001000006ec <+44>: bl 0x1000007a4 <printf>
0x00000001000006f0 <+48>: ld r2,40(r1)
0x00000001000006f4 <+52>: ld r9,176(r31)
0x00000001000006f8 <+56>: paddi r9,r9,74565
0x0000000100000700 <+64>: mr r3,r9
0x0000000100000704 <+68>: addi r1,r31,128
0x0000000100000708 <+72>: ld r0,16(r1)
0x000000010000070c <+76>: mtlr r0
0x0000000100000710 <+80>: ld r31,-8(r1)
0x0000000100000714 <+84>: blr
0x0000000100000718 <+88>: .long 0x0
0x000000010000071c <+92>: .long 0x2061
0x0000000100000720 <+96>: lwz r0,257(r1)
0x0000000100000724 <+100>: .long 0x0
0x0000000100000728 <+104>: .long 0x58
0x000000010000072c <+108>: .long 0x36164
0x0000000100000730 <+112>: oris r31,r0,0
End of assembler dump.
(gdb) b *0x00000001000006dc
Breakpoint 2 at 0x1000006dc: file /home/buildusr/p10_test.c, line 6.
(gdb) b *0x00000001000006e4
Breakpoint 3 at 0x1000006e4: file /home/buildusr/p10_test.c, line 6.
(gdb) c
Continuing.
Breakpoint 2, 0x00000001000006dc in add (a=1) at /home/buildusr/p10_test.c:6
6 printf ("%ld is the num \n", a + 0x12345U);
(gdb) c
Continuing.
Breakpoint 3, 0x00000001000006e4 in add (a=1) at /home/buildusr/p10_test.c:6
6 printf ("%ld is the num \n", a + 0x12345U);
(gdb) c
Continuing.
74566 is the num
Simple print statement
Hello Bengaluru
[Inferior 1 (process 6685154) exited normally]
(gdb)
So, I would like your views and guidance on this. Though this patch fixes things in this example we might need to take care many other things which I might not be aware of since this involves step and breakpoint.
Kindly let me know what you all think and fix this issue for GDB and AIX.
Awaiting a reply,
Have a nice day ahead.
Thanks and regards,
Aditya.
[-- Attachment #2: 0001-Fix-to-step-instruction-due-to-P10-prefix-instructio.patch --]
[-- Type: application/octet-stream, Size: 1364 bytes --]
From 9e7a503ddd787c03848a6e931444d3901ca5ac07 Mon Sep 17 00:00:00 2001
From: Aditya Vidyadhar Kamath <Aditya.Kamath1@ibm.com>
Date: Tue, 26 Sep 2023 00:48:57 -0500
Subject: [PATCH] Fix to step instruction due to P10 prefix instruction.
In AIX, power 10 instructions like paddi occupy 8 bytes, while the other instructions
4 bytes of space. Due to this when we do a stepi on paddi instruction we get a SIGILL interrupt. Hence, we
need to check during stepi if we are able to step 8 bytes during this instruction execution and is the
breakpoint to this instruction set correctly in both 32- and 64-bit mode.
This patch is a fix to the same.
---
gdb/rs6000-aix-tdep.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/gdb/rs6000-aix-tdep.c b/gdb/rs6000-aix-tdep.c
index c5446db2c1e..b8772bd02bd 100644
--- a/gdb/rs6000-aix-tdep.c
+++ b/gdb/rs6000-aix-tdep.c
@@ -1025,7 +1025,11 @@ rs6000_software_single_step (struct regcache *regcache)
if (!next_pcs.empty ())
return next_pcs;
- breaks[0] = loc + PPC_INSN_SIZE;
+ /* Here 0xfc000000 is the opcode mask to detect a P10 prefix instruction. */
+ if ((insn & 0xfc000000) == 1 << 26)
+ breaks[0] = loc + 2 * PPC_INSN_SIZE;
+ else
+ breaks[0] = loc + PPC_INSN_SIZE;
opcode = insn >> 26;
breaks[1] = branch_dest (regcache, opcode, insn, loc, breaks[0]);
--
2.38.3
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] Fix to step instruction due to P10 prefix instruction in AIX
2023-09-26 7:01 [PATCH] Fix to step instruction due to P10 prefix instruction in AIX Aditya Kamath1
@ 2023-09-26 13:15 ` Ulrich Weigand
2023-09-26 13:35 ` Aditya Kamath1
0 siblings, 1 reply; 3+ messages in thread
From: Ulrich Weigand @ 2023-09-26 13:15 UTC (permalink / raw)
To: gdb-patches, Aditya Kamath1; +Cc: Sangamesh Mallayya
Aditya Kamath1 <Aditya.Kamath1@ibm.com> wrote:
>Please find attached a patch. {See: 0001-Fix-to-step-instruction-due-to-P10-prefix-instructio.patch}
>
>This is a patch to fix the SIGILL instruction coming in AIX running on a power 10 machine.
This is OK. I've applied the patch.
Thanks,
Ulrich
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] Fix to step instruction due to P10 prefix instruction in AIX
2023-09-26 13:15 ` Ulrich Weigand
@ 2023-09-26 13:35 ` Aditya Kamath1
0 siblings, 0 replies; 3+ messages in thread
From: Aditya Kamath1 @ 2023-09-26 13:35 UTC (permalink / raw)
To: Ulrich Weigand, gdb-patches; +Cc: Sangamesh Mallayya
[-- Attachment #1: Type: text/plain, Size: 659 bytes --]
Thank you :).
From: Ulrich Weigand <Ulrich.Weigand@de.ibm.com>
Date: Tuesday, 26 September 2023 at 6:45 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 to step instruction due to P10 prefix instruction in AIX
Aditya Kamath1 <Aditya.Kamath1@ibm.com> wrote:
>Please find attached a patch. {See: 0001-Fix-to-step-instruction-due-to-P10-prefix-instructio.patch}
>
>This is a patch to fix the SIGILL instruction coming in AIX running on a power 10 machine.
This is OK. I've applied the patch.
Thanks,
Ulrich
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2023-09-26 13:35 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-09-26 7:01 [PATCH] Fix to step instruction due to P10 prefix instruction in AIX Aditya Kamath1
2023-09-26 13:15 ` Ulrich Weigand
2023-09-26 13:35 ` Aditya Kamath1
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).