Fix PR gdb/18653: gdb disturbs inferior's inherited signal dispositions
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.gdb / selftest.exp
1 # Copyright 1988-2016 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 Rob Savoye. (rob@cygnus.com)
17
18 load_lib selftest-support.exp
19
20 # Not all of the lines of code near the start of main are executed for
21 # every machine. Also, optimization may reorder some of the lines.
22 # So all we do is try to step or next over everything until we get
23 # to a line that we know is always executed.
24
25 proc do_steps_and_nexts {} {
26 global gdb_prompt
27 global srcdir
28
29 gdb_reinitialize_dir $srcdir/..
30
31 set unlikely_line 0
32 for {set count 0} {$count < 32} {incr count} {
33 # NOTE: carlton/2002-12-11: The "initial brace" and
34 # "current_directory initialization" possibilities happen to
35 # me with GCC 3.1 on i686-pc-linux-gnu when I compile with
36 # optimization.
37 gdb_test_multiple "list" "list" {
38 -re ".*context = \\(struct captured_main_args \\*\\) data.*$gdb_prompt $" {
39 set description "step over context initialization"
40 set command "step"
41 }
42 -re ".*argc = context->argc.*$gdb_prompt $" {
43 set description "step over argc initialization"
44 set command "step"
45 }
46 -re ".*argv = context->argv.*$gdb_prompt $" {
47 set description "step over argv initialization"
48 set command "step"
49 }
50 -re ".*quiet = 0.*$gdb_prompt $" {
51 set description "step over quiet initialization"
52 set command "step"
53 }
54 -re ".*batch = 0.*$gdb_prompt $" {
55 set description "step over batch initialization"
56 set command "step"
57 }
58 -re ".*symarg = NULL.*$gdb_prompt $" {
59 set description "step over symarg initialization"
60 set command "step"
61 }
62 -re ".*execarg = NULL.*$gdb_prompt $" {
63 set description "step over execarg initialization"
64 set command "step"
65 }
66 -re ".*pidarg = NULL.*$gdb_prompt $" {
67 set description "step over pidarg initialization"
68 set command "step"
69 }
70 -re ".*corearg = NULL.*$gdb_prompt $" {
71 set description "step over corearg initialization"
72 set command "step"
73 }
74 -re ".*pid_or_core_arg = NULL.*$gdb_prompt $" {
75 set description "step over pid_or_core_arg initialization"
76 set command "step"
77 }
78 -re ".*cdarg = NULL.*$gdb_prompt $" {
79 set description "step over cdarg initialization"
80 set command "step"
81 }
82 -re ".*ttyarg = NULL.*$gdb_prompt $" {
83 set description "step over ttyarg initialization"
84 set command "step"
85 }
86 -re ".*cmdarg_vec = NULL.*$gdb_prompt $" {
87 set description "step over cmdarg_vec initialization"
88 set command "step"
89 }
90 -re ".*pre_stat_chain = make_command_stats_cleanup.*$gdb_prompt $" {
91 set description "next over make_command_stats_cleanup and everything it calls"
92 set command "next"
93 }
94 -re ".*START_PROGRESS.*$gdb_prompt $" {
95 # Note: ezannoni/2004/02/17: This check should be
96 # removed, since as of today that source line is not
97 # in gdb anymore.
98 set description "next over START_PROGRESS and everything it calls"
99 set command "next"
100 }
101 -re ".*mac_init.*$gdb_prompt $" {
102 set description "next over mac_init and everything it calls"
103 set command "next"
104 }
105 -re ".*init_malloc.*$gdb_prompt $" {
106 # gdb 6.2.X is the last gdb which called init_malloc
107 set description "next over init_malloc and everything it calls"
108 set command "next"
109 }
110 -re ".*lim_at_start.*$gdb_prompt $" {
111 set description "next over lim_at_start initialization"
112 set command "next"
113 }
114 -re ".*TRY.*$gdb_prompt $" {
115 set description "next over TRY"
116 set command "next"
117 }
118 -re ".*captured_main \\(args\\);.*$gdb_prompt $" {
119 set description "step into captured_main (args)"
120 set command "step"
121 }
122 -re ".*count . 0x3.*$gdb_prompt $" {
123 set description "next over conditional stack alignment code 1"
124 set command "next"
125 }
126 -re ".*if .i != 0.*$gdb_prompt $" {
127 set description "next over conditional stack alignment code 2"
128 set command "next"
129 }
130 -re ".*alloca .i - 4.*$gdb_prompt $" {
131 set description "next over conditional stack alignment alloca"
132 set command "next"
133 }
134 -re ".*dirsize = 1.*$gdb_prompt $" {
135 set description "next over dirsize initialization"
136 set command "next"
137 }
138 -re ".*dirarg = .* xmalloc.*$gdb_prompt $" {
139 return
140 }
141 -re ".*setlocale .LC_MESSAGES,.*$gdb_prompt $" {
142 set description "next over setlocale LC_MESSAGES"
143 set command "next"
144 }
145 -re ".*setlocale .LC_CTYPE,.*$gdb_prompt $" {
146 set description "next over setlocale LC_CTYPE"
147 set command "next"
148 }
149 -re ".*bindtextdomain .PACKAGE, LOCALEDIR.;.*$gdb_prompt $" {
150 set description "next over bindtextdomain"
151 set command "next"
152 }
153 -re ".*textdomain .PACKAGE.;.*$gdb_prompt $" {
154 set description "next over textdomain PACKAGE"
155 set command "next"
156 }
157 -re ".*bfd_init ..;.*$gdb_prompt $" {
158 set description "next over bfd_init"
159 set command "next"
160 }
161 -re ".*notice_open_fds ..;.*$gdb_prompt $" {
162 set description "next over notice_open_fds"
163 set command "next"
164 }
165 -re ".*save_original_signals_state ..;.*$gdb_prompt $" {
166 set description "next over save_original_signals_state"
167 set command "next"
168 }
169 -re ".*VEC_cleanup .cmdarg_s.*$gdb_prompt $" {
170 set description "next over cmdarg_s VEC_cleanup"
171 set command "next"
172 }
173 -re "\[0-9\]+\[\t \]+\{\r\n$gdb_prompt $" {
174 set description "step over initial brace"
175 set command "step"
176 }
177 -re ".*current_directory = gdb_dirbuf.*$gdb_prompt $" {
178 set description "step over current_directory initialization"
179 set command "step"
180 }
181 -re ".*gdb_sysroot = .*$gdb_prompt $" {
182 # NOTE: carlton/2003-01-15: More optimization reordering,
183 # observed on GCC 3.1.
184 set description "step over gdb_sysroot initialization"
185 set command "step"
186 }
187 -re ".*ndir = 0.*$gdb_prompt $" {
188 set description "step over ndir initialization"
189 set command "step"
190 }
191 -re ".*instream = stdin.*$gdb_prompt $" {
192 set description "step over instream initialization"
193 set command "step"
194 }
195 -re ".*getcwd .gdb_dirbuf, sizeof .gdb_dirbuf.*$gdb_prompt $" {
196 set description "next over getcwd"
197 set command "next"
198 }
199 -re ".*gdb_program_name = xstrdup.*$gdb_prompt $" {
200 set description "next over xstrdup"
201 set command "next"
202 }
203 -re ".*quit_flag = 0.*$gdb_prompt $" {
204 set description "step over quit_flag initialization"
205 set command "step"
206 }
207 -re ".*gdb_stdout = stdio_fileopen .stdout.;.*$gdb_prompt $" {
208 set description "step over gdb_stdout initialization"
209 set command "step"
210 }
211 -re ".*gdb_stderr = stdio_fileopen .stderr.;.*$gdb_prompt $" {
212 set description "step over gdb_stderr initialization"
213 set command "step"
214 }
215 -re "ui = current_ui.*$gdb_prompt $" {
216 set description "step over top_level initialization"
217 set command "step"
218 }
219 -re ".*main.c.*No such file or directory.*$gdb_prompt $" {
220 setup_xfail "rs6000-*-aix3*"
221 fail "must be able to list source lines"
222 return
223 }
224 -re ".*interpreter_p = xstrdup.*$gdb_prompt $" {
225 if { $unlikely_line == 0 } {
226 # This is a GCC optimization bug; a constant has been
227 # associated with the wrong line number.
228 setup_xfail "*-*-*" gcc/26475
229 fail "$description (unlikely line from gcc)"
230 set unlikely_line 1
231 }
232 set description "next over xstrdup"
233 set command "next"
234 }
235 -re ".*$gdb_prompt $" {
236 # If $description hasn't been set yet, it's likely the file
237 # has been edited but gdb hasn't been recompiled.
238 if [info exists description] {
239 fail "unknown source line (after $description)"
240 } else {
241 fail "unknown source line"
242 }
243 return
244 }
245 default {
246 fail "unknown source line near main"
247 return
248 }
249 }
250 gdb_test_multiple "$command" "$description" {
251 -re ".*No such file or directory.\r\n$gdb_prompt $" {
252 fail "$description (no source available)"
253 }
254 -re ".*A file or directory .* does not exist..\r\n$gdb_prompt $" {
255 fail "$description (no source available)"
256 }
257 -re ".*$gdb_prompt $" {
258 pass "$description"
259 }
260 }
261 }
262 }
263
264 proc test_with_self { } {
265 global gdb_prompt
266 global decimal
267 global timeout
268 global inferior_spawn_id
269
270 # When GDB is built as a C++ program, disassemble shows the full
271 # prototype.
272 set cxx_main_args_re [string_to_regexp "(int, char**)"]
273
274 # disassemble yourself
275 gdb_test "x/10i main" \
276 "x/10i.*main.*main($cxx_main_args_re)?.$decimal.*main($cxx_main_args_re)?.$decimal.*" \
277 "Disassemble main"
278
279 # We'll need this when we send a ^C to GDB. Need to do it before we
280 # run the program and gdb starts saving and restoring tty states.
281 gdb_test "shell stty intr '^C'" ".*" \
282 "set interrupt character in test_with_self"
283
284 # FIXME: If we put this after the run to main, the first list
285 # command doesn't print the same line as the current line where
286 # gdb is stopped.
287 gdb_test_no_output "set listsize 1" "set listsize to 1"
288
289 # do we have a version number ?
290 gdb_test_multiple "print version" "printed version" {
291 -re ".\[0-9\]+ = .\[0-9.\]+.*$gdb_prompt $" {
292 pass "printed version as string"
293 }
294 -re ".\[0-9\]+ = +0x.*\[0-9.\]+.*$gdb_prompt $" {
295 pass "printed version as pointer"
296 }
297 -re ".\[0-9\]+ = +.+ +0x.*\[0-9.\]+.*$gdb_prompt $" {
298 pass "printed version with cast"
299 }
300 }
301
302 do_steps_and_nexts
303
304 gdb_test "print \"foo\"" ".\[0-9\]+ = \"foo\"" "print a string"
305
306 # do_steps_and_nexts left us ready to execute an xmalloc call,
307 # so give that a try.
308 # If we don't actually enter the xmalloc call when we give a
309 # step command that seems like a genuine bug. It seems to happen
310 # on most RISC processors.
311 # NOTE drow/2003-06-22: However, if we step back to the preceding two
312 # lines, just keep stepping until we enter.
313 set stepped_back 0
314 setup_xfail "alpha-*-*" "mips-*-*"
315 set description "step into xmalloc call"
316 gdb_test_multiple "step" "$description" {
317 -re "ncmd = 0;.*$gdb_prompt $" {
318 set stepped_back 1
319 send_gdb "step\n"
320 exp_continue
321 }
322 -re ".*cmdarg = .* xmalloc.*$gdb_prompt $" {
323 set stepped_back 1
324 send_gdb "step\n"
325 exp_continue
326 }
327 -re "dirsize = 1;.*$gdb_prompt $" {
328 set stepped_back 1
329 send_gdb "step\n"
330 exp_continue
331 }
332 -re ".*dirarg = .* xmalloc.*$gdb_prompt $" {
333 if { $stepped_back == 1 } {
334 send_gdb "step\n"
335 exp_continue
336 } else {
337 fail "$description"
338 }
339 }
340 -re "xmalloc.*size=.*at.*utils.c.*$gdb_prompt $" {
341 pass "$description"
342 }
343 -re ".*No such file or directory.\r\n$gdb_prompt $" {
344 pass "$description (no source available)"
345 }
346 -re "A file or directory .* does not exist..\r\n$gdb_prompt $" {
347 pass "$description (no source available)"
348 }
349 }
350
351 # start the "xgdb" process
352 if [target_info exists gdb,noinferiorio] {
353 # With no way to interact with the inferior GDB, all we can do
354 # is let it run.
355 send_gdb "continue\n"
356 # Wait a bit while the inferior gdb gets to its prompt.
357 sleep 1
358 } else {
359 set test "xgdb is at prompt"
360 gdb_test_multiple "continue" $test {
361 -i "$inferior_spawn_id"
362 -re "GNU gdb \[0-9\.\]*.*Copyright \\(C\\) \[0-9\]* Free Software Foundation, Inc.*License GPLv3\\+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.*This is free software: you are free to change and redistribute it.*There is NO WARRANTY, to the extent permitted by law. Type \"show copying\".*and \"show warranty\" for details.*This GDB was configured as .*$gdb_prompt $" {
363 pass $test
364 }
365 }
366
367 # set xgdb prompt so we can tell which is which
368 send_inferior "set prompt (xgdb) \n"
369 set msg "Set xgdb_prompt"
370 gdb_test_multiple "" $msg {
371 -i "$inferior_spawn_id"
372 -re "\[(\]xgdb\[)\].*\[(\]xgdb\[)\] $" {
373 pass $msg
374 }
375 }
376 }
377
378 # kill the xgdb process
379 if ![target_info exists gdb,nointerrupts] {
380 set description "send ^C to child process"
381 send_gdb "\003"
382 # "Thread 1" is displayed iff Guile support is linked in.
383 gdb_expect {
384 -re "(Thread .*|Program) received signal SIGINT.*$gdb_prompt $" {
385 pass "$description"
386 }
387 -re ".*$gdb_prompt $" {
388 fail "$description"
389 }
390 timeout {
391 fail "$description (timeout)"
392 }
393 }
394 }
395
396 set description "send SIGINT signal to child process"
397 gdb_test "signal SIGINT" \
398 "Continuing with signal SIGINT.*" \
399 "$description"
400
401 # Switch back to the GDB thread if Guile support is linked in.
402 # "signal SIGINT" could also switch the current thread.
403 gdb_test "thread 1" {\[Switching to thread 1 .*\].*}
404
405 # get a stack trace
406 #
407 # This fails on some linux systems for unknown reasons. On the
408 # systems where it fails, sometimes it works fine when run manually.
409 # The testsuite failures may not be limited to just aout systems.
410 setup_xfail "i*86-pc-linuxaout-gnu"
411 set description "backtrace through signal handler"
412 gdb_test_multiple "backtrace" "$description" {
413 -re "#0.*(read|poll).*in main \\(.*\\) at .*gdb\\.c.*$gdb_prompt $" {
414 pass "$description"
415 }
416 }
417
418 # Restart gdb in case next test expects it to be started already.
419 return 0
420 }
421
422 do_self_tests captured_main test_with_self
This page took 0.040016 seconds and 4 git commands to generate.