Update copyright year range in header of all files managed by GDB
[binutils-gdb.git] / gdb / testsuite / gdb.gdb / selftest.exp
blob177c29fb224d0858068556f41ffa196d42ed1b70
1 # Copyright 1988-2023 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 proc test_with_self { } {
21     global gdb_prompt
22     global decimal
23     global timeout
24     global inferior_spawn_id
26     # When GDB is built as a C++ program, disassemble shows the full
27     # prototype.
28     set cxx_main_args_re [string_to_regexp "(int, char**)"]
30     # disassemble yourself
31     gdb_test "x/10i main" \
32             "x/10i.*main.*main($cxx_main_args_re)?.$decimal.*main($cxx_main_args_re)?.$decimal.*" \
33             "disassemble main"
35     # We'll need this when we send a ^C to GDB.  Need to do it before we
36     # run the program and gdb starts saving and restoring tty states.
37     gdb_test "shell stty intr '^C'" ".*" \
38         "set interrupt character in test_with_self"
40     # FIXME: If we put this after the run to main, the first list
41     # command doesn't print the same line as the current line where
42     # gdb is stopped.
43     gdb_test_no_output "set listsize 1" "set listsize to 1"
45     # do we have a version number ?
46     gdb_test_multiple "print version" "printed version" {
47         -re ".\[0-9\]+ = .\[0-9.\]+.*$gdb_prompt $" {
48             pass "printed version as string"
49         }
50         -re ".\[0-9\]+ = +0x.*\[0-9.\]+.*$gdb_prompt $" {
51             pass "printed version as pointer"
52         }
53         -re ".\[0-9\]+ = +.+ +0x.*\[0-9.\]+.*$gdb_prompt $" {
54             pass "printed version with cast"
55         }
56     }
58     # start the "xgdb" process
59     if [target_info exists gdb,noinferiorio] {
60         # With no way to interact with the inferior GDB, all we can do
61         # is let it run.
62         send_gdb "continue\n"
63         # Wait a bit while the inferior gdb gets to its prompt.
64         sleep 1
65     } else {
66         set banner [multi_line \
67                         "GNU gdb \[0-9\.\]*\[^\r\n\]*" \
68                         "Copyright \\(C\\) \[0-9\]* Free Software Foundation, Inc\." \
69                         "License GPLv3\\+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>" \
70                         "This is free software: you are free to change and redistribute it\." \
71                         "There is NO WARRANTY, to the extent permitted by law\." \
72                         "Type \"show copying\" and \"show warranty\" for details\." \
73                         "This GDB was configured as .*" \
74                         "$gdb_prompt $"]
75         set test "xgdb is at prompt"
76         gdb_test_multiple "continue" $test {
77             -i "$inferior_spawn_id"
78             -re "received signal SIGSEGV.* in GC_.*$gdb_prompt" {
79                 # Some versions of the GC used by Guile cause a SEGV
80                 # during stack probing.  Ignore this and carry on.
81                 send_gdb "continue\n"
82                 exp_continue
83             }
84             -re "$banner" {
85                 pass $test
86             }
87         }
89         # set xgdb prompt so we can tell which is which
90         send_inferior "set prompt (xgdb) \n"
91         set msg "Set xgdb_prompt"
92         gdb_test_multiple "" $msg {
93             -i "$inferior_spawn_id"
94             -re "\[(\]xgdb\[)\].*\[(\]xgdb\[)\] $" {
95                 pass $msg
96             }
97         }
98     }
100     # kill the xgdb process
101     if ![target_info exists gdb,nointerrupts] {
102         set description "send ^C to child process"
103         send_gdb "\003"
104         # "Thread 1" is displayed iff Guile support is linked in.
105         gdb_expect {
106             -re "(Thread .*|Program) received signal SIGINT.*$gdb_prompt $" {
107                 pass "$description"
108             }
109             -re ".*$gdb_prompt $" {
110                 fail "$description"
111             }
112             timeout {
113                 fail "$description (timeout)"
114             }
115         }
116     }
117     
118     set description "send SIGINT signal to child process"
119     gdb_test_multiple "signal SIGINT" "$description" {
120         -re "^signal SIGINT\r\nContinuing with signal SIGINT.\r\nQuit\r\n.* $" {
121             pass "$description"
122         }
123     }
125     set description "send ^C to child process again"
126     send_gdb "\003"
127     gdb_expect {
128         -re "(Thread .*|Program) received signal SIGINT.*$gdb_prompt $" {
129             pass "$description"
130         }
131         -re ".*$gdb_prompt $" {
132             fail "$description"
133         }
134         timeout {
135             fail "$description (timeout)"
136         }
137     }
140     # Switch back to the GDB thread if Guile support is linked in.
141     # "signal SIGINT" could also switch the current thread.
142     gdb_test "thread 1" {\[Switching to thread 1 .*\].*}
143     
144     # get a stack trace
145     #
146     # This fails on some linux systems for unknown reasons.  On the
147     # systems where it fails, sometimes it works fine when run manually.
148     # The testsuite failures may not be limited to just aout systems.
149     setup_xfail "i*86-pc-linuxaout-gnu"
150     set description "backtrace through signal handler"
151     gdb_test_multiple "backtrace" "$description" {
152         -re "#0.*(read|poll).* main \\(.*\\) at .*gdb\\.c.*$gdb_prompt $" {
153             pass "$description"
154         }
155     }
157     # Restart gdb in case next test expects it to be started already.
158     return 0
161 do_self_tests captured_main test_with_self