Commit | Line | Data |
---|---|---|
d65308ae RM |
1 | # Test `info auxv' and related functionality. |
2 | ||
4c38e0a4 JB |
3 | # Copyright |
4 | # 1992,1993,1994,1995,1996,1997,1998,1999,2000,2004,2007,2008,2009,2010 | |
d65308ae RM |
5 | # Free Software Foundation, Inc. |
6 | ||
7 | # This program is free software; you can redistribute it and/or modify | |
8 | # it under the terms of the GNU General Public License as published by | |
e22f8b7c | 9 | # the Free Software Foundation; either version 3 of the License, or |
d65308ae RM |
10 | # (at your option) any later version. |
11 | # | |
12 | # This program is distributed in the hope that it will be useful, | |
13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | # GNU General Public License for more details. | |
16 | # | |
17 | # You should have received a copy of the GNU General Public License | |
e22f8b7c | 18 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
d65308ae | 19 | |
d65308ae RM |
20 | # This file is based on corefile.exp which was written by Fred |
21 | # Fish. (fnf@cygnus.com) | |
22 | ||
0155cc76 NS |
23 | if { ! [istarget "*-*-linux*"] && ! [istarget "*-*-solaris*"] } { |
24 | verbose "Skipping auxv.exp because of lack of support." | |
25 | return | |
26 | } | |
27 | ||
d65308ae RM |
28 | if $tracelevel then { |
29 | strace $tracelevel | |
30 | } | |
31 | ||
d65308ae RM |
32 | |
33 | set testfile "auxv" | |
34 | set srcfile ${testfile}.c | |
35 | set binfile ${objdir}/${subdir}/${testfile} | |
36 | set corefile ${objdir}/${subdir}/${testfile}.corefile | |
37 | set gcorefile ${objdir}/${subdir}/${testfile}.gcore | |
38 | ||
39 | if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } { | |
78df6c56 JB |
40 | untested "couldn't compile ${srcdir}/${subdir}/${srcfile}" |
41 | return -1 | |
d65308ae RM |
42 | } |
43 | ||
44 | # Use a fresh directory to confine the native core dumps. | |
45 | # Make it the working directory for gdb and its child. | |
46 | set coredir "${objdir}/${subdir}/coredir.[getpid]" | |
47 | file mkdir $coredir | |
db9d7fc5 | 48 | set core_works [expr [isnative] && ! [is_remote target]] |
d65308ae RM |
49 | |
50 | # Run GDB on the test program up to where it will dump core. | |
51 | ||
52 | gdb_exit | |
53 | gdb_start | |
54 | gdb_reinitialize_dir $srcdir/$subdir | |
55 | gdb_load ${binfile} | |
27d3a1a2 MS |
56 | gdb_test_no_output "set print sevenbit-strings" |
57 | gdb_test_no_output "set width 0" | |
d65308ae RM |
58 | |
59 | if {$core_works} { | |
60 | if {[gdb_test "cd $coredir" ".*Working directory .*" \ | |
61 | "cd to temporary directory for core dumps"]} { | |
62 | set core_works 0 | |
63 | } | |
64 | } | |
65 | ||
66 | if { ![runto_main] } then { | |
67 | gdb_suppress_tests; | |
68 | } | |
69 | set print_core_line [gdb_get_line_number "ABORT;"] | |
70 | gdb_test "tbreak $print_core_line" | |
71 | gdb_test continue ".*ABORT;.*" | |
72 | ||
73 | proc fetch_auxv {test} { | |
74 | global gdb_prompt | |
75 | ||
76 | set auxv_lines {} | |
77 | set bad -1 | |
bcd5727b JK |
78 | # Former trailing `\[\r\n\]+' may eat just \r leaving \n in the buffer |
79 | # corrupting the next matches. | |
d65308ae | 80 | if {[gdb_test_multiple "info auxv" $test { |
bcd5727b | 81 | -re "info auxv\r\n" { |
d65308ae RM |
82 | exp_continue |
83 | } | |
c1b5970d | 84 | -ex "The program has no auxiliary information now" { |
d65308ae | 85 | set bad 1 |
f1ed375c | 86 | exp_continue |
d65308ae | 87 | } |
c1b5970d | 88 | -ex "Auxiliary vector is empty" { |
d65308ae | 89 | set bad 1 |
f1ed375c | 90 | exp_continue |
d65308ae | 91 | } |
c1b5970d | 92 | -ex "No auxiliary vector found" { |
d65308ae | 93 | set bad 1 |
f1ed375c | 94 | exp_continue |
d65308ae | 95 | } |
bcd5727b | 96 | -re "^\[0-9\]+\[ \t\]+(AT_\[^ \t\]+)\[^\r\n\]+\r\n" { |
d65308ae RM |
97 | lappend auxv_lines $expect_out(0,string) |
98 | exp_continue | |
99 | } | |
bcd5727b | 100 | -re "^\[0-9\]+\[ \t\]+\\?\\?\\?\[^\r\n\]+\r\n" { |
d65308ae RM |
101 | warning "Unrecognized tag value: $expect_out(0,string)" |
102 | set bad 1 | |
103 | lappend auxv_lines $expect_out(0,string) | |
104 | exp_continue | |
105 | } | |
bcd5727b | 106 | -re "$gdb_prompt $" { |
f1ed375c | 107 | incr bad |
d65308ae | 108 | } |
bcd5727b | 109 | -re "^\[^\r\n\]+\r\n" { |
c1b5970d RM |
110 | if {!$bad} { |
111 | warning "Unrecognized output: $expect_out(0,string)" | |
112 | set bad 1 | |
113 | } | |
114 | exp_continue | |
115 | } | |
d65308ae RM |
116 | }] != 0} { |
117 | return {} | |
118 | } | |
119 | ||
120 | if {$bad} { | |
121 | fail $test | |
122 | return {} | |
123 | } | |
124 | ||
125 | pass $test | |
126 | return $auxv_lines | |
127 | } | |
128 | ||
129 | set live_data [fetch_auxv "info auxv on live process"] | |
130 | ||
131 | # Now try gcore. | |
132 | set gcore_works 0 | |
133 | set escapedfilename [string_to_regexp $gcorefile] | |
134 | gdb_test_multiple "gcore $gcorefile" "gcore" { | |
135 | -re "Saved corefile ${escapedfilename}\[\r\n\]+$gdb_prompt $" { | |
136 | pass "gcore" | |
137 | set gcore_works 1 | |
138 | } | |
139 | -re "Can't create a corefile\[\r\n\]+$gdb_prompt $" { | |
140 | unsupported "gcore" | |
141 | } | |
aa32fa1d DJ |
142 | -re "Undefined command: .*\[\r\n\]+$gdb_prompt $" { |
143 | unsupported "gcore" | |
144 | } | |
d65308ae RM |
145 | } |
146 | ||
147 | # Let the program continue and die. | |
148 | gdb_test continue ".*Program received signal.*" | |
149 | gdb_test continue ".*Program terminated with signal.*" | |
150 | ||
151 | # Now collect the core dump it left. | |
152 | set test "generate native core dump" | |
153 | if {$core_works} { | |
154 | # Find the | |
155 | set names [glob -nocomplain -directory $coredir *core*] | |
156 | if {[llength $names] == 1} { | |
157 | set file [file join $coredir [lindex $names 0]] | |
158 | remote_exec build "mv $file $corefile" | |
159 | pass $test | |
160 | } else { | |
161 | set core_works 0 | |
162 | warning "can't generate a core file - core tests suppressed - check ulimit -c" | |
163 | fail $test | |
164 | } | |
165 | } else { | |
166 | unsupported $test | |
167 | } | |
168 | remote_exec build "rm -rf $coredir" | |
169 | ||
170 | # Now we can examine the core files and check that their data matches what | |
171 | # we saw in the process. Note that the exact data can vary between runs, | |
172 | # so it's important that the native core dump file and the gcore-created dump | |
173 | # both be from the same run of the program as we examined live. | |
174 | ||
175 | proc do_core_test {works corefile test1 test2} { | |
176 | if {! $works} { | |
177 | unsupported $test1 | |
178 | unsupported $test2 | |
179 | } else { | |
180 | gdb_test "core $corefile" "Core was generated by.*" \ | |
181 | "load core file for $test1" \ | |
182 | "A program is being debugged already.*" "y" | |
183 | set core_data [fetch_auxv $test1] | |
184 | global live_data | |
185 | if {$core_data == $live_data} { | |
186 | pass $test2 | |
187 | } else { | |
188 | fail $test2 | |
189 | } | |
190 | } | |
191 | } | |
192 | ||
193 | do_core_test $core_works $corefile \ | |
194 | "info auxv on native core dump" "matching auxv data from live and core" | |
195 | ||
196 | do_core_test $gcore_works $gcorefile \ | |
197 | "info auxv on gcore-created dump" "matching auxv data from live and gcore" |