1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
|
# Copyright 1988-2017 Free Software Foundation, Inc.
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# This file was written by Rob Savoye. (rob@cygnus.com)
load_lib selftest-support.exp
proc test_with_self { } {
global gdb_prompt
global decimal
global timeout
global inferior_spawn_id
# When GDB is built as a C++ program, disassemble shows the full
# prototype.
set cxx_main_args_re [string_to_regexp "(int, char**)"]
# disassemble yourself
gdb_test "x/10i main" \
"x/10i.*main.*main($cxx_main_args_re)?.$decimal.*main($cxx_main_args_re)?.$decimal.*" \
"disassemble main"
# We'll need this when we send a ^C to GDB. Need to do it before we
# run the program and gdb starts saving and restoring tty states.
gdb_test "shell stty intr '^C'" ".*" \
"set interrupt character in test_with_self"
# FIXME: If we put this after the run to main, the first list
# command doesn't print the same line as the current line where
# gdb is stopped.
gdb_test_no_output "set listsize 1" "set listsize to 1"
# do we have a version number ?
gdb_test_multiple "print version" "printed version" {
-re ".\[0-9\]+ = .\[0-9.\]+.*$gdb_prompt $" {
pass "printed version as string"
}
-re ".\[0-9\]+ = +0x.*\[0-9.\]+.*$gdb_prompt $" {
pass "printed version as pointer"
}
-re ".\[0-9\]+ = +.+ +0x.*\[0-9.\]+.*$gdb_prompt $" {
pass "printed version with cast"
}
}
# start the "xgdb" process
if [target_info exists gdb,noinferiorio] {
# With no way to interact with the inferior GDB, all we can do
# is let it run.
send_gdb "continue\n"
# Wait a bit while the inferior gdb gets to its prompt.
sleep 1
} else {
set test "xgdb is at prompt"
gdb_test_multiple "continue" $test {
-i "$inferior_spawn_id"
-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 $" {
pass $test
}
}
# set xgdb prompt so we can tell which is which
send_inferior "set prompt (xgdb) \n"
set msg "Set xgdb_prompt"
gdb_test_multiple "" $msg {
-i "$inferior_spawn_id"
-re "\[(\]xgdb\[)\].*\[(\]xgdb\[)\] $" {
pass $msg
}
}
}
# kill the xgdb process
if ![target_info exists gdb,nointerrupts] {
set description "send ^C to child process"
send_gdb "\003"
# "Thread 1" is displayed iff Guile support is linked in.
gdb_expect {
-re "(Thread .*|Program) received signal SIGINT.*$gdb_prompt $" {
pass "$description"
}
-re ".*$gdb_prompt $" {
fail "$description"
}
timeout {
fail "$description (timeout)"
}
}
}
set description "send SIGINT signal to child process"
gdb_test "signal SIGINT" \
"Continuing with signal SIGINT.*" \
"$description"
# Switch back to the GDB thread if Guile support is linked in.
# "signal SIGINT" could also switch the current thread.
gdb_test "thread 1" {\[Switching to thread 1 .*\].*}
# get a stack trace
#
# This fails on some linux systems for unknown reasons. On the
# systems where it fails, sometimes it works fine when run manually.
# The testsuite failures may not be limited to just aout systems.
setup_xfail "i*86-pc-linuxaout-gnu"
set description "backtrace through signal handler"
gdb_test_multiple "backtrace" "$description" {
-re "#0.*(read|poll).*in main \\(.*\\) at .*gdb\\.c.*$gdb_prompt $" {
pass "$description"
}
}
# Restart gdb in case next test expects it to be started already.
return 0
}
do_self_tests captured_main test_with_self
|