OSDN Git Service

Copyright updates for 2007.
[pf3gnuchains/pf3gnuchains3x.git] / gdb / testsuite / gdb.trace / backtrace.exp
1 #   Copyright 1998, 2007 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 2 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, write to the Free Software
15 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  
16
17 # Please email any bugs, comments, and/or additions to this file to:
18 # bug-gdb@prep.ai.mit.edu
19
20 # This file was written by Michael Snyder (msnyder@cygnus.com)
21
22 load_lib "trace-support.exp";
23
24 if $tracelevel then {
25     strace $tracelevel
26 }
27
28 set prms_id 0
29 set bug_id 0
30
31 gdb_exit
32 gdb_start
33
34 if [istarget "m68k-*-elf"] then {
35     load_lib "emc-support.exp";
36     set srcfile gdb_c_test.c
37     set binfile [board_info target d490_binfile];
38     gdb_test "set remotetimeout 6" "" ""
39     set timeout 500
40     gdb_target_monitor "$binfile"
41     # Give a TSTOP and ignore errors, to make sure any previous trace is off
42     gdb_test "tstop" "" ""
43     gdb_test "tfind none"  "" ""
44     send_gdb "compare-sections CS\n"
45     gdb_expect {
46         -re "MIS-MATCHED.*$gdb_prompt $" {
47             untested backtrace.exp
48             return -1
49             all tests in this module will fail.";
50         }
51         -re ".*$gdb_prompt $" { }
52     }
53 } else {
54     set testfile "actions"
55     set srcfile ${testfile}.c
56     set binfile $objdir/$subdir/$testfile
57     if { [gdb_compile "$srcdir/$subdir/$srcfile" $binfile \
58             executable {debug nowarnings}] != "" } {
59         untested backtrace.exp
60         return -1
61     }
62     gdb_load $binfile
63     gdb_test "tstop"       "" ""
64     gdb_test "tfind none"  "" ""
65     runto_main
66 }
67 gdb_reinitialize_dir $srcdir/$subdir
68
69 # We generously give ourselves one "pass" if we successfully 
70 # detect that this test cannot be run on this target!
71 if { ![gdb_target_supports_trace] } then {
72     pass "Current target does not supporst trace"
73     return 1;
74
75 }
76
77 #
78 # test backtraces in trace frames
79 #
80
81 set testline1 0
82 set testline2 0
83 set testline3 0
84 set testline4 0
85 set testline5 0
86 set testline6 0
87
88 set arg1 1
89 set arg2 2
90 set arg3 3
91 set arg4 4
92 set arg5 5
93 set arg6 6
94
95 set baseline [gdb_find_recursion_test_baseline $srcfile];
96 if { $baseline == -1 } {
97     fail "Could not find gdb_recursion_test function"
98     return;
99 }
100
101 send_gdb "list $baseline, +12\n"
102 gdb_expect {
103     -re "\[\r\n\](\[0-9\]+).*gdbtestline 1 " {
104         set testline1 $expect_out(1,string)
105         exp_continue
106     }
107     -re "\[\r\n\](\[0-9\]+).*gdbtestline 2 " {
108         set testline2 $expect_out(1,string)
109         exp_continue
110     }
111     -re "\[\r\n\](\[0-9\]+).*gdbtestline 3 " {
112         set testline3 $expect_out(1,string)
113         exp_continue
114     }
115     -re "\[\r\n\](\[0-9\]+).*gdbtestline 4 " {
116         set testline4 $expect_out(1,string)
117         exp_continue
118     }
119     -re "\[\r\n\](\[0-9\]+).*gdbtestline 5 " {
120         set testline5 $expect_out(1,string)
121         exp_continue
122     }
123     -re "\[\r\n\](\[0-9\]+).*gdbtestline 6 " {
124         set testline6 $expect_out(1,string)
125         exp_continue
126     }
127     -re ".*$gdb_prompt $" {
128         if { ($testline1 == 0) || ($testline2 == 0) || ($testline3 == 0) || ($testline4 == 0) || ($testline5 == 0) || ($testline6 == 0) } {
129             untested backtrace.exp
130             return -1
131 all tests in this module will fail."
132         }
133     }
134     default {
135             untested backtrace.exp
136             return -1
137 all tests in this module will fail."
138     } 
139 }
140
141 #
142 # Setup backtrace experiment.  This will involve:
143 #   1) a tracepoint where nothing is collected
144 #   2) a tracepoint where only regs are collected
145 #   3) a tracepoint where regs, locals and args are collected
146 #   4) a tracepoint where regs plus some amount of stack are collected.
147 #
148
149 gdb_delete_tracepoints
150 set tdp2 [gdb_gettpnum $testline2]
151 set tdp3 [gdb_gettpnum $testline3]
152 set tdp4 [gdb_gettpnum $testline4]
153 set tdp5 [gdb_gettpnum $testline5]
154 set tdp6 [gdb_gettpnum $testline6]
155 if {    $tdp2 <= 0 || $tdp3 <= 0 || \
156         $tdp4 <= 0 || $tdp5 <= 0 || $tdp6 <= 0 } then {
157     fail "setting tracepoints failed"
158     return;
159 }
160
161 #gdb_trace_setactions "setup TP to collect FP" \
162 #       "$tdp2" \
163 #       "collect \$fp" ""
164 #
165
166 gdb_trace_setactions "8.6: setup TP to collect regs" \
167         "$tdp3" \
168         "collect \$regs" "^$"
169
170 gdb_trace_setactions "8.6: setup TP to collect regs, args, and locals" \
171         "$tdp4" \
172         "collect \$regs, \$args, \$locs" "^$"
173
174 gdb_trace_setactions "8.6: setup TP to collect stack mem cast expr" \
175         "$tdp6" \
176         "collect \$fp, \(\*\(void \*\*\) \(\$sp\)\) @ 64" "^$"
177
178 gdb_test "tstart" "" ""
179
180 if [istarget "m68k-*-elf"] then {
181     gdb_emclaptop_command "85,$arg1,$arg2,$arg3,$arg4,$arg5,$arg6"
182     sleep 5
183 } else {
184     gdb_test "break end" "" ""
185     gdb_test "continue" \
186             "Continuing.*Breakpoint $decimal, end.*" \
187             "run trace experiment"
188 }
189
190 gdb_test "tstop" "" ""
191
192 proc gdb_backtrace_tdp_1 { msg } {
193     global gdb_prompt
194     
195     # We are in a trace frame at which we didn't collect anything
196     # except $PC.  Therefore we expect to be able to identify stack
197     # frame #0, but that's about all.  In particular we do not expect
198     # to be able to display the function's arguments or locals, and we
199     # do not expect to be able to identify the caller of this function.
200     
201     send_gdb "backtrace\n"
202     gdb_expect {
203         -re "#0\[\t \]+gdb_recursion_test.*depth=.*$gdb_prompt $" {
204             pass "$msg"
205         }
206         -re ".*$gdb_prompt $" {
207             fail "$msg"
208         }
209         timeout { fail "$msg (timeout)" }
210     }
211 }
212
213 proc gdb_backtrace_tdp_2 { msg } {
214     global gdb_prompt
215
216     # We are in a trace frame at which we collected only the registers
217     # Therefore we expect to be able to identify stack frame #0, but
218     # we don't expect to be able to display its args unles they are
219     # passed in registers (which isn't the case for m68k), and we
220     # don't expect to be able to identify the caller's stack frame.
221
222     send_gdb "backtrace\n"
223     gdb_expect {
224         -re "#0\[\t \]+gdb_recursion_test.*depth=.*$gdb_prompt $" {
225             pass "$msg"
226         }
227         -re ".*$gdb_prompt $" {
228             fail "$msg"
229         }
230         timeout { fail "$msg (timeout)" }
231     }
232 }
233
234 proc gdb_backtrace_tdp_3 { msg } {
235     global gdb_prompt
236
237     # We are in a trace frame at which we collected all registers, all
238     # arguments and all locals.  This means that the display of
239     # stack frame #0 should be complete (including argument values).
240
241     send_gdb "backtrace\n"
242     gdb_expect {
243         -re "#0\[\t \]+gdb_recursion_test.*depth=\[0-9\]+.*q1=\[0-9\]+.*q2=\[0-9\]+.*q3=\[0-9\]+.*q4=\[0-9\]+.*q5=\[0-9\]+.*q6=\[0-9\]+.*$gdb_prompt $" {
244             pass "$msg"
245         }
246         -re "#0\[\t \]+gdb_recursion_test.*depth=Cannot access.*$gdb_prompt $" {
247             fail "$msg (failed to collect arguments)"
248         }
249         -re ".*$gdb_prompt $" {
250             fail "$msg"
251         }
252         timeout { fail "$msg (timeout)" }
253     }
254 }
255
256 proc gdb_backtrace_tdp_4 { msg depth } {
257     global gdb_prompt
258
259     # We are in a trace frame at which we collected all registers,
260     # plus a sizeable hunk of stack memory.  This should enable us to
261     # display at least several stack frames worth of backtrace.  We'll
262     # assume that if we can't display at least "depth" levels (with
263     # args), it counts as an error.
264
265     send_gdb "backtrace\n"
266     gdb_expect {
267         -re "#$depth\[\t \].*gdb_recursion_test.*depth=\[0-9\]+.*q1=\[0-9\]+.*q2=\[0-9\]+.*q3=\[0-9\]+.*q4=\[0-9\]+.*q5=\[0-9\]+.*q6=\[0-9\]+.*$gdb_prompt $" {
268             pass "$msg"
269         }
270         -re "#$depth\[\t \].*gdb_recursion_test.*depth=.*$gdb_prompt $" {
271             fail "$msg (args missing from #$depth stack frame)"
272         }
273         -re "#\[0-9\]+\[\t \].*gdb_recursion_test.*depth=.*$gdb_prompt $" {
274             fail "$msg (fewer than $depth stack frames found)"
275         }
276         -re ".*$gdb_prompt $" {
277             fail "$msg"
278         }
279         timeout { fail "$msg (timeout)" }
280     }
281 }
282
283 #
284 # begin backtrace test
285 #
286
287 set timeout 60
288
289 gdb_tfind_test "init: make sure not debugging any trace frame" "none" "-1"
290
291 gdb_tfind_test "8.6: find start frame" "start" "0"
292 gdb_test "printf \"TDP \%d:\\n\", \$tracepoint" \
293         "TDP $tdp2:" ""
294 gdb_backtrace_tdp_1 "8.6: Backtrace, depth == 1, collect nothing"
295
296 gdb_tfind_test "8.6: find frame 1"     "1" "1"
297 gdb_test "printf \"TDP \%d:\\n\", \$tracepoint" \
298         "TDP $tdp3:" ""
299 gdb_backtrace_tdp_2 "8.6: Backtrace, depth == 1, collect regs"
300
301 gdb_tfind_test "8.6: find frame 2"     "2" "2"
302 gdb_test "printf \"TDP \%d:\\n\", \$tracepoint" \
303         "TDP $tdp4:" ""
304 gdb_backtrace_tdp_3 "8.6: Backtrace, depth == 1, collect args and locals"
305
306
307 gdb_tfind_test "8.6: find frame 4"     "4" "4"
308 gdb_test "printf \"TDP \%d:\\n\", \$tracepoint" \
309         "TDP $tdp6:" ""
310 gdb_backtrace_tdp_4 "8.6: Backtrace, depth == 1, collect stack mem expr" "0"
311
312 gdb_tfind_test "8.6: find frame 5"     "5" "5"
313 gdb_test "printf \"TDP \%d:\\n\", \$tracepoint" \
314         "TDP $tdp2:" ""
315 gdb_backtrace_tdp_1 "8.6: Backtrace, depth == 2, collect nothing"
316
317 gdb_tfind_test "8.6: find frame 6"     "6" "6"
318 gdb_test "printf \"TDP \%d:\\n\", \$tracepoint" \
319         "TDP $tdp3:" ""
320 gdb_backtrace_tdp_2 "8.6: Backtrace, depth == 2, collect regs"
321
322 gdb_tfind_test "8.6: find frame 7"     "7" "7"
323 gdb_test "printf \"TDP \%d:\\n\", \$tracepoint" \
324         "TDP $tdp4:" ""
325 gdb_backtrace_tdp_3 "8.6: Backtrace, depth == 2, collect args and locals"
326
327
328 gdb_tfind_test "8.6: find frame 9"     "9" "9"
329 gdb_test "printf \"TDP \%d:\\n\", \$tracepoint" \
330         "TDP $tdp6:" ""
331 gdb_backtrace_tdp_4 "8.6: Backtrace, depth == 1, collect stack mem expr" "0"
332
333 gdb_tfind_test "8.6: find frame 10"    "10" "10"
334 gdb_test "printf \"TDP \%d:\\n\", \$tracepoint" \
335         "TDP $tdp2:" ""
336 gdb_backtrace_tdp_1 "8.6: Backtrace, depth == 3, collect nothing"
337
338 gdb_tfind_test "8.6: find frame 11"    "11" "11"
339 gdb_test "printf \"TDP \%d:\\n\", \$tracepoint" \
340         "TDP $tdp3:" ""
341 gdb_backtrace_tdp_2 "8.6: Backtrace, depth == 3, collect regs"
342
343 gdb_tfind_test "8.6: find frame 12"    "12" "12"
344 gdb_test "printf \"TDP \%d:\\n\", \$tracepoint" \
345         "TDP $tdp4:" ""
346 gdb_backtrace_tdp_3 "8.6: Backtrace, depth == 3, collect args and locals"
347
348
349 gdb_tfind_test "8.6: find frame 14"    "14" "14"
350 gdb_test "printf \"TDP \%d:\\n\", \$tracepoint" \
351         "TDP $tdp6:" ""
352 gdb_backtrace_tdp_4 "8.6: Backtrace, depth == 1, collect stack mem expr" "0"
353
354 gdb_tfind_test "8.6: find frame 15"    "15" "15"
355 gdb_test "printf \"TDP \%d:\\n\", \$tracepoint" \
356         "TDP $tdp2:" ""
357 gdb_backtrace_tdp_1 "8.6: Backtrace, depth == 4, collect nothing"
358
359 gdb_tfind_test "8.6: find frame 16"    "16" "16"
360 gdb_test "printf \"TDP \%d:\\n\", \$tracepoint" \
361         "TDP $tdp3:" ""
362 gdb_backtrace_tdp_2 "8.6: Backtrace, depth == 4, collect regs"
363
364 gdb_tfind_test "8.6: find frame 17"    "17" "17"
365 gdb_test "printf \"TDP \%d:\\n\", \$tracepoint" \
366         "TDP $tdp4:" ""
367 gdb_backtrace_tdp_3 "8.6: Backtrace, depth == 4, collect args and locals"
368
369
370 gdb_tfind_test "8.6: find frame 19"    "19" "19"
371 gdb_test "printf \"TDP \%d:\\n\", \$tracepoint" \
372         "TDP $tdp6:" ""
373 gdb_backtrace_tdp_4 "8.6: Backtrace, depth == 1, collect stack mem expr" "0"
374
375 gdb_test "printf \"x \%d x\\n\", depth == 3" \
376         "x 0 x" \
377         "1.13: trace in recursion: depth not equal to 3"
378
379 # Finished!
380 gdb_test "tfind none" "" ""