Refactor gdb.trace/save-trace.exp
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.trace / save-trace.exp
CommitLineData
32d0add0 1# Copyright 1998-2015 Free Software Foundation, Inc.
c906108c
SS
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
e22f8b7c 5# the Free Software Foundation; either version 3 of the License, or
c906108c 6# (at your option) any later version.
e22f8b7c 7#
c906108c
SS
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.
e22f8b7c 12#
c906108c 13# You should have received a copy of the GNU General Public License
e22f8b7c 14# along with this program. If not, see <http://www.gnu.org/licenses/>.
c906108c 15
c906108c
SS
16# This file was written by Michael Snyder (msnyder@cygnus.com)
17
4ec70201 18load_lib "trace-support.exp"
c906108c 19
c906108c
SS
20
21gdb_exit
22gdb_start
23
497a5eb0 24standard_testfile actions.c
f8b7eaf3
DJ
25if { [gdb_compile "$srcdir/$subdir/$srcfile" $binfile \
26 executable {debug nowarnings}] != "" } {
27 untested save-trace.exp
28 return -1
c906108c
SS
29}
30gdb_reinitialize_dir $srcdir/$subdir
31
32# If testing on a remote host, download the source file.
33# remote_download host $srcdir/$subdir/$srcfile
34
35gdb_file_cmd $binfile
36
37# define relative source line numbers:
38# all subsequent line numbers are relative to this first one (baseline)
4ec70201 39set baseline [gdb_find_recursion_test_baseline $srcfile]
c906108c
SS
40if { $baseline == -1 } then {
41 fail "Could not find gdb_recursion_test function"
4ec70201 42 return
c906108c
SS
43}
44
45set testline1 [expr $baseline + 4]
46set testline2 [expr $baseline + 5]
47set testline3 [expr $baseline + 6]
48set testline4 [expr $baseline + 7]
49set testline5 [expr $baseline + 8]
50set testline6 [expr $baseline + 9]
51
52#
53# test save-trace command
54#
55
56# setup a set of tracepoints to save
57
58gdb_delete_tracepoints
59
60foreach x { 1 2 3 4 5 6 } {
4ec70201
PA
61 set testline [expr \$testline$x]
62 set trcpt [gdb_gettpnum $testline]
63 set trcpt$x $trcpt
c906108c
SS
64 gdb_test "passcount $x" \
65 "Setting tracepoint $trcpt.* to $x" \
045ccf91 66 "set passcount for tracepoint $trcpt"
c906108c 67
e68d8fd4 68 gdb_test_no_output "condition $trcpt $x - 1 == $x / 2" \
045ccf91 69 "set condition for tracepoint $trcpt"
8bf6485c 70
045ccf91 71 gdb_trace_setactions "set actions for tracepoint $x" \
c906108c
SS
72 "" \
73 "collect q$x" "^$" \
74 "while-stepping $x" "^$" \
75 "collect q$x" "^$" \
76 "end" "^$"
77}
78
e68d8fd4 79gdb_test_no_output "set default-collect gdb_char_test, gdb_long_test - 100" \
045ccf91
SM
80 "set default-collect"
81
82# Save tracepoint definitions to a file, at path SAVE_PATH.
83proc gdb_save_tracepoints { save_path } {
84 set save_path_regexp [string_to_regexp $save_path]
85 remote_file host delete $save_path
86 gdb_test "save tracepoints $save_path" \
87 "Saved to file '$save_path_regexp'." \
88 "save tracepoint definitions"
89}
90
91# Load tracepoint definitions from a file, from path SAVE_PATH.
92proc gdb_load_tracepoints { save_path } {
93 # Cleanup existing tracepoints/collections
94 gdb_delete_tracepoints
95 gdb_test_no_output "set default-collect" "clear default-collect"
96
97 gdb_test "info tracepoints" "No tracepoints." "delete tracepoints"
98
99 gdb_test "source $save_path" "Tracepoint \[0-9\]+ at .*" \
100 "read back saved tracepoints"
101}
c906108c
SS
102
103proc gdb_verify_tracepoints { testname } {
4ec70201 104 global gdb_prompt
c906108c
SS
105
106 set ws "\[\t \]+"
107 set nl "\[\r\n\]+"
4ec70201
PA
108 set ourstate 1
109 set result "pass"
0ab48859 110 gdb_test_multiple "info tracepoints" "$testname" {
8bf6485c 111 -re "\[0-9\]+\[\t \]+tracepoint\[\t \]+keep y\[\t \]+0x\[0-9a-fA-F\]+ in gdb_recursion_test\[^\r\n\]+\r\n\[ \t]+trace only if \[0-9\] - 1 == \[0-9\] / 2" {
1042e4c0 112# if { $expect_out(1,string) != $ourstate } {
4ec70201 113# set result "fail"
1042e4c0 114# }
4ec70201
PA
115 incr ourstate
116 exp_continue
c906108c
SS
117 }
118 -re "$gdb_prompt $" {
119 if { $ourstate >= 6 } {
4ec70201 120 set result "pass"
c906108c 121 } else {
4ec70201 122 set result "fail"
c906108c
SS
123 }
124 }
125 default {
4ec70201 126 set result "fail"
c906108c
SS
127 }
128 }
4ec70201 129 $result $testname
8bf6485c
SS
130
131 gdb_test "show default-collect" \
132 "The list of expressions to collect by default is \"gdb_char_test, gdb_long_test - 100\"..*" \
045ccf91 133 "verify default-collect"
c906108c
SS
134}
135
045ccf91
SM
136proc do_save_load_test { save_path } {
137 # Save current tracepoint definitions to a file
138 gdb_save_tracepoints $save_path
c906108c 139
045ccf91
SM
140 # Clear existing tracepoints and reload from file
141 gdb_load_tracepoints $save_path
c906108c 142
045ccf91
SM
143 # Check if they match the expected tracepoints
144 gdb_verify_tracepoints "verify recovered tracepoints"
145}
c906108c 146
045ccf91 147gdb_verify_tracepoints "verify trace setup"
c906108c 148
045ccf91
SM
149with_test_prefix "relative" {
150 do_save_load_test "savetrace-relative.tr"
151}
c906108c 152
045ccf91
SM
153with_test_prefix "absolute" {
154 do_save_load_test [standard_output_file "savetrace-absolute.tr"]
155}
156
157# invalid filename
c906108c
SS
158# [deferred -- not sure what a good invalid filename would be]
159
045ccf91 160# save-trace (file already exists)
c906108c
SS
161# [expect it to clobber the old one]
162
045ccf91 163# help save tracepoints
c906108c 164
045ccf91 165gdb_test "help save tracepoints" \
c906108c 166 "Save current tracepoint definitions as a script.*" \
045ccf91 167 "verify help save tracepoints"
This page took 1.516727 seconds and 4 git commands to generate.