--- a/testsuite/gdb.trace/Makefile.in
+++ b/testsuite/gdb.trace/Makefile.in
@@ -3,7 +3,7 @@ srcdir = @srcdir@
.PHONY: all clean mostlyclean distclean realclean
-PROGS = ax backtrace deltrace disconnected-tracing infotrace packetlen \
+PROGS = ax backtrace ctf deltrace disconnected-tracing infotrace packetlen \
passc-dyn passcount report save-trace tfile tfind tracecmd tsv \
unavailable while-dyn while-stepping
--- /dev/null
+++ b/testsuite/gdb.trace/ctf.c
@@ -0,0 +1,48 @@
+/* CTF test program.
+
+ Copyright (C) 2013 Free Software Foundation, Inc.
+
+ This file is part of GDB.
+
+ 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 . */
+
+typedef char test_t1;
+typedef test_t1 test_t2;
+typedef test_t2 test_t3;
+
+int
+main ()
+{
+ int i;
+ int a = 0;
+ test_t3 b = 1;
+ test_t3 c[][4] = {"123", "456", "789", "123", "456", "789"};
+ struct
+ {
+ int a;
+ int b;
+ } d[2][2] = {{{1, 2}, {3, 4}}, {{5, 6}, {7, 8}}};
+
+ for (i = 0; i < 10; i++)
+ {
+ ++a; /* set tracepoint 1 here */
+ ++b; /* set tracepoint 2 here */
+ ++c[0][1];
+ ++d[0][1].a;
+ }
+
+ /* set breakpoint end here */
+
+ return 0;
+}
--- /dev/null
+++ b/testsuite/gdb.trace/ctf.exp
@@ -0,0 +1,159 @@
+# Copyright 2013 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 .
+
+load_lib "trace-support.exp";
+
+proc file_contents { filename } {
+ set file [open $filename r]
+ set contents [read $file]
+ close $file
+ return $contents
+}
+
+standard_testfile
+set executable $testfile
+set expfile $testfile.exp
+set ctfdir [standard_output_file $testfile.ctf]
+
+if [prepare_for_testing $expfile $executable $srcfile \
+ {debug nowarnings}] {
+ untested "failed to prepare for trace tests"
+ return -1
+}
+
+if ![runto_main] {
+ fail "can't run to main to check for trace support"
+ return -1
+}
+
+if ![gdb_target_supports_trace] {
+ unsupported "target does not support trace"
+ return -1;
+}
+
+
+# Test "tsave -ctf"
+
+set trace_location1 [gdb_get_line_number "set tracepoint 1 here"]
+gdb_test "trace $trace_location1" "Tracepoint ${decimal} at .*"
+gdb_trace_setactions "set action for line $trace_location1" "" \
+ "collect \$local" "^$" \
+ "while-stepping 1" "^$" \
+ "collect \$local" "^$" \
+ "end" "^$" \
+ "end" ""
+
+set trace_location2 [gdb_get_line_number "set tracepoint 2 here"]
+gdb_test "trace $trace_location2" "Tracepoint ${decimal} at .*"
+gdb_trace_setactions "set action for line $trace_location2" "" \
+ "collect \$reg" "^$" \
+ "while-stepping 1" "^$" \
+ "collect \$reg" "^$" \
+ "end" "^$" \
+ "end" ""
+
+gdb_test_no_output "tstart"
+
+set break_end [gdb_get_line_number "set breakpoint end here"]
+gdb_test "break $break_end" "Breakpoint ${decimal} at .*"
+gdb_test "continue" "Continuing\\.\[ \r\n\]+Breakpoint.*"
+
+gdb_test_no_output "tstop"
+
+gdb_test "tsave -ctf $ctfdir" "Trace data saved to directory \'$ctfdir\'."
+
+# Get the pathname of babeltrace and set it to $which_babeltrace.
+# If host doesn't have babeltrace, $which_babeltrace will set to 0.
+if [info exists BABELTRACE] {
+ set which_babeltrace ${BABELTRACE}
+} else {
+ remote_exec host "which babeltrace" "" "/dev/null" "babeltrace.which"
+ remote_upload host "babeltrace.which"
+ set which_babeltrace [file_contents "babeltrace.which"]
+ remote_file build delete "babeltrace.which"
+ remote_file host delete "babeltrace.which"
+}
+
+# Use $which_babeltrace check $ctfdir.
+if { $which_babeltrace == "" } then {
+ unsupported "babeltrace check ctf directory"
+} else {
+ # Let babeltrace output an error to make sure current way is right.
+ remote_exec host "$which_babeltrace not_exist" "" "/dev/null" "babeltrace.output"
+ remote_upload host "babeltrace.output"
+ set babeltrace_output [file_contents "babeltrace.output"]
+ remote_file build delete "babeltrace.output"
+ remote_file host delete "babeltrace.output"
+ if { [string last "\[error\]" $babeltrace_output] == -1 } then {
+ unsupported "cannot handle babeltrace output"
+ } else {
+ #Call $which_babeltrace check $ctfdir.
+ remote_exec host "$which_babeltrace $ctfdir" "" "/dev/null" "babeltrace.output"
+ remote_upload host "babeltrace.output"
+ set babeltrace_output [file_contents "babeltrace.output"]
+ remote_file build delete "babeltrace.output"
+ remote_file host delete "babeltrace.output"
+ if { [string last "\[error\]" $babeltrace_output] != -1 } then {
+ fail "babeltrace open ctf directory"
+ }
+ }
+}
+
+
+#Test "target ctf" with $ctfdir.
+gdb_test_no_output "set confirm off"
+gdb_test_no_output "kill"
+gdb_test_multiple "target ctf $ctfdir" "" {
+ -re "Undefined target command: \"ctf ctf\.ctf\"\. Try \"help target\"\.\r\n$gdb_prompt $" {
+ unsupported "target does not support ctf"
+ remote_exec host "rm -rf $ctfdir"
+ return -1;
+ }
+ -re ".*Unable.*\r\n$gdb_prompt $" {
+ fail "target ctf $ctfdir"
+ }
+ -re "\r\n$gdb_prompt $" {
+ pass "target ctf $ctfdir"
+ }
+}
+
+gdb_test "tfind 0" ".*Found trace frame 0.*" "target ctf tfind 0"
+gdb_test "tdump" ".*b = 1.*a = 0.*i = 0.*" "first target ctf tdump"
+gdb_test "print \$b" ".* = 1.*" "first target ctf print \$b"
+gdb_test "print \$a" ".* = 0.*" "first target ctf print \$a"
+gdb_test "print \$i" ".* = 0.*" "first target ctf print \$i"
+
+gdb_test "tfind 1" ".*Found trace frame 1.*" "target ctf tfind 1"
+gdb_test "tdump" ".*b = 1.*a = 1.*i = 0.*" "second target ctf tdump"
+gdb_test "print \$b" ".* = 1.*" "second target ctf print \$b"
+gdb_test "print \$a" ".* = 1.*" "second target ctf print \$a"
+gdb_test "print \$i" ".* = 0.*" "second target ctf print \$i"
+
+gdb_test "tfind 2" ".*Found trace frame 2.*" "target ctf tfind 2"
+
+gdb_test "tfind 3" ".*Found trace frame 3.*" "target ctf tfind 3"
+
+gdb_test "tfind 4" ".*Found trace frame 4.*" "target ctf tfind 4"
+gdb_test "tdump" ".*b = 2.*a = 1.*i = 1.*" "third target ctf tdump"
+gdb_test "print \$b" ".* = 2.*" "third target ctf print \$b"
+gdb_test "print \$a" ".* = 1.*" "third target ctf print \$a"
+gdb_test "print \$i" ".* = 1.*" "third target ctf print \$i"
+
+gdb_test "tfind 5" ".*Found trace frame 5.*" "target ctf tfind 5"
+gdb_test "tdump" ".*b = 2.*a = 2.*i = 1.*" "fourth target ctf tdump"
+gdb_test "print \$b" ".* = 2.*" "fourth target ctf print \$b"
+gdb_test "print \$a" ".* = 2.*" "fourth target ctf print \$a"
+gdb_test "print \$i" ".* = 1.*" "fourth target ctf print \$i"
+