1 # Copyright 1988-2016 Free Software Foundation, Inc.
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.
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.
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/>.
16 # This file was written by Rob Savoye. (rob@cygnus.com)
18 load_lib selftest-support.exp
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.
25 proc do_steps_and_nexts {} {
29 gdb_reinitialize_dir $srcdir/..
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
37 gdb_test_multiple "list" "list" {
38 -re ".*context = \\(struct captured_main_args \\*\\) data.*$gdb_prompt $" {
39 set description "step over context initialization"
42 -re ".*argc = context->argc.*$gdb_prompt $" {
43 set description "step over argc initialization"
46 -re ".*argv = context->argv.*$gdb_prompt $" {
47 set description "step over argv initialization"
50 -re ".*quiet = 0.*$gdb_prompt $" {
51 set description "step over quiet initialization"
54 -re ".*batch = 0.*$gdb_prompt $" {
55 set description "step over batch initialization"
58 -re ".*symarg = NULL.*$gdb_prompt $" {
59 set description "step over symarg initialization"
62 -re ".*execarg = NULL.*$gdb_prompt $" {
63 set description "step over execarg initialization"
66 -re ".*pidarg = NULL.*$gdb_prompt $" {
67 set description "step over pidarg initialization"
70 -re ".*corearg = NULL.*$gdb_prompt $" {
71 set description "step over corearg initialization"
74 -re ".*pid_or_core_arg = NULL.*$gdb_prompt $" {
75 set description "step over pid_or_core_arg initialization"
78 -re ".*cdarg = NULL.*$gdb_prompt $" {
79 set description "step over cdarg initialization"
82 -re ".*ttyarg = NULL.*$gdb_prompt $" {
83 set description "step over ttyarg initialization"
86 -re ".*cmdarg_vec = NULL.*$gdb_prompt $" {
87 set description "step over cmdarg_vec initialization"
90 -re ".*pre_stat_chain = make_command_stats_cleanup.*$gdb_prompt $" {
91 set description "next over make_command_stats_cleanup and everything it calls"
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
98 set description "next over START_PROGRESS and everything it calls"
101 -re ".*mac_init.*$gdb_prompt $" {
102 set description "next over mac_init and everything it calls"
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"
110 -re ".*lim_at_start.*$gdb_prompt $" {
111 set description "next over lim_at_start initialization"
114 -re ".*TRY.*$gdb_prompt $" {
115 set description "next over TRY"
118 -re ".*captured_main \\(args\\);.*$gdb_prompt $" {
119 set description "step into captured_main (args)"
122 -re ".*count . 0x3.*$gdb_prompt $" {
123 set description "next over conditional stack alignment code 1"
126 -re ".*if .i != 0.*$gdb_prompt $" {
127 set description "next over conditional stack alignment code 2"
130 -re ".*alloca .i - 4.*$gdb_prompt $" {
131 set description "next over conditional stack alignment alloca"
134 -re ".*dirsize = 1.*$gdb_prompt $" {
135 set description "next over dirsize initialization"
138 -re ".*dirarg = .* xmalloc.*$gdb_prompt $" {
141 -re ".*setlocale .LC_MESSAGES,.*$gdb_prompt $" {
142 set description "next over setlocale LC_MESSAGES"
145 -re ".*setlocale .LC_CTYPE,.*$gdb_prompt $" {
146 set description "next over setlocale LC_CTYPE"
149 -re ".*bindtextdomain .PACKAGE, LOCALEDIR.;.*$gdb_prompt $" {
150 set description "next over bindtextdomain"
153 -re ".*textdomain .PACKAGE.;.*$gdb_prompt $" {
154 set description "next over textdomain PACKAGE"
157 -re ".*bfd_init ..;.*$gdb_prompt $" {
158 set description "next over bfd_init"
161 -re ".*notice_open_fds ..;.*$gdb_prompt $" {
162 set description "next over notice_open_fds"
165 -re ".*save_original_signals_state ..;.*$gdb_prompt $" {
166 set description "next over save_original_signals_state"
169 -re ".*VEC_cleanup .cmdarg_s.*$gdb_prompt $" {
170 set description "next over cmdarg_s VEC_cleanup"
173 -re "\[0-9\]+\[\t \]+\{\r\n$gdb_prompt $" {
174 set description "step over initial brace"
177 -re ".*current_directory = gdb_dirbuf.*$gdb_prompt $" {
178 set description "step over current_directory initialization"
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"
187 -re ".*ndir = 0.*$gdb_prompt $" {
188 set description "step over ndir initialization"
191 -re ".*instream = stdin.*$gdb_prompt $" {
192 set description "step over instream initialization"
195 -re ".*getcwd .gdb_dirbuf, sizeof .gdb_dirbuf.*$gdb_prompt $" {
196 set description "next over getcwd"
199 -re ".*gdb_program_name = xstrdup.*$gdb_prompt $" {
200 set description "next over xstrdup"
203 -re ".*quit_flag = 0.*$gdb_prompt $" {
204 set description "step over quit_flag initialization"
207 -re ".*gdb_stdout = stdio_fileopen .stdout.;.*$gdb_prompt $" {
208 set description "step over gdb_stdout initialization"
211 -re ".*gdb_stderr = stdio_fileopen .stderr.;.*$gdb_prompt $" {
212 set description "step over gdb_stderr initialization"
215 -re "ui = current_ui.*$gdb_prompt $" {
216 set description "step over top_level initialization"
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"
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)"
232 set description "next over xstrdup"
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)"
241 fail "unknown source line"
246 fail "unknown source line near main"
250 gdb_test_multiple "$command" "$description" {
251 -re ".*No such file or directory.\r\n$gdb_prompt $" {
252 fail "$description (no source available)"
254 -re ".*A file or directory .* does not exist..\r\n$gdb_prompt $" {
255 fail "$description (no source available)"
257 -re ".*$gdb_prompt $" {
264 proc test_with_self { } {
268 global inferior_spawn_id
270 # When GDB is built as a C++ program, disassemble shows the full
272 set cxx_main_args_re [string_to_regexp "(int, char**)"]
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.*" \
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"
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
287 gdb_test_no_output "set listsize 1" "set listsize to 1"
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"
294 -re ".\[0-9\]+ = +0x.*\[0-9.\]+.*$gdb_prompt $" {
295 pass "printed version as pointer"
297 -re ".\[0-9\]+ = +.+ +0x.*\[0-9.\]+.*$gdb_prompt $" {
298 pass "printed version with cast"
304 gdb_test "print \"foo\"" ".\[0-9\]+ = \"foo\"" "print a string"
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.
314 setup_xfail "alpha-*-*" "mips-*-*"
315 set description "step into xmalloc call"
316 gdb_test_multiple "step" "$description" {
317 -re "ncmd = 0;.*$gdb_prompt $" {
322 -re ".*cmdarg = .* xmalloc.*$gdb_prompt $" {
327 -re "dirsize = 1;.*$gdb_prompt $" {
332 -re ".*dirarg = .* xmalloc.*$gdb_prompt $" {
333 if { $stepped_back == 1 } {
340 -re "xmalloc.*size=.*at.*utils.c.*$gdb_prompt $" {
343 -re ".*No such file or directory.\r\n$gdb_prompt $" {
344 pass "$description (no source available)"
346 -re "A file or directory .* does not exist..\r\n$gdb_prompt $" {
347 pass "$description (no source available)"
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
355 send_gdb "continue\n"
356 # Wait a bit while the inferior gdb gets to its prompt.
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 $" {
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\[)\] $" {
378 # kill the xgdb process
379 if ![target_info exists gdb,nointerrupts] {
380 set description "send ^C to child process"
382 # "Thread 1" is displayed iff Guile support is linked in.
384 -re "(Thread .*|Program) received signal SIGINT.*$gdb_prompt $" {
387 -re ".*$gdb_prompt $" {
391 fail "$description (timeout)"
396 set description "send SIGINT signal to child process"
397 gdb_test "signal SIGINT" \
398 "Continuing with signal SIGINT.*" \
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 .*\].*}
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 $" {
418 # Restart gdb in case next test expects it to be started already.
422 do_self_tests captured_main test_with_self