xref: /netbsd-src/external/gpl3/gdb.old/dist/gdb/testsuite/gdb.trace/tfile.exp (revision 70f7362772ba52b749c976fb5e86e39a8b2c9afc)
1#   Copyright 2010-2020 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
23load_lib "trace-support.exp"
24
25if {![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
37standard_testfile
38if { [gdb_compile "$srcdir/$subdir/$srcfile" $binfile \
39	  executable \
40	  [list debug nopie\
41	       "additional_flags=-DTFILE_DIR=\"$tfile_dir\""]] \
42	 != "" } {
43    untested "failed to compile"
44    return -1
45}
46
47# Make sure we are starting fresh.
48remote_file host delete $tfile_basic
49remote_file host delete $tfile_error
50remote_file target delete $tfile_basic
51remote_file target delete $tfile_error
52
53if { ![generate_tracefile $binfile] } {
54    unsupported "unable to generate trace file"
55    return -1
56}
57
58if {!$purely_local} {
59    # Copy tracefile from target to host through build.
60    remote_download host [remote_upload target tfile-basic.tf] tfile-basic.tf
61    remote_download host [remote_upload target tfile-error.tf] tfile-error.tf
62}
63
64clean_restart $binfile
65
66# Program has presumably exited, now target a trace file it created.
67
68gdb_test "target tfile $tfile_basic" "Created tracepoint.*" \
69    "target tfile [file tail $tfile_basic]"
70
71gdb_test "info trace" ".*tracepoint.*in write_basic_trace_file.*" \
72    "info tracepoints on trace file"
73
74gdb_test "tfind 0" \
75    "Found trace frame 0, tracepoint \[0-9\]+.
76\#0  write_basic_trace_file ().*" \
77    "tfind 0 on trace file"
78
79# Note that there is no tracepoint collecting these globals, we
80# just happen to know they are covered by the trace frame.
81
82gdb_test "print testglob" " = 31415" "print testglob on trace file"
83
84gdb_test "print testglob2" " = 271828" "print testglob2 on trace file"
85
86# This global is not covered by the trace frame, but since it's const,
87# we should be able to read it from the executable.
88
89gdb_test "print constglob" " = 10000" "print constglob on trace file"
90
91# Similarly, disassembly should find the read-only pieces in the executable.
92gdb_test "disassemble main" \
93    "Dump of assembler code for function main:.*   $hex <\\+0\\>:.*End of assembler dump\."
94
95# This global is also not covered by the trace frame, and since it's
96# non-const, we should _not_ read it from the executable, as that
97# would show the variable's initial value, not the current at time the
98# trace frame was created.
99
100gdb_test "print nonconstglob" \
101    " = <unavailable>" "print nonconstglob on trace file"
102
103gdb_test "tfind" "Target failed to find requested trace frame." \
104    "tfind does not find a second frame in trace file"
105
106gdb_test "tstatus" \
107    "Using a trace file.*
108Trace stopped by a tstop command.*
109Collected 1 trace frame.*
110Trace buffer has 256 bytes of 4096 bytes free \\(93% full\\).*
111Looking at trace frame 0, tracepoint .*" \
112    "tstatus on trace file"
113
114gdb_test "tfind end" "No longer looking at any trace frame" "leave tfind mode"
115
116gdb_test "backtrace" "No stack\." \
117    "no stack if no traceframe selected"
118
119gdb_test "info registers" "The program has no registers now\." \
120    "no registers if no traceframe selected"
121
122# Now start afresh, using only a trace file.
123
124gdb_exit
125gdb_start
126
127gdb_load $binfile
128
129gdb_test "target tfile $tfile_error" "Created tracepoint.*" \
130    "target tfile [file tail $tfile_error]"
131
132gdb_test "tstatus" \
133    "Using a trace file.*
134Trace stopped by an error \\(made-up error, tracepoint 1\\).*
135Collected 0 trace frame.*
136Trace buffer has 256 bytes of 4096 bytes free \\(93% full\\).*
137Not looking at any trace frame.*" \
138    "tstatus on error trace file"
139
140# Make sure we can reopen without error.
141gdb_test \
142    "interpreter-exec mi \"-target-select tfile $tfile_basic\"" \
143    "\\^connected.*" \
144    "interpreter-exec mi \"-target-select tfile tfile-basic.tf\""
145
146gdb_test "interpreter-exec mi \"-trace-status\"" \
147    "\\^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=\".*\"" \
148    "-trace-status"
149
150# Test completion works well.
151
152if { [readline_is_used] } {
153    gdb_test "target tfile [file rootname $tfile_basic]\t" \
154	"Assuming tracepoint.*" \
155	"complete-command 'target tfile'"
156}
157