2012-01-16 Pedro Alves <palves@redhat.com>
[binutils-gdb.git] / gdb / testsuite / gdb.trace / tsv.exp
1 # Copyright 2009-2012 Free Software Foundation, Inc.
2 #
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 3 of the License, or
6 # (at your option) any later version.
7 #
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
12 #
13 # You should have received a copy of the GNU General Public License
14 # along with this program. If not, see <http://www.gnu.org/licenses/>.
15
16 load_lib "trace-support.exp";
17
18
19 gdb_exit
20 gdb_start
21 set testfile "actions"
22 set srcfile ${testfile}.c
23 set binfile $objdir/$subdir/tsv
24 if { [gdb_compile "$srcdir/$subdir/$srcfile" $binfile \
25 executable {debug nowarnings}] != "" } {
26 untested tsv.exp
27 return -1
28 }
29 gdb_load $binfile
30
31 gdb_test "tvariable \$tvar1" \
32 "Trace state variable \\\$tvar1 created, with initial value 0." \
33 "Create a trace state variable"
34
35 gdb_test "tvariable \$tvar2 = 45" \
36 "Trace state variable \\\$tvar2 created, with initial value 45." \
37 "Create a trace state variable with initial value"
38
39 gdb_test "tvariable \$tvar2 = -92" \
40 "Trace state variable \\\$tvar2 now has initial value -92." \
41 "Change initial value of a trace state variable"
42
43 gdb_test "tvariable \$tvar3 = 2 + 3" \
44 "Trace state variable \\\$tvar3 created, with initial value 5." \
45 "Create a trace state variable with expression"
46
47 gdb_test "tvariable \$tvar3 = 1234567000000" \
48 "Trace state variable \\\$tvar3 now has initial value 1234567000000." \
49 "Init trace state variable to a 64-bit value"
50
51 gdb_test "tvariable main" \
52 "Syntax must be \\\$NAME \\\[ = EXPR \\\]" \
53 "tvariable syntax error, bad name"
54
55 gdb_test "tvariable \$tvar1 - 93" \
56 "Syntax must be \\\$NAME \\\[ = EXPR \\\]" \
57 "tvariable syntax error, not an assignment"
58
59 gdb_test "info tvariables" \
60 "Name\[\t \]+Initial\[\t \]+Current.*
61 \\\$tvar1\[\t \]+0\[\t \]+<undefined>.*
62 \\\$tvar2\[\t \]+-92\[\t \]+<undefined>.*
63 \\\$tvar3\[\t \]+1234567000000\[\t \]+.*<undefined>.*" \
64 "List tvariables"
65
66 gdb_test "print \$tvar2" " = void" \
67 "Print a trace state variable before run"
68
69 gdb_test_no_output "delete tvariable \$tvar2" \
70 "delete trace state variable"
71
72 gdb_test "info tvariables" \
73 "Name\[\t \]+Initial\[\t \]+Current.*
74 \\\$tvar1\[\t \]+0\[\t \]+<undefined>.*
75 \\\$tvar3\[\t \]+1234567000000\[\t \]+.*<undefined>.*" \
76 "List tvariables after deletion"
77
78 gdb_test "delete tvariable" \
79 "" \
80 "Delete all trace state variables" \
81 "Delete all trace state variables.*y or n.*$" \
82 "y"
83
84 gdb_test "info tvariables" \
85 "No trace state variables.*" \
86 "List tvariables after deleting all"
87
88 # Now try running a trace.
89
90 runto_main
91 gdb_reinitialize_dir $srcdir/$subdir
92
93 # The rest of the testing needs actual tracing to work.
94 if { ![gdb_target_supports_trace] } then {
95 pass "Current target does not support trace"
96 return 1;
97 }
98
99 # define relative source line numbers:
100 # all subsequent line numbers are relative to this first one (baseline)
101
102 set baseline [gdb_find_recursion_test_baseline $srcfile];
103 if { $baseline == -1 } then {
104 fail "Could not find gdb_recursion_test function"
105 return;
106 }
107
108 set testline1 [expr $baseline + 7]
109
110 gdb_delete_tracepoints
111 set trcpt1 [gdb_gettpnum gdb_c_test];
112 set trcpt2 [gdb_gettpnum gdb_asm_test];
113 set trcpt3 [gdb_gettpnum $testline1];
114 if { $trcpt1 <= 0 || $trcpt2 <= 0 || $trcpt3 <= 0 } then {
115 fail "setting tracepoints"
116 return;
117 }
118
119 gdb_test "tvariable \$tvar5 = 15" \
120 "Trace state variable \\\$tvar5 created, with initial value 15." \
121 "Create a trace state variable tvar5"
122
123 gdb_trace_setactions "collect tsv for first tracepoint" \
124 "$trcpt1" \
125 "collect \$tvar5 += 1" "^$"
126
127 gdb_test "tstart" ".*" ""
128
129 gdb_test "print \$tvar5" " = 15" \
130 "Print a trace state variable at start of run"
131
132 # Be sure not to fall off the end of the program.
133 gdb_test "break end" ".*" ""
134 gdb_test "continue" \
135 "Continuing.*Breakpoint $decimal, end.*" \
136 "run trace experiment"
137
138 gdb_test "print \$tvar5" " = 16" \
139 "Print a trace state variable during run"
140
141 gdb_test "tstop" ".*" ""
142
143 gdb_test "print \$tvar5" " = 16" \
144 "Print a trace state variable after run"
145
146