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