diff options
author | Jan Vrany <jan.vrany@labware.com> | 2021-12-08 10:46:49 +0000 |
---|---|---|
committer | Jan Vrany <jan.vrany@labware.com> | 2021-12-08 10:46:49 +0000 |
commit | 2bd64d21094f9527c9a6019f668c16ca897b2631 (patch) | |
tree | 8cc6fda87a0ccdc6011237b1ce30876661a5698f /gdb/testsuite | |
parent | 44f3c3c212f9b568a6b3cff0444b6750e3d8680f (diff) | |
download | gdb-2bd64d21094f9527c9a6019f668c16ca897b2631.zip gdb-2bd64d21094f9527c9a6019f668c16ca897b2631.tar.gz gdb-2bd64d21094f9527c9a6019f668c16ca897b2631.tar.bz2 |
ppc: recognize all program traps
Permanent program breakpoints (ones inserted into the code) other than
the one GDB uses for POWER (0x7fe00008) did not result in stop but
caused GDB to loop infinitely.
This was because GDB did not recognize trap instructions other than
"trap". For example, "tw 12, 4, 4" was not be recognized, causing GDB
to loop forever.
This commit fixes this by providing POWER specific hook
(gdbarch_program_breakpoint_here_p) recognizing all tw, twi, td and tdi
instructions.
Tested on Linux on PowerPC e500 and on QEMU PPC64le.
Diffstat (limited to 'gdb/testsuite')
-rw-r--r-- | gdb/testsuite/gdb.arch/powerpc-trap.exp | 72 | ||||
-rw-r--r-- | gdb/testsuite/gdb.arch/powerpc-trap.s | 31 | ||||
-rw-r--r-- | gdb/testsuite/gdb.arch/powerpc64-trap.s | 33 |
3 files changed, 136 insertions, 0 deletions
diff --git a/gdb/testsuite/gdb.arch/powerpc-trap.exp b/gdb/testsuite/gdb.arch/powerpc-trap.exp new file mode 100644 index 0000000..57a683d --- /dev/null +++ b/gdb/testsuite/gdb.arch/powerpc-trap.exp @@ -0,0 +1,72 @@ +# Copyright 2021 Free Software Foundation, Inc. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. +# +# This file is part of the gdb testsuite. + +# Test if GDB stops at various trap instructions inserted into +# the code. + +if { [istarget powerpc-*] } { + standard_testfile powerpc-trap.s + # Number of expected SIGTRAPs to get. This needs to be kept in sync + # with the source file powerpc-trap.s. + set expected_traps 3 +} elseif {[istarget powerpc64*] } { + standard_testfile powerpc64-trap.s + # Number of expected SIGTRAPs to get. This needs to be kept in sync + # with the source file powerpc64-trap.s. + set expected_traps 5 +} else { + verbose "Skipping ${gdb_test_file_name}." + return +} + +if {[prepare_for_testing "failed to prepare" ${testfile} ${srcfile}]} { + return -1 +} + +if {![runto_main]} { + untested "could not run to main" + return -1 +} + +set keep_going 1 +set count 0 + +while {$keep_going} { + set keep_going 0 + + # Continue to next program breakpoint instruction. + gdb_test_multiple "continue" "trap instruction $count causes SIGTRAP" { + -re "Program received signal SIGTRAP, Trace/breakpoint trap.*$gdb_prompt $" { + pass $gdb_test_name + + # Advance PC to next instruction + gdb_test "set \$pc = \$pc + 4" "" "advance past trap instruction $count" + + incr count + if {$count < $expected_traps} { + set keep_going 1 + } + } + } +} + +# Verify we stopped at the expected number of SIGTRAP's. +gdb_assert {$count == $expected_traps} "all trap instructions triggered" + +# One last continue to reach the end of the test, to make sure we don't get +# another SIGTRAP. +gdb_test "continue" "exited normally.*" "continue to end" diff --git a/gdb/testsuite/gdb.arch/powerpc-trap.s b/gdb/testsuite/gdb.arch/powerpc-trap.s new file mode 100644 index 0000000..b03176f --- /dev/null +++ b/gdb/testsuite/gdb.arch/powerpc-trap.s @@ -0,0 +1,31 @@ +/* This testcase is part of GDB, the GNU debugger. + + Copyright 2021 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. */ + +/* To test if GDB stops at various trap instructions inserted into + the code. */ + +.global main +.type main,function +main: + ori 0, 0, 0 + trap + tw 12, 2, 2 + twi 31, 3, 3 + ori 0, 0, 0 + li 3, 0 + blr + diff --git a/gdb/testsuite/gdb.arch/powerpc64-trap.s b/gdb/testsuite/gdb.arch/powerpc64-trap.s new file mode 100644 index 0000000..2272b42 --- /dev/null +++ b/gdb/testsuite/gdb.arch/powerpc64-trap.s @@ -0,0 +1,33 @@ +/* This testcase is part of GDB, the GNU debugger. + + Copyright 2021 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. */ + +/* To test if GDB stops at various trap instructions inserted into + the code. */ + +.global main +.type main,function +main: + ori 0, 0, 0 + trap + tw 12, 2, 2 + twi 31, 3, 3 + td 12, 2, 2 + tdi 31, 3, 3 + ori 0, 0, 0 + li 3, 0 + blr + |