fix up gdb.trace
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.trace / tfile.exp
1 # Copyright 2010-2013 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 # Test of trace file support.
17
18 # Note that unlike most of the tracing tests, this can be run on
19 # targets lacking tracepoint support; the program tfile.c has the
20 # ability to generate synthetic trace files directly, and the tfile
21 # target is available to all GDB configs.
22
23 load_lib "trace-support.exp"
24
25 if {![is_remote host] && ![is_remote target]} {
26 set tfile_basic [standard_output_file tfile-basic.tf]
27 set tfile_error [standard_output_file tfile-error.tf]
28 set tfile_dir [file dirname $tfile_basic]/
29 set purely_local 1
30 } else {
31 set tfile_basic tfile-basic.tf
32 set tfile_error tfile-error.tf
33 set tfile_dir ""
34 set purely_local 0
35 }
36
37 gdb_exit
38 gdb_start
39 standard_testfile
40 if { [gdb_compile "$srcdir/$subdir/$srcfile" $binfile \
41 executable \
42 [list debug nowarnings \
43 "additional_flags=-DTFILE_DIR=\"$tfile_dir\""]] \
44 != "" } {
45 untested ${testfile}.exp
46 return -1
47 }
48 gdb_reinitialize_dir $srcdir/$subdir
49
50 # Make sure we are starting fresh.
51 remote_file host delete $tfile_basic
52 remote_file host delete $tfile_error
53 remote_file target delete $tfile_basic
54 remote_file target delete $tfile_error
55
56 remote_exec target "$binfile"
57 if {!$purely_local} {
58 # Copy tracefile from target to host through build.
59 remote_download host [remote_upload target tfile-basic.tf] tfile-basic.tf
60 remote_download host [remote_upload target tfile-error.tf] tfile-error.tf
61 }
62
63 gdb_load $binfile
64
65 # Program has presumably exited, now target a trace file it created.
66
67 gdb_test "target tfile $tfile_basic" "Created tracepoint.*" \
68 "target tfile [file tail $tfile_basic]"
69
70 gdb_test "info trace" ".*tracepoint.*in write_basic_trace_file.*" \
71 "info tracepoints on trace file"
72
73 gdb_test "tfind 0" \
74 "Found trace frame 0, tracepoint \[0-9\]+.
75 \#0 write_basic_trace_file ().*" \
76 "tfind 0 on trace file"
77
78 # Note that there is no tracepoint collecting these globals, we
79 # just happen to know they are covered by the trace frame.
80
81 gdb_test "print testglob" " = 31415" "print testglob on trace file"
82
83 gdb_test "print testglob2" " = 271828" "print testglob2 on trace file"
84
85 # This global is not covered by the trace frame, but since it's const,
86 # we should be able to read it from the executable.
87
88 gdb_test "print constglob" " = 10000" "print constglob on trace file"
89
90 # Similarly, disassembly should find the read-only pieces in the executable.
91 gdb_test "disassemble main" \
92 "Dump of assembler code for function main:.* $hex <\\+0\\>:.*End of assembler dump\."
93
94 # This global is also not covered by the trace frame, and since it's
95 # non-const, we should _not_ read it from the executable, as that
96 # would show the variable's initial value, not the current at time the
97 # trace frame was created.
98
99 gdb_test "print nonconstglob" \
100 " = <unavailable>" "print nonconstglob on trace file"
101
102 gdb_test "tfind" "Target failed to find requested trace frame." \
103 "tfind does not find a second frame in trace file"
104
105 gdb_test "tstatus" \
106 "Using a trace file.*
107 Trace stopped by a tstop command.*
108 Collected 1 trace frame.*
109 Trace buffer has 256 bytes of 4096 bytes free \\(93% full\\).*
110 Looking at trace frame 0, tracepoint .*" \
111 "tstatus on trace file"
112
113 gdb_test "tfind end" "No longer looking at any trace frame" "leave tfind mode"
114
115 gdb_test "backtrace" "No stack\." \
116 "no stack if no traceframe selected"
117
118 gdb_test "info registers" "The program has no registers now\." \
119 "no registers if no traceframe selected"
120
121 # Now start afresh, using only a trace file.
122
123 gdb_exit
124 gdb_start
125
126 gdb_load $binfile
127
128 gdb_test "target tfile $tfile_error" "Created tracepoint.*" \
129 "target tfile [file tail $tfile_error]"
130
131 gdb_test "tstatus" \
132 "Using a trace file.*
133 Trace stopped by an error \\(made-up error, tracepoint 1\\).*
134 Collected 0 trace frame.*
135 Trace buffer has 256 bytes of 4096 bytes free \\(93% full\\).*
136 Not looking at any trace frame.*" \
137 "tstatus on error trace file"
138
139 gdb_test "info threads" "No threads\..*"
140 gdb_test "info inferiors" "\\* 1 <null>\[ \t\]+${binfile}.*"
141
142 # Make sure we can reopen without error.
143 gdb_test \
144 "interpreter-exec mi \"-target-select tfile $tfile_basic\"" \
145 "\\^connected.*" \
146 "interpreter-exec mi \"-target-select tfile tfile-basic.tf\""
147
148 gdb_test "interpreter-exec mi \"-trace-status\"" \
149 "\\^done,supported=\"file\",trace-file=\".*$tfile_basic\",running=\"0\",stop-reason=\"request\",frames=\"${decimal}\",frames-created=\"${decimal}\",buffer-size=\"${decimal}\",buffer-free=\"${decimal}\",disconnected=\".*\",circular=\".*\",user-name=\"\",notes=\"\",start-time=\".*\",stop-time=\".*\"" \
150 "-trace-status"
151
152 # Test completion works well.
153
154 gdb_test "target tfile [file rootname $tfile_basic]\t" \
155 "Assuming tracepoint.*" \
156 "complete-command 'target tfile'"
This page took 0.032504 seconds and 4 git commands to generate.