[12/17,PowerPC] Add tests for TAR
Commit Message
This patch adds a testcase for GDB access to the Target Address
Register.
gdb/testsuite/ChangeLog:
YYYY-MM-DD Pedro Franco de Carvalho <pedromfc@linux.ibm.com>
* gdb.arch/powerpc-tar.c: New file.
* gdb.arch/powerpc-tar.exp: New file.
---
gdb/testsuite/gdb.arch/powerpc-tar.c | 33 ++++++++++
gdb/testsuite/gdb.arch/powerpc-tar.exp | 115 +++++++++++++++++++++++++++++++++
2 files changed, 148 insertions(+)
create mode 100644 gdb/testsuite/gdb.arch/powerpc-tar.c
create mode 100644 gdb/testsuite/gdb.arch/powerpc-tar.exp
new file mode 100644
@@ -0,0 +1,33 @@
+/* This test is part of GDB, the GNU debugger.
+
+ Copyright 2018 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/>. */
+
+int main (void)
+{
+ void * target1 = &&target1_l;
+ void * target2 = &&target2_l;
+ asm volatile ("mtspr 815,%0" : : "r" (target1) : );
+
+ /* Branch always to TAR. */
+ asm volatile ("bctar 20,0,0"); // marker
+
+ target2_l:
+ asm volatile ("nop"); // marker 2
+ target1_l:
+ asm volatile ("nop");
+
+ return 0;
+}
new file mode 100644
@@ -0,0 +1,115 @@
+# Copyright 2018 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 access to special purpose register TAR.
+
+if {![istarget "powerpc*-*-linux*"]} then {
+ verbose "Skipping PowerPC test for the TAR register."
+ return
+}
+
+standard_testfile .c
+
+if {[build_executable "compile" $binfile $srcfile {debug}] == -1} {
+ return -1
+}
+
+proc check_register_access { regname } {
+ global gdb_prompt
+
+ set test "$regname register access"
+ gdb_test_multiple "info reg $regname" "$test" {
+ -re "Invalid register.*\r\n$gdb_prompt $" {
+ unsupported "$test"
+ return 0
+ }
+ -re "\r\n$regname.*\r\n$gdb_prompt $" {
+ pass "$test"
+ return 1
+ }
+ }
+ return 0
+}
+
+clean_restart $binfile
+
+runto_main
+
+if {![check_register_access "tar"]} {
+ return
+}
+
+# Do one pass to check if TAR is usable, system
+# software can prevent it from being used.
+proc tar_available {} {
+ global gdb_prompt
+ global inferior_exited_re
+
+ set test "TAR available to inferior"
+ gdb_test_multiple "continue" "" {
+ -re "Illegal instruction.*\r\n$gdb_prompt $" {
+ unsupported "$test"
+ return 0
+ }
+ -re "$inferior_exited_re normally.*$gdb_prompt $" {
+ pass "$test"
+ return 1
+ }
+ }
+ return 0
+}
+
+if {![tar_available]} {
+ return
+}
+
+# Now do the actual test
+clean_restart $binfile
+
+runto_main
+
+set bp_line [gdb_get_line_number "marker"]
+
+gdb_breakpoint ${srcfile}:${bp_line}
+
+gdb_continue_to_breakpoint "continue to marker"
+
+set target1 [get_hexadecimal_valueof "target1" -1]
+set tar [get_hexadecimal_valueof "\$tar" -2]
+
+set test "TAR value from mtspr"
+
+if {${target1} == ${tar}} {
+ pass $test
+} else {
+ fail $test
+}
+
+set target2 [get_hexadecimal_valueof "target2" -1]
+
+if {$target2 == -1} {
+ fail "Could not get value of label2"
+ return
+}
+
+gdb_test_no_output "set \$tar = $target2"
+
+set bp_line [gdb_get_line_number "marker 2"]
+
+gdb_breakpoint ${srcfile}:${bp_line}
+
+gdb_continue_to_breakpoint "continue to new target address" ".*marker 2.*"