aboutsummaryrefslogtreecommitdiff
path: root/gdb
diff options
context:
space:
mode:
authorCarl Love <cel@us.ibm.com>2022-05-06 17:45:58 +0000
committerCarl Love <cel@us.ibm.com>2022-05-06 17:45:58 +0000
commitdd9cd55e990bcc9f8448cac38d242d53974b3604 (patch)
tree893591892ca3b14891ab94b8295cb0e29fb8a053 /gdb
parent0ee8858e7aeca5ba5f702204daad2ddd290ef229 (diff)
downloadgdb-dd9cd55e990bcc9f8448cac38d242d53974b3604.zip
gdb-dd9cd55e990bcc9f8448cac38d242d53974b3604.tar.gz
gdb-dd9cd55e990bcc9f8448cac38d242d53974b3604.tar.bz2
PowerPC: bp-permanent.exp, kill-after-signal fix
The break point after the stepi on Intel is the entry point of the user signal handler function test_signal_handler. The code at the break point looks like: 0x<hex address> <test_signal_handler>: endbr64 On PowerPC with a Linux 5.9 kernel or latter, the address where gdb stops after the stepi is in the vdso code inserted by the kernel. The code at the breakpoint looks like: 0x<hex address> <__kernel_start_sigtramp_rt64>: bctrl This is different from other architectures. As discussed below, recent kernel changes involving the vdso for PowerPC have been made changes to the signal handler code flow. PowerPC is now stopping in function __kernel_start_sigtramp_rt64. PowerPC now requires an additional stepi to reach the user signal handler unlike other architectures. The bp-permanent.exp and kill-after-signal tests run fine on PowerPC with an kernel that is older than Linux 5.9. The PowerPC 64 signal handler was updated by the Linux kernel 5.9-rc1: commit id: 0138ba5783ae0dcc799ad401a1e8ac8333790df9 powerpc/64/signal: Balance return predictor stack in signal trampoline An additional change to the PowerPC 64 signal handler was made in Linux kernel version 5.11-rc7 : commit id: 24321ac668e452a4942598533d267805f291fdc9 powerpc/64/signal: Fix regression in __kernel_sigtramp_rt64() semantics The first kernel change, puts code into the user space signal handler (in the vdso) as a performance optimization to prevent the call/return stack from getting out of balance. The patch ensures that the entire user/kernel/vdso cycle is balanced with the addition of the "brctl" instruction. The second patch, fixes the semantics of __kernel_sigtramp_rt64(). A new symbol is introduced to serve as the jump target from the kernel to the trampoline which now consists of two parts. The above changes for PowerPC signal handler, causes gdb to stop in the kernel code not the user signal handler as expected. The kernel dispatches to the vdso code which in turn calls into the signal handler. PowerPC is special in that the kernel is using a vdso instruction (bctrl) to enter the signal handler. I do not have access to a system with the first patch but not the second. I did test on Power 9 with the Linux 5.15.0-27-generic kernel. Both tests fail on this Power 9 system. The two tests also fail on Power 10 with the Linux 5.14.0-70.9.1.el9_0.ppc64le kernel. The following patch fixes the issue by checking if gdb stopped at "signal handler called". If gdb stopped there, the tests verifies gdb is in the kernel function __kernel_start_sigtramp_rt64 then does an additional stepi to reach the user signal handler. With the patch below, the tests run without errors on both the Power 9 and Power 10 systems with out any failures.
Diffstat (limited to 'gdb')
-rw-r--r--gdb/testsuite/gdb.base/bp-permanent.exp25
-rw-r--r--gdb/testsuite/gdb.base/kill-after-signal.exp33
2 files changed, 57 insertions, 1 deletions
diff --git a/gdb/testsuite/gdb.base/bp-permanent.exp b/gdb/testsuite/gdb.base/bp-permanent.exp
index 8be46e9..21b0bc7 100644
--- a/gdb/testsuite/gdb.base/bp-permanent.exp
+++ b/gdb/testsuite/gdb.base/bp-permanent.exp
@@ -260,6 +260,31 @@ proc test {always_inserted sw_watchpoint} {
-re "Program received signal SIGTRAP.*$gdb_prompt $" {
fail $test
}
+ -re ".*signal handler called.*$gdb_prompt $" {
+ # PowerPC Linux kernel patchs:
+ # commit: 0138ba5783ae0dcc799ad401a1e8ac8333790df9
+ # powerpc/64/signal: Balance return predictor
+ # stack in signal trampoline.
+ #
+ # The kernel places an additional brctl instruction
+ # in the vdso to call the user hadler.
+ #
+ # commit 24321ac668e452a4942598533d267805f291fdc9
+ # powerpc/64/signal: Fix regression in
+ # __kernel_sigtramp_rt64() semantics
+ #
+ # Updates the semantics of __kernel_sigtramp_rt64().
+ # It adds a new symbol to serve as a jump target from
+ # the kernel to the trampoline.
+ #
+ # The net result of these changes is that gdb stops
+ # at __kernel_start_sigtramp_rt64. Need to do one
+ # more stepi to reach the expected location in the user
+ # signal handler.
+ gdb_test "p \$pc" ".*__kernel_start_sigtramp_rt64.*" \
+ "in kernel code"
+ gdb_test "stepi" "handler .*" $test
+ }
-re "handler .*$gdb_prompt $" {
pass $test
}
diff --git a/gdb/testsuite/gdb.base/kill-after-signal.exp b/gdb/testsuite/gdb.base/kill-after-signal.exp
index 09f5cbc..fcbec9a 100644
--- a/gdb/testsuite/gdb.base/kill-after-signal.exp
+++ b/gdb/testsuite/gdb.base/kill-after-signal.exp
@@ -36,7 +36,38 @@ if ![runto_main] {
}
gdb_test "continue" "Program received signal SIGUSR1, .*"
-gdb_test "stepi" "\r\nhandler .*"
+
+set test "handler"
+gdb_test_multiple "stepi" $test {
+ -re "\r\nhandler .*" {
+ pass $test
+ }
+ -re ".*signal handler called.*$gdb_prompt $" {
+ # PowerPC Linux kernel patchs:
+ # commit: 0138ba5783ae0dcc799ad401a1e8ac8333790df9
+ # powerpc/64/signal: Balance return predictor
+ # stack in signal trampoline.
+ #
+ # The kernel places an additional brctl instruction
+ # in the vdso to call the user hadler.
+ #
+ # commit 24321ac668e452a4942598533d267805f291fdc9
+ # powerpc/64/signal: Fix regression in
+ # __kernel_sigtramp_rt64() semantics
+ #
+ # Updates the semantics of __kernel_sigtramp_rt64().
+ # It adds a new symbol to serve as a jump target from
+ # the kernel to the trampoline.
+ #
+ # The net result of these changes is that gdb stops
+ # at __kernel_start_sigtramp_rt64. Need to do one
+ # more stepi to reach the expected location in the user
+ # signal handler.
+ gdb_test "p \$pc" ".*__kernel_start_sigtramp_rt64.*" "in kernel code"
+ gdb_test "stepi" "\r\nhandler .*" $test
+ }
+}
+
gdb_test_multiple "kill" "kill" {
-re "Kill the program being debugged\\? \\(y or n\\) $" {
gdb_test "y" "\\\[Inferior $decimal \\(.*\\) killed\\\]" "kill"