public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH,rs6000]  GDB testcases for exercising breakpoints over PC-Relative instructions
@ 2021-03-27  0:25 will schmidt
  2021-03-27 14:27 ` Andrew Burgess
  2021-03-29 22:43 ` [PATCH,rs6000, v2] " will schmidt
  0 siblings, 2 replies; 4+ messages in thread
From: will schmidt @ 2021-03-27  0:25 UTC (permalink / raw)
  To: gdb-patches; +Cc: Ulrich Weigand, Will Schmidt, rogerio


    Hi,
      A few testcases to exercise powerpc PC-Relative instructions.
    These exercise single-stepping over prefixed instructions and
    verifying the loaded values are correct when we have single-stepped
    over an instruction that was executed from a displaced
    location.
    
    This is meant to assure that
    - single stepping over a prefixed instruction succeeds, in particular to
    confirm that an 8-byte instruction is properly handled.
    - An instruction that references the PC/NIA is properly fixed-up upon
    completion.


    YYYY-MM-DD  Will Schmidt  <will_schmidt@vnet.ibm.com>

    gdb/testsuite/ChangeLog:
	* gdb/testsuite/gdb.arch/powerpc-breakpoint-on-prefix-insn.s:  Testcase with pnop and 
	  pcrelative plxv instructions.
	* gdb/testsuite/gdb.arch/powerpc-breakpoint-on-prefix-insn.exp: Testcase harness.
	* gdb/testsuite/gdb.arch/powerpc-plxv.s:  Testcase with plxv and nop instructions.
	* gdb/testsuite/gdb.arch/powerpc-plxv.exp:  Testcase harness.



 powerpc-breakpoint-on-prefix-insn.exp |  135 ++++++++++++++++++++++++++++++++++
 powerpc-breakpoint-on-prefix-insn.s   |   29 +++++++
 powerpc-plxv.exp                      |  133 +++++++++++++++++++++++++++++++++
 powerpc-plxv.s                        |   30 +++++++
 4 files changed, 327 insertions(+)


diff --git a/gdb/testsuite/gdb.arch/powerpc-breakpoint-on-prefix-insn.exp b/gdb/testsuite/gdb.arch/powerpc-breakpoint-on-prefix-insn.exp
new file mode 100644
index 0000000000..35c9d88703
--- /dev/null
+++ b/gdb/testsuite/gdb.arch/powerpc-breakpoint-on-prefix-insn.exp
@@ -0,0 +1,135 @@
+# 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/>.
+
+# Test to see if gdb is properly single stepping over the
+# displaced plxv instruction.
+# plxv is an extended mnemonic for the addpcis instruction, which
+# stores the $NIA plus an immediate value into a register.
+#
+#		plxv Rx == addpcis Rx,0 == plxv Rx
+#		subcis Rx,value == addpcis Rx,-value
+
+if { ![istarget powerpc*-*] } {
+    verbose "Skipping powerpc plxv test."
+    return
+}
+
+set retval 0
+
+set testfile "powerpc-breakpoint-on-prefix-insn"
+set srcfile ${testfile}.s
+set binfile [standard_output_file ${testfile}]
+
+if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {}] != "" } {
+    untested "PowerPC plxv test"
+    return -1
+}
+
+gdb_exit
+gdb_start
+gdb_load ${binfile}
+gdb_test "set radix 0b10000"
+gdb_test "set debug displaced"
+
+if ![runto_main] then {
+      return
+}
+
+proc get_vector_hexadecimal_valueof { exp default {test ""} } {
+global gdb_prompt
+set val 0xeeee
+	if {$test == ""} {
+		set test "get vector_hexadecimal valueof \"${exp}\""
+	}
+    gdb_test_multiple "print $${exp}.uint128" $test {
+	-re "\\$\[0-9\]* = (0x\[0-9a-zA-Z\]+).*$gdb_prompt $" {
+	    set val $expect_out(1,string)
+	    pass "$test"
+	}
+    }
+    return ${val}
+}
+
+proc stepi_over_instruction { xyz } {
+       global gdb_prompt
+       gdb_test_multiple "stepi" "${xyz} " {
+               -re ".*Illegal instruction.*${gdb_prompt}" {
+                   fail "Illegal instruction on single step."
+               return
+               }
+               -re ".*${gdb_prompt}" {
+                pass "stepi ${xyz}"
+               }
+       }
+}
+
+set check_pc [get_hexadecimal_valueof "\$pc" "default0"]
+
+# set some breakpoints on the instructions below main().
+gdb_test "info reg pc"
+gdb_test "disas /r main"
+set bp1 *$check_pc+8
+set bp2 *$check_pc+0d16
+set bp3 *$check_pc+0d24
+set bp4 *$check_pc+0d32
+set bp5 *$check_pc+0d40
+set bp6 *$check_pc+0
+gdb_breakpoint $bp1
+gdb_breakpoint $bp2
+gdb_breakpoint $bp3
+gdb_breakpoint $bp4
+gdb_breakpoint $bp5
+gdb_breakpoint $bp6
+gdb_test "info break"
+
+# single-step through the plxv instructions, and see what happens.
+# If the breakpoints are improperly set, these will fail with
+# illegal instruction errors.
+stepi_over_instruction "stepi over pnop"
+stepi_over_instruction "stepi over vs4 assignment"
+stepi_over_instruction "stepi over pnop"
+stepi_over_instruction "stepi over vs5 assignment"
+stepi_over_instruction "stepi over pnop"
+stepi_over_instruction "stepi over vs6 assignment"
+stepi_over_instruction "stepi over pnop"
+stepi_over_instruction "stepi over vs7 assignment"
+stepi_over_instruction "stepi over pnop"
+
+set check_vs4 [get_vector_hexadecimal_valueof "vs4" "default0"]
+set check_vs5 [get_vector_hexadecimal_valueof "vs5" "default0"]
+set check_vs6 [get_vector_hexadecimal_valueof "vs6" "default0"]
+set check_vs7 [get_vector_hexadecimal_valueof "vs7" "default0"]
+
+set vs4_expected 0xa5b5c5d5a4b4c4d4a3b3c3d3a2b2c2d2
+set vs5_expected 0xa7b7c7d7a6b6c6d6a5b5c5d5a4b4c4d4
+set vs6_expected 0xa9b9c9d9a8b8c8d8a7b7c7d7a6b6c6d6
+set vs7_expected 0xabbbcbdbaabacadaa9b9c9d9a8b8c8d8
+
+if [expr  $check_vs4 != $vs4_expected] {
+    fail "unexpected value vs4;  actual:$check_vs4 expected:$vs4_expected"
+}
+if [expr $check_vs5 != $vs5_expected ] {
+    fail "unexpected value vs5;   actual:$check_vs5 expected:$vs5_expected"
+}
+if [expr $check_vs6 != $vs6_expected ] {
+    fail "unexpected value vs6;   actual:$check_vs6 expected:$vs6_expected"
+}
+if [expr $check_vs7 != $vs7_expected ] {
+    fail "unexpected value vs7;   actual:$check_vs7 expected:$vs7_expected"
+}
+
+gdb_test "info register vs4 vs5 vs6 vs7 "
+
+
diff --git a/gdb/testsuite/gdb.arch/powerpc-breakpoint-on-prefix-insn.s b/gdb/testsuite/gdb.arch/powerpc-breakpoint-on-prefix-insn.s
new file mode 100644
index 0000000000..e5d2b5f69d
--- /dev/null
+++ b/gdb/testsuite/gdb.arch/powerpc-breakpoint-on-prefix-insn.s
@@ -0,0 +1,29 @@
+
+.global main
+.type main,function
+main:
+	pnop
+	plxv 4,40(0),1
+	pnop
+	plxv 5,40(0),1
+	pnop
+	plxv 6,40(0),1
+	pnop
+	plxv 7,40(0),1
+	pnop
+check_here:
+	blr
+mydata:
+	.long 0xa1b1c1d1	# <<-
+	.long 0xa2b2c2d2	# <<- loaded into vs4
+	.long 0xa3b3c3d3	# <<- loaded into vs4
+	.long 0xa4b4c4d4	# <<- loaded into vs4, vs5
+	.long 0xa5b5c5d5	# <<- loaded into vs4, vs5
+	.long 0xa6b6c6d6	# <<- loaded into      vs5, vs6
+	.long 0xa7b7c7d7	# <<- loaded into      vs5, vs6
+	.long 0xa8b8c8d8	# <<- loaded into           vs6, vs7
+	.long 0xa9b9c9d9	# <<- loaded into           vs6, vs7
+	.long 0xaabacada	# <<- loaded into                vs7
+	.long 0xabbbcbdb	# <<- loaded into                vs7
+	.long 0xacbcccdc	# <<-
+
diff --git a/gdb/testsuite/gdb.arch/powerpc-plxv.exp b/gdb/testsuite/gdb.arch/powerpc-plxv.exp
new file mode 100644
index 0000000000..d71810f871
--- /dev/null
+++ b/gdb/testsuite/gdb.arch/powerpc-plxv.exp
@@ -0,0 +1,133 @@
+# 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/>.
+
+# Test to see if gdb is properly single stepping over the
+# displaced plxv instruction.
+# plxv is an extended mnemonic for the addpcis instruction, which
+# stores the $NIA plus an immediate value into a register.
+#
+#		plxv Rx == addpcis Rx,0 == plxv Rx
+#		subcis Rx,value == addpcis Rx,-value
+
+if { ![istarget powerpc*-*] } {
+    verbose "Skipping powerpc plxv test."
+    return
+}
+
+set retval 0
+
+set testfile "powerpc-plxv"
+set srcfile ${testfile}.s
+set binfile [standard_output_file ${testfile}]
+
+if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {}] != "" } {
+    untested "PowerPC plxv test"
+    return -1
+}
+
+gdb_exit
+gdb_start
+gdb_load ${binfile}
+gdb_test "set radix 0b10000"
+gdb_test "set debug displaced"
+
+if ![runto_main] then {
+      return
+}
+
+proc get_vector_hexadecimal_valueof { exp default {test ""} } {
+	set val "0x0000"
+	global gdb_prompt
+	if {$test == ""} {
+		set test "get vector_hexadecimal valueof \"${exp}\""
+	}
+	gdb_test_multiple "print $${exp}.uint128" $test {
+		-re "\\$\[0-9\]* = (0x\[0-9a-zA-Z\]+).*$gdb_prompt $" {
+			set val $expect_out(1,string)
+				pass "$test"
+		}
+		-re ".*Illegal instruction.*${gdb_prompt} $" {
+			fail "Illegal instruction on print."
+			set val 0xffff
+		}
+	}
+	return ${val}
+}
+
+proc stepi_over_instruction { xyz } {
+	global gdb_prompt
+	gdb_test_multiple "stepi" "${xyz} " {
+		-re ".*Illegal instruction.*${gdb_prompt}" {
+		    fail "Illegal instruction on single step."
+		return
+		}
+		-re ".*${gdb_prompt}" {
+		 pass "stepi ${xyz}"
+		}
+	}
+}
+
+set check_pc [get_hexadecimal_valueof "\$pc" "default0"]
+
+# set some breakpoints on the instructions below main().
+gdb_test "disas /r main"
+set bp1 *$check_pc+4
+set bp2 *$check_pc+0d12
+set bp3 *$check_pc+0d20
+set bp4 *$check_pc+0d28
+gdb_breakpoint $bp1
+gdb_breakpoint $bp2
+gdb_breakpoint $bp3
+gdb_breakpoint $bp4
+
+# single-step through the plxv instructions, and retrieve the
+# register values as we proceed.
+
+stepi_over_instruction  "stepi over NOP"
+
+stepi_over_instruction  "stepi over vs4 assignment"
+set check_vs4 [get_vector_hexadecimal_valueof "vs4" "default0"]
+
+stepi_over_instruction  "stepi over vs5 assignment"
+set check_vs5 [get_vector_hexadecimal_valueof "vs5" "default0"]
+
+stepi_over_instruction  "stepi over vs6 assignment"
+set check_vs6 [get_vector_hexadecimal_valueof "vs6" "default0"]
+
+stepi_over_instruction  "stepi over vs7 assignment"
+set check_vs7 [get_vector_hexadecimal_valueof "vs7" "default0"]
+
+set vs4_expected 0xa5b5c5d5a4b4c4d4a3b3c3d3a2b2c2d2
+set vs5_expected 0xa7b7c7d7a6b6c6d6a5b5c5d5a4b4c4d4
+set vs6_expected 0xa9b9c9d9a8b8c8d8a7b7c7d7a6b6c6d6
+set vs7_expected 0xabbbcbdbaabacadaa9b9c9d9a8b8c8d8
+
+if [expr  $check_vs4 != $vs4_expected] {
+    fail "unexpected value vs4;  actual:$check_vs4 expected:$vs4_expected"
+}
+if [expr $check_vs5 != $vs5_expected ] {
+    fail "unexpected value vs5;   actual:$check_vs5 expected:$vs5_expected"
+}
+if [expr $check_vs6 != $vs6_expected ] {
+    fail "unexpected value vs6;   actual:$check_vs6 expected:$vs6_expected"
+}
+if [expr $check_vs7 != $vs7_expected ] {
+    fail "unexpected value vs7;   actual:$check_vs7 expected:$vs7_expected"
+}
+
+gdb_test "info break"
+gdb_test "info register vs4 vs5 vs6 vs7 "
+gdb_test "disas main #2"
+
diff --git a/gdb/testsuite/gdb.arch/powerpc-plxv.s b/gdb/testsuite/gdb.arch/powerpc-plxv.s
new file mode 100644
index 0000000000..d87b0771c8
--- /dev/null
+++ b/gdb/testsuite/gdb.arch/powerpc-plxv.s
@@ -0,0 +1,30 @@
+
+# Test to verify that the prefixed instructions that load/store
+# data off of a PC-Relative value behave properly when a
+# breakpoint is set on the instruction and the instruction
+# is executed from a displaced location.
+
+.global main
+.type main,function
+main:
+	nop
+	plxv 4,40(0),1
+	plxv 5,40(0),1
+	plxv 6,40(0),1
+	plxv 7,40(0),1
+check_here:
+	blr
+mydata:
+	.long 0xa1b1c1d1	# <<-
+	.long 0xa2b2c2d2	# <<- loaded into vs4
+	.long 0xa3b3c3d3	# <<- loaded into vs4
+	.long 0xa4b4c4d4	# <<- loaded into vs4, vs5
+	.long 0xa5b5c5d5	# <<- loaded into vs4, vs5
+	.long 0xa6b6c6d6	# <<- loaded into      vs5, vs6
+	.long 0xa7b7c7d7	# <<- loaded into      vs5, vs6
+	.long 0xa8b8c8d8	# <<- loaded into           vs6, vs7
+	.long 0xa9b9c9d9	# <<- loaded into           vs6, vs7
+	.long 0xaabacada	# <<- loaded into                vs7
+	.long 0xabbbcbdb	# <<- loaded into                vs7
+	.long 0xacbcccdc	# <<-
+


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-03-29 22:44 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-27  0:25 [PATCH,rs6000] GDB testcases for exercising breakpoints over PC-Relative instructions will schmidt
2021-03-27 14:27 ` Andrew Burgess
2021-03-29 15:09   ` will schmidt
2021-03-29 22:43 ` [PATCH,rs6000, v2] " will schmidt

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).