2012-01-16 Pedro Alves <palves@redhat.com>
[external/binutils.git] / gdb / testsuite / gdb.trace / while-dyn.exp
1 #   Copyright 1998, 2007-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 # This file was written by Michael Snyder (msnyder@cygnus.com)
17
18 load_lib "trace-support.exp"
19
20
21 gdb_exit
22 gdb_start
23
24 set testfile "actions"
25 set srcfile $testfile.c
26 set executable while-dyn
27 set binfile $objdir/$subdir/$executable
28 if { [gdb_compile "$srcdir/$subdir/$srcfile" $binfile \
29           executable {debug nowarnings}] != "" } {
30     untested while-dyn.exp
31     return -1
32 }
33 gdb_load $binfile
34 gdb_test "tstop"       ".*" ""
35 gdb_test "tfind none"  ".*" ""
36 runto_main
37 gdb_reinitialize_dir $srcdir/$subdir
38
39 # We generously give ourselves one "pass" if we successfully 
40 # detect that this test cannot be run on this target!
41 if { ![gdb_target_supports_trace] } then {
42     pass "Current target does not support trace"
43     return 1;
44 }
45
46 #
47 # test while-stepping dynamically (live target)
48 #
49
50 if [is_amd64_regs_target] {
51     set fpreg "\$rbp"
52 } elseif [is_x86_like_target] {
53     set fpreg "\$ebp"
54 } else {
55     set fpreg "\$fp"
56 }
57
58 proc test_while_stepping { while_stepping } {
59     global fpreg
60     global decimal
61     global gdb_prompt
62     global executable
63
64     clean_restart $executable
65
66     gdb_test "tstop" ".*" ""
67     gdb_test "tfind none" ".*" ""
68     runto_main
69
70     ## verify number of trace frames collected matches stepcount
71
72     gdb_delete_tracepoints
73     gdb_test "trace gdb_c_test" \
74         "Tracepoint $decimal at .*" \
75         "$while_stepping: Set tracepoint at gdb_c_test"
76
77     gdb_trace_setactions "5.12: define $while_stepping <stepcount>" \
78         "" \
79         "collect $fpreg" "^$" \
80         "$while_stepping 5" "^$" \
81         "collect p" "^$" \
82         "end" "^$" \
83         "end" ""
84
85     gdb_test "tstart" ".*" ""
86
87     gdb_test "break end" ".*" ""
88     gdb_test "continue" \
89         "Continuing.*Breakpoint $decimal, end.*" \
90         "$while_stepping: run trace experiment"
91
92     gdb_test "tstop" ".*" ""
93
94     gdb_tfind_test "$while_stepping: frame 5 should be the last one collected" "5" "5"
95
96     set test "$while_stepping: trace stopped after 5 stepping frames"
97     gdb_test_multiple "tfind 6" "$test" {
98         -re "failed to find.*$gdb_prompt $" {
99             pass "$test"
100         }
101         -re ".*$gdb_prompt $" {
102             fail "$test"
103         }
104     }
105
106     gdb_test "tfind none" ".*" ""
107 }
108
109 # Test all while-stepping aliases.
110
111 test_while_stepping "while-stepping"
112 test_while_stepping "stepping"
113 test_while_stepping "ws"