New test for follow-exec-mode
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.base / foll-exec-mode.exp
1 # Copyright 1997-2015 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 is a test of gdb's follow-exec-mode.
17 #
18 # It first checks that exec events are supported by using a catchpoint,
19 # then tests multiple scenarios for follow-exec-mode using parameters
20 # that test:
21 # - each mode
22 # - different commands to execute past the exec
23 # - re-running both the original and new inferiors.
24 #
25 # Note that we can't single-step past an exec call. There has to
26 # be a breakpoint in order to stop after the exec, even if we use
27 # a single-step command to execute past the exec.
28
29 if { [is_remote target] || ![isnative] } then {
30 continue
31 }
32
33 # Until "catch exec" is implemented on other targets...
34 #
35 if {![istarget "hppa*-hp-hpux*"] && ![istarget "*-linux*"]} then {
36 continue
37 }
38
39 standard_testfile foll-exec-mode.c
40
41 set testfile2 "execd-prog"
42 set srcfile2 ${testfile2}.c
43 set binfile2 [standard_output_file ${testfile2}]
44
45 set compile_options debug
46 set dirname [relative_filename [pwd] [file dirname $binfile]]
47 lappend compile_options "additional_flags=-DBASEDIR=\"$dirname\""
48
49 # build the first test case
50 if { [gdb_compile "${srcdir}/${subdir}/${srcfile2}" "${binfile2}" executable $compile_options] != "" } {
51 untested foll-exec-mode.exp
52 return -1
53 }
54
55 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable $compile_options] != "" } {
56 untested foll-exec-mode.exp
57 return -1
58 }
59
60 # Test exec catchpoints to ensure exec events are supported.
61 #
62 proc do_catch_exec_test { } {
63 global testfile
64 global gdb_prompt
65
66 clean_restart $testfile
67
68 # Start the program running, and stop at main.
69 #
70 if ![runto_main] then {
71 fail "Couldn't run ${testfile}"
72 return
73 }
74
75 # Verify that the system supports "catch exec".
76 gdb_test "catch exec" "Catchpoint \[0-9\]* \\(exec\\)" "insert first exec catchpoint"
77 set has_exec_catchpoints 0
78 gdb_test_multiple "continue" "continue to first exec catchpoint" {
79 -re ".*Your system does not support this type\r\nof catchpoint.*$gdb_prompt $" {
80 unsupported "continue to first exec catchpoint"
81 }
82 -re ".*Catchpoint.*$gdb_prompt $" {
83 set has_exec_catchpoints 1
84 pass "continue to first exec catchpoint"
85 }
86 }
87
88 if {$has_exec_catchpoints == 0} {
89 unsupported "exec catchpoints"
90 return
91 }
92 }
93
94 # Test follow-exec-mode in the specified scenario.
95 # MODE determines whether follow-exec-mode is "same" or "new".
96 # CMD determines the command used to execute past the exec call.
97 # INFSWITCH is ignored for MODE == "same", and for "new" it is
98 # used to determine whether to switch to the original inferior
99 # before re-running.
100
101 proc do_follow_exec_mode_tests { mode cmd infswitch } {
102 global binfile srcfile srcfile2 testfile testfile2
103 global gdb_prompt
104
105 with_test_prefix "$mode,$cmd,$infswitch" {
106 clean_restart $testfile
107
108 # Start the program running, and stop at main.
109 #
110 if ![runto_main] then {
111 fail "Couldn't run ${testfile}"
112 return
113 }
114
115 # Set the follow-exec mode.
116 #
117 gdb_test_no_output "set follow-exec-mode $mode"
118
119 # Run to the line of the exec call.
120 #
121 gdb_breakpoint [gdb_get_line_number "Set breakpoint here"]
122 gdb_continue_to_breakpoint "continue to line of exec call"
123
124 # Set up the output we expect to see after we execute past the exec.
125 #
126 set execd_line [gdb_get_line_number "after-exec" $srcfile2]
127 set expected_re ".*xecuting new program: .*${testfile2}.*Breakpoint .,.*${srcfile2}:${execd_line}.*$gdb_prompt $"
128
129 # Set a breakpoint after the exec call if we aren't single-stepping
130 # past it.
131 #
132 if {$cmd == "continue"} {
133 gdb_breakpoint "$execd_line"
134 }
135
136 # Execute past the exec call.
137 #
138 set test "$cmd past exec"
139 gdb_test_multiple $cmd $test {
140 -re "$expected_re" {
141 pass $test
142 }
143 }
144
145 # Set expected output, given the test parameters.
146 #
147 if {$mode == "same"} {
148 set expected_re "\\* 1.*process.*"
149 } else {
150 set expected_re "\\* 2.*process.*$testfile2 \r\n 1.*null.*$testfile.*"
151 }
152
153 # Check that the inferior list is correct:
154 # - one inferior for MODE == "same"
155 # - two inferiors for MODE == "new", current is execd program
156 #
157 gdb_test "info inferiors" $expected_re "Check inferior list"
158
159 set expected_inf ""
160 if {$mode == "same"} {
161 # One inferior, the execd program.
162 set expected_inf $testfile2
163 } elseif {$infswitch == "infswitch"} {
164 # Two inferiors, we have switched to the original program.
165 set expected_inf $testfile
166 gdb_test "inferior 1" "Switching to inferior 1.*$testfile.*" "Switch inferiors"
167 } else {
168 # Two inferiors, run the execd program
169 set expected_inf $testfile2
170 }
171
172 # Now check that a 'run' command will run the correct inferior.
173 #
174 set test "use correct executable ($expected_inf) for run after follow exec"
175 gdb_run_cmd
176 gdb_test_multiple "" $test {
177 -re {Start it from the beginning\? \(y or n\) $} {
178 send_gdb "y\n"
179 exp_continue
180 }
181 -re "Starting program: .*$expected_inf.*Breakpoint .,.*\r\n$gdb_prompt $" {
182 pass $test
183 }
184 }
185 }
186 }
187
188 do_catch_exec_test
189
190 foreach cmd {"next" "continue"} {
191 foreach mode {"same" "new"} {
192 # Test basic follow-exec-mode.
193 do_follow_exec_mode_tests $mode $cmd "no_infswitch"
194 if {$mode == "new"} {
195 # Test that when we do 'run' we get the correct executable.
196 do_follow_exec_mode_tests $mode $cmd "infswitch"
197 }
198 }
199 }
200
201 return 0
This page took 0.035025 seconds and 5 git commands to generate.