aboutsummaryrefslogtreecommitdiff
path: root/gdb/testsuite/gdb.btrace
diff options
context:
space:
mode:
authorMarkus Metzger <mmetzger@sourceware.org>2013-03-11 08:59:00 +0000
committerMarkus Metzger <mmetzger@sourceware.org>2013-03-11 08:59:00 +0000
commit2f1d9bddccc54e02e2c5a94e8aa21e3c2f430068 (patch)
tree087265de33c5c1dd48590f9ebcef9a47fb8909ff /gdb/testsuite/gdb.btrace
parent59ea568849132556b980b161cbfb5e8708087719 (diff)
downloadgdb-2f1d9bddccc54e02e2c5a94e8aa21e3c2f430068.zip
gdb-2f1d9bddccc54e02e2c5a94e8aa21e3c2f430068.tar.gz
gdb-2f1d9bddccc54e02e2c5a94e8aa21e3c2f430068.tar.bz2
Add tests for the new record-btrace target.
testsuite/ * Makefile.in: Add btrace testsuite. * configure: Regenerated. * configure.ac: Add btrace testsuite. * gdb.btrace/Makefile.in: New file. * gdb.btrace/enable.c: New file. * gdb.btrace/enable.exp: New file. * gdb.btrace/function_call_history.c: New file. * gdb.btrace/function_call_history.exp: New file. * gdb.btrace/instruction_history.c: New file. * gdb.btrace/instruction_history.exp: New file. * gdb.btrace/instruction_history.S: New file. * lib/gdb.exp: Add btrace skip proc.
Diffstat (limited to 'gdb/testsuite/gdb.btrace')
-rw-r--r--gdb/testsuite/gdb.btrace/Makefile.in17
-rw-r--r--gdb/testsuite/gdb.btrace/enable.c24
-rw-r--r--gdb/testsuite/gdb.btrace/enable.exp84
-rw-r--r--gdb/testsuite/gdb.btrace/function_call_history.c45
-rw-r--r--gdb/testsuite/gdb.btrace/function_call_history.exp219
-rw-r--r--gdb/testsuite/gdb.btrace/instruction_history.S32
-rw-r--r--gdb/testsuite/gdb.btrace/instruction_history.c26
-rw-r--r--gdb/testsuite/gdb.btrace/instruction_history.exp195
8 files changed, 642 insertions, 0 deletions
diff --git a/gdb/testsuite/gdb.btrace/Makefile.in b/gdb/testsuite/gdb.btrace/Makefile.in
new file mode 100644
index 0000000..f4c06d1
--- /dev/null
+++ b/gdb/testsuite/gdb.btrace/Makefile.in
@@ -0,0 +1,17 @@
+VPATH = @srcdir@
+srcdir = @srcdir@
+
+EXECUTABLES = enable function_call_history instruction_history
+
+MISCELLANEOUS =
+
+all info install-info dvi install uninstall installcheck check:
+ @echo "Nothing to be done for $@..."
+
+clean mostlyclean:
+ rm -f *~ *.o *.x *.ci *.sl a.out core
+ rm -f *.dwo *.dwp
+ rm -f $(EXECUTABLES) $(MISCELLANEOUS)
+
+distclean maintainer-clean realclean: clean
+ rm -f Makefile config.status config.log site.* gdb.log gdb.sum
diff --git a/gdb/testsuite/gdb.btrace/enable.c b/gdb/testsuite/gdb.btrace/enable.c
new file mode 100644
index 0000000..ce77651
--- /dev/null
+++ b/gdb/testsuite/gdb.btrace/enable.c
@@ -0,0 +1,24 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+ Copyright 2013 Free Software Foundation, Inc.
+
+ Contributed by Intel Corp. <christian.himpel@intel.com>
+
+ 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)
+{
+ return 0;
+}
diff --git a/gdb/testsuite/gdb.btrace/enable.exp b/gdb/testsuite/gdb.btrace/enable.exp
new file mode 100644
index 0000000..f3acbf8
--- /dev/null
+++ b/gdb/testsuite/gdb.btrace/enable.exp
@@ -0,0 +1,84 @@
+# This testcase is part of GDB, the GNU debugger.
+#
+# Copyright 2013 Free Software Foundation, Inc.
+#
+# Contributed by Intel Corp. <christian.himpel@intel.com>
+#
+# 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/>.
+
+# check for btrace support
+if { [skip_btrace_tests] } { return -1 }
+
+# start fresh - without an executable
+gdb_exit
+gdb_start
+
+# record cannot be stopped, if it was never active
+gdb_test "record stop" "No record target is currently active\\..*" "record stop without target"
+
+# btrace cannot be enabled without a running inferior
+gdb_test "record btrace" "The program is not being run\\." "record btrace without running program"
+
+# no function and no instruction history without btrace enabled
+gdb_test "record function-call-history" "No record target is currently active\\..*" "record function-call-history without target"
+gdb_test "record instruction-history" "No record target is currently active\\..*" "record instruction-history without target"
+gdb_test "info record" "No record target is currently active\\." "info record without target"
+
+# start inferior
+standard_testfile
+if [prepare_for_testing $testfile.exp $testfile {} {debug}] {
+ return -1
+}
+if ![runto_main] {
+ return -1
+}
+
+# enable btrace
+gdb_test_no_output "record btrace" "record btrace"
+gdb_test "record function-call-history" "No trace\\." "record function-call-history without trace"
+gdb_test "record instruction-history" "No trace\\." "record instruction-history without trace"
+
+# btrace cannot be enabled twice
+gdb_test "record btrace" "The process is already being recorded\\." "record btrace the second time"
+
+# full record cannot be activated as long as btrace is active
+gdb_test "record full" "Process record target already running\\. Use \"record stop\" to stop record target first\\." "record full cannot be enabled"
+
+# no trace recorded yet
+gdb_test "info record" "Active record target: record-btrace\r\nRecorded 0 instructions in 0 functions for thread 1.*\\." "info record without trace"
+
+# stop btrace record
+gdb_test "record stop" "Process record is stopped and all execution logs are deleted\\." "record stop"
+gdb_test "record stop" "No record target is currently active\\..*" "record stop the second time"
+
+# enable btrace again
+gdb_test_no_output "record btrace" "record btrace re-enable"
+gdb_test "record btrace" "The process is already being recorded\\." "record btrace re-enable twice"
+
+# continue to the end and make sure we don't die
+gdb_test "continue" ".*Inferior.*exited.*" "continue to end"
+
+# skip the rerun test when using gdbserver
+# otherwise rerun twice, target should be automatically disabled
+load_lib gdbserver-support.exp
+if [skip_gdbserver_tests] {
+ return 0
+}
+clean_restart $testfile
+if ![runto_main] {
+ return -1
+}
+if ![runto_main] {
+ return -1
+}
diff --git a/gdb/testsuite/gdb.btrace/function_call_history.c b/gdb/testsuite/gdb.btrace/function_call_history.c
new file mode 100644
index 0000000..a76b7c3
--- /dev/null
+++ b/gdb/testsuite/gdb.btrace/function_call_history.c
@@ -0,0 +1,45 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+ Copyright 2013 Free Software Foundation, Inc.
+
+ Contributed by Intel Corp. <christian.himpel@intel.com>
+
+ 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
+inc (int i)
+{
+ return i+1;
+}
+
+int
+fib (int n)
+{
+ if (n <= 1)
+ return n;
+
+ return fib(n-2) + fib(n-1);
+}
+
+int
+main (void)
+{
+ int i, j;
+
+ for (i = 0; i < 10; i++)
+ j += inc(i);
+
+ j += fib(3); /* bp.1 */
+ return j; /* bp.2 */
+}
diff --git a/gdb/testsuite/gdb.btrace/function_call_history.exp b/gdb/testsuite/gdb.btrace/function_call_history.exp
new file mode 100644
index 0000000..97447e1
--- /dev/null
+++ b/gdb/testsuite/gdb.btrace/function_call_history.exp
@@ -0,0 +1,219 @@
+# This testcase is part of GDB, the GNU debugger.
+#
+# Copyright 2013 Free Software Foundation, Inc.
+#
+# Contributed by Intel Corp. <christian.himpel@intel.com>
+#
+# 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/>.
+
+# check for btrace support
+if { [skip_btrace_tests] } { return -1 }
+
+# start inferior
+standard_testfile
+if [prepare_for_testing function_call_history.exp $testfile {} {debug}] {
+ return -1
+}
+if ![runto_main] {
+ return -1
+}
+
+# start btrace
+gdb_test_no_output "record btrace"
+
+# set bp after increment loop and continue
+set bp_location [gdb_get_line_number "bp.1" $testfile.c]
+gdb_breakpoint $bp_location
+gdb_continue_to_breakpoint "cont to $bp_location" ".*$testfile.c:$bp_location.*"
+
+# show function call history with unlimited size, we expect to see all 21 entries
+gdb_test_no_output "set record function-call-history-size 0"
+gdb_test "record function-call-history" "
+0\tmain\r
+1\tinc\r
+2\tmain\r
+3\tinc\r
+4\tmain\r
+5\tinc\r
+6\tmain\r
+7\tinc\r
+8\tmain\r
+9\tinc\r
+10\tmain\r
+11\tinc\r
+12\tmain\r
+13\tinc\r
+14\tmain\r
+15\tinc\r
+16\tmain\r
+17\tinc\r
+18\tmain\r
+19\tinc\r
+20\tmain\r" "record function-call-history - with size unlimited"
+
+# show function call history with size of 21, we expect to see all 21 entries
+gdb_test_no_output "set record function-call-history-size 21"
+# show function call history
+gdb_test "record function-call-history 0" "
+0\tmain\r
+1\tinc\r
+2\tmain\r
+3\tinc\r
+4\tmain\r
+5\tinc\r
+6\tmain\r
+7\tinc\r
+8\tmain\r
+9\tinc\r
+10\tmain\r
+11\tinc\r
+12\tmain\r
+13\tinc\r
+14\tmain\r
+15\tinc\r
+16\tmain\r
+17\tinc\r
+18\tmain\r
+19\tinc\r
+20\tmain\r" "record function-call-history - show all 21 entries"
+
+# show first 15 entries
+gdb_test_no_output "set record function-call-history-size 15"
+gdb_test "record function-call-history 0" "
+0\tmain\r
+1\tinc\r
+2\tmain\r
+3\tinc\r
+4\tmain\r
+5\tinc\r
+6\tmain\r
+7\tinc\r
+8\tmain\r
+9\tinc\r
+10\tmain\r
+11\tinc\r
+12\tmain\r
+13\tinc\r
+14\tmain\r" "record function-call-history - show first 15 entries"
+
+# show last 6 entries
+gdb_test "record function-call-history +" "
+15\tinc\r
+16\tmain\r
+17\tinc\r
+18\tmain\r
+19\tinc\r
+20\tmain\r" "record function-call-history - show last 6 entries"
+
+# moving further should not work
+gdb_test "record function-call-history +" "At the end of the branch trace record\\." "record function-call-history - at the end (1)"
+
+# make sure we cannot move any further a second time
+gdb_test "record function-call-history +" "At the end of the branch trace record\\." "record function-call-history - at the end (2)"
+
+# moving back showing the latest 15 function calls
+gdb_test "record function-call-history -" "
+6\tmain\r
+7\tinc\r
+8\tmain\r
+9\tinc\r
+10\tmain\r
+11\tinc\r
+12\tmain\r
+13\tinc\r
+14\tmain\r
+15\tinc\r
+16\tmain\r
+17\tinc\r
+18\tmain\r
+19\tinc\r
+20\tmain\r" "record function-call-history - show last 15 entries"
+
+# moving further back shows the 6 first function calls
+gdb_test "record function-call-history -" "
+0\tmain\r
+1\tinc\r
+2\tmain\r
+3\tinc\r
+4\tmain\r
+5\tinc\r" "record function-call-history - show first 6 entries"
+
+# moving further back shouldn't work
+gdb_test "record function-call-history -" "At the start of the branch trace record\\." "record function-call-history - at the start (1)"
+
+# make sure we cannot move any further back
+gdb_test "record function-call-history -" "At the start of the branch trace record\\." "record function-call-history - at the start (2)"
+
+# moving forward again, but this time with file and line number, expected to see the first 15 entries
+gdb_test "record function-call-history /l +" "
+.*$srcfile:40-41\tmain\r
+.*$srcfile:22-24\tinc\r
+.*$srcfile:40-41\tmain\r
+.*$srcfile:22-24\tinc\r
+.*$srcfile:40-41\tmain\r
+.*$srcfile:22-24\tinc\r
+.*$srcfile:40-41\tmain\r
+.*$srcfile:22-24\tinc\r
+.*$srcfile:40-41\tmain\r
+.*$srcfile:22-24\tinc\r
+.*$srcfile:40-41\tmain\r
+.*$srcfile:22-24\tinc\r
+.*$srcfile:40-41\tmain\r
+.*$srcfile:22-24\tinc\r
+.*$srcfile:40-41\tmain\r" "record function-call-history /l - show first 15 entries"
+
+# moving forward and expect to see the latest 6 entries
+gdb_test "record function-call-history /l +" "
+.*$srcfile:22-24\tinc\r
+.*$srcfile:40-41\tmain\r
+.*$srcfile:22-24\tinc\r
+.*$srcfile:40-41\tmain\r
+.*$srcfile:22-24\tinc\r
+.*$srcfile:40-43\tmain\r" "record function-call-history /l - show last 6 entries"
+
+# moving further forward shouldn't work
+gdb_test "record function-call-history /l +" "At the end of the branch trace record\\." "record function-call-history /l - at the end (1)"
+gdb_test "record function-call-history /l" "At the end of the branch trace record\\." "record function-call-history /l - at the end (2)"
+
+set expected_range "3\tinc\r
+4\tmain\r
+5\tinc\r
+6\tmain\r
+7\tinc\r
+8\tmain\r
+9\tinc\r"
+
+# show functions in instruction range
+gdb_test "record function-call-history 3,10" $expected_range "absolute instruction range"
+gdb_test "record function-call-history 3,+7" $expected_range "relative positive instruction range"
+gdb_test "record function-call-history 10,-7" $expected_range "relative negative instruction range"
+
+# set bp after fib recursion and continue
+set bp_location [gdb_get_line_number "bp.2" $testfile.c]
+gdb_breakpoint $bp_location
+gdb_continue_to_breakpoint "cont to $bp_location" ".*$testfile.c:$bp_location.*"
+
+# at this point we expect to have main, fib, ..., fib, main, where fib occurs 8 times,
+# so we limit the output to only show the latest 10 function calls
+gdb_test_no_output "set record function-call-history-size 10"
+set message "show recursive function call history"
+gdb_test_multiple "record function-call-history" $message {
+ -re "13\tmain\r\n14\tfib\r\n15\tfib\r\n16\tfib\r\n17\tfib\r\n18\tfib\r\n19\tfib\r\n20\tfib\r\n21\tfib\r\n22 main\r\n$gdb_prompt $" {
+ pass $message
+ }
+ -re "13\tinc\r\n14\tmain\r\n15\tinc\r\n16\tmain\r\n17\tinc\r\n18\tmain\r\n19\tinc\r\n20\tmain\r\n21\tfib\r\n22\tmain\r\n$gdb_prompt $" {
+ # recursive function calls appear only as 1 call
+ kfail "gdb/15240" $message
+ }
+}
diff --git a/gdb/testsuite/gdb.btrace/instruction_history.S b/gdb/testsuite/gdb.btrace/instruction_history.S
new file mode 100644
index 0000000..5c74b46
--- /dev/null
+++ b/gdb/testsuite/gdb.btrace/instruction_history.S
@@ -0,0 +1,32 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+ Copyright 2013 Free Software Foundation, Inc.
+
+ Contributed by Intel Corp. <christian.himpel@intel.com>
+
+ 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/>. */
+
+ .text
+ .globl loop
+ .type loop, @function
+
+loop:
+ movl $0x2, %eax /* bp.1 */
+.L1:
+ cmpl $0, %eax
+ je .L2
+ decl %eax
+ jmp .L1
+.L2:
+ ret /* bp.2 */
diff --git a/gdb/testsuite/gdb.btrace/instruction_history.c b/gdb/testsuite/gdb.btrace/instruction_history.c
new file mode 100644
index 0000000..45d9d67
--- /dev/null
+++ b/gdb/testsuite/gdb.btrace/instruction_history.c
@@ -0,0 +1,26 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+ Copyright 2013 Free Software Foundation, Inc.
+
+ Contributed by Intel Corp. <christian.himpel@intel.com>
+
+ 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)
+{
+ /* loop is declared in instruction_history.S */
+ loop ();
+ return 0;
+}
diff --git a/gdb/testsuite/gdb.btrace/instruction_history.exp b/gdb/testsuite/gdb.btrace/instruction_history.exp
new file mode 100644
index 0000000..c1a61b7
--- /dev/null
+++ b/gdb/testsuite/gdb.btrace/instruction_history.exp
@@ -0,0 +1,195 @@
+# This testcase is part of GDB, the GNU debugger.
+#
+# Copyright 2013 Free Software Foundation, Inc.
+#
+# Contributed by Intel Corp. <christian.himpel@intel.com>
+#
+# 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/>.
+
+# check for btrace support
+if { [skip_btrace_tests] } { return -1 }
+
+# compile and run to main
+standard_testfile .c .S
+if [prepare_for_testing $testfile.exp $testfile "$srcfile $srcfile2" {debug}] {
+ return -1
+}
+if ![runto_main] {
+ return -1
+}
+
+# set bp before loop and continue
+set bp_location [gdb_get_line_number "bp.1" $srcfile2]
+gdb_breakpoint $srcfile2:$bp_location
+gdb_continue_to_breakpoint "cont to $bp_location" ".*$srcfile2:$bp_location.*"
+
+# start btrace
+gdb_test_no_output "record btrace"
+
+# set bp after loop and continue
+set bp_location [gdb_get_line_number "bp.2" $srcfile2]
+gdb_breakpoint $srcfile2:$bp_location
+gdb_continue_to_breakpoint "cont to $bp_location" ".*$srcfile2:$bp_location.*"
+
+# The following test cases test if "browsing" through the
+# instruction history works as expected. So for the tests
+# it is necessary to count the number of lines that are
+# shown by the "record instruction-history" command.
+
+set testname "determine number of recorded instructions"
+gdb_test_multiple "info record" $testname {
+ -re "Active record target: record-btrace\r\nRecorded \(\[0-9\]*\) instructions in \(\[0-9\]*\) functions for thread 1 .*\\.\r\n$gdb_prompt $" {
+ set traced $expect_out(1,string)
+ set traced_functions $expect_out(2,string)
+ pass $testname
+ }
+}
+
+# we have exactly 7 instructions here
+set message "exactly 7 instructions"
+if { $traced != 7 } {
+ fail $message
+} else {
+ pass $message
+}
+
+# test that we see the expected instructions
+gdb_test "record instruction-history 1,6" "
+1\t 0x\[0-9a-f\]+ <loop\\+\[0-9\]+>:\tje 0x\[0-9a-f\]+ <loop\\+\[0-9\]+>\r
+2\t 0x\[0-9a-f\]+ <loop\\+\[0-9\]+>:\tdec %eax\r
+3\t 0x\[0-9a-f\]+ <loop\\+\[0-9\]+>:\tjmp 0x\[0-9a-f\]+ <loop\\+\[0-9\]+>\r
+4\t 0x\[0-9a-f\]+ <loop\\+\[0-9\]+>:\tcmp \\\$0x0,%eax\r
+5\t 0x\[0-9a-f\]+ <loop\\+\[0-9\]+>:\tje 0x\[0-9a-f\]+ <loop\\+\[0-9\]+>\r"
+
+gdb_test "record instruction-history /f 1,+5" "
+1\t 0x\[0-9a-f\]+ <\\+\[0-9\]+>:\tje 0x\[0-9a-f\]+ <loop\\+\[0-9\]+>\r
+2\t 0x\[0-9a-f\]+ <\\+\[0-9\]+>:\tdec %eax\r
+3\t 0x\[0-9a-f\]+ <\\+\[0-9\]+>:\tjmp 0x\[0-9a-f\]+ <loop\\+\[0-9\]+>\r
+4\t 0x\[0-9a-f\]+ <\\+\[0-9\]+>:\tcmp \\\$0x0,%eax\r
+5\t 0x\[0-9a-f\]+ <\\+\[0-9\]+>:\tje 0x\[0-9a-f\]+ <loop\\+\[0-9\]+>\r"
+
+gdb_test "record instruction-history /p 6,-5" "
+1\t0x\[0-9a-f\]+ <loop\\+\[0-9\]+>:\tje 0x\[0-9a-f\]+ <loop\\+\[0-9\]+>\r
+2\t0x\[0-9a-f\]+ <loop\\+\[0-9\]+>:\tdec %eax\r
+3\t0x\[0-9a-f\]+ <loop\\+\[0-9\]+>:\tjmp 0x\[0-9a-f\]+ <loop\\+\[0-9\]+>\r
+4\t0x\[0-9a-f\]+ <loop\\+\[0-9\]+>:\tcmp \\\$0x0,%eax\r
+5\t0x\[0-9a-f\]+ <loop\\+\[0-9\]+>:\tje 0x\[0-9a-f\]+ <loop\\+\[0-9\]+>\r"
+
+gdb_test "record instruction-history /pf 1,6" "
+1\t0x\[0-9a-f\]+ <\\+\[0-9\]+>:\tje 0x\[0-9a-f\]+ <loop\\+\[0-9\]+>\r
+2\t0x\[0-9a-f\]+ <\\+\[0-9\]+>:\tdec %eax\r
+3\t0x\[0-9a-f\]+ <\\+\[0-9\]+>:\tjmp 0x\[0-9a-f\]+ <loop\\+\[0-9\]+>\r
+4\t0x\[0-9a-f\]+ <\\+\[0-9\]+>:\tcmp \\\$0x0,%eax\r
+5\t0x\[0-9a-f\]+ <\\+\[0-9\]+>:\tje 0x\[0-9a-f\]+ <loop\\+\[0-9\]+>\r"
+
+# the following tests are checking the iterators
+# to avoid lots of regexps, we just check the number of lines that
+# were printed during command execution.
+
+# test_lines_output returns the output lines from command as a list.
+proc test_lines_output { command message } {
+ global gdb_prompt
+ set message "test_lines_output: $message"
+ gdb_test_multiple $command $message {
+ -re "\n\(.*\)\r\n$gdb_prompt $" {
+ return [split [string trim $expect_out(1,string)] "\n"]
+ }
+ }
+}
+
+# test_lines_length returns the number of lines from command.
+proc test_lines_length { command message } {
+ return [llength [test_lines_output $command $message]]
+}
+
+# show instruction history with unlimited size, we expect to see
+# all $traced instructions
+gdb_test_no_output "set record instruction-history-size 0"
+set message "record instruction-history - unlimited"
+set lines [test_lines_length "record instruction-history 0" $message]
+if { $traced != $lines } {
+ fail $message
+} else {
+ pass $message
+}
+
+gdb_test_no_output "set record instruction-history-size $traced"
+set message "record instruction-history - traced"
+set lines [test_lines_length "record instruction-history 0" $message]
+if { $traced != $lines } {
+ fail $message
+} else {
+ pass $message
+}
+
+# test that the iterator works
+set history_size 3
+gdb_test_no_output "set record instruction-history-size $history_size"
+set message "browse history forward start"
+set lines [test_lines_length "record instruction-history 0" $message]
+if { $lines != $history_size } {
+ fail $message
+} else {
+ pass $message
+}
+
+set message "browse history forward middle"
+set lines [test_lines_length "record instruction-history +" $message]
+if { $lines != $history_size } {
+ fail $message
+} else {
+ pass $message
+}
+
+set message "browse history forward last"
+set lines [test_lines_length "record instruction-history +" $message]
+if { $lines != 1 } {
+ fail $message
+} else {
+ pass $message
+}
+
+gdb_test "record instruction-history" "At the end of the branch trace record\\." "browse history forward beyond 1"
+
+# make sure we cannot move further
+gdb_test "record instruction-history" "At the end of the branch trace record\\." "browse history forward beyond 2"
+
+set message "browse history backward last"
+set lines [test_lines_length "record instruction-history -" $message]
+if { $lines != $history_size } {
+ fail $message
+} else {
+ pass $message
+}
+
+set message "browse history backward middle"
+set lines [test_lines_length "record instruction-history -" $message]
+if { $lines != $history_size } {
+ fail $message
+} else {
+ pass $message
+}
+
+set message "browse history backward first"
+set lines [test_lines_length "record instruction-history -" $message]
+if { $lines != 1 } {
+ fail $message
+} else {
+ pass $message
+}
+
+gdb_test "record instruction-history -" "At the start of the branch trace record\\." "browse history backward beyond 1"
+
+# make sure we cannot move further back
+gdb_test "record instruction-history -" "At the start of the branch trace record\\." "browse history backward beyond 2"