18547b599d93415c7afa9a336707ce2c6bbfd085
[binutils-gdb.git] / gdb / testsuite / gdb.base / auxv.exp
1 # Test `info auxv' and related functionality.
2
3 # Copyright
4 # 1992,1993,1994,1995,1996,1997,1998,1999,2000,2004,2007,2008,2009,2010
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
9 # the Free Software Foundation; either version 3 of the License, or
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
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
19
20 # This file is based on corefile.exp which was written by Fred
21 # Fish. (fnf@cygnus.com)
22
23 if { ! [istarget "*-*-linux*"] && ! [istarget "*-*-solaris*"] } {
24 verbose "Skipping auxv.exp because of lack of support."
25 return
26 }
27
28 if $tracelevel then {
29 strace $tracelevel
30 }
31
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}] != "" } {
40 untested "couldn't compile ${srcdir}/${subdir}/${srcfile}"
41 return -1
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
48 set core_works [expr [isnative] && ! [is_remote target]]
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}
56 gdb_test "set print sevenbit-strings" "" \
57 "set print sevenbit-strings; ${testfile}"
58 gdb_test "set width 0" "" \
59 "set width 0; ${testfile}"
60
61 if {$core_works} {
62 if {[gdb_test "cd $coredir" ".*Working directory .*" \
63 "cd to temporary directory for core dumps"]} {
64 set core_works 0
65 }
66 }
67
68 if { ![runto_main] } then {
69 gdb_suppress_tests;
70 }
71 set print_core_line [gdb_get_line_number "ABORT;"]
72 gdb_test "tbreak $print_core_line"
73 gdb_test continue ".*ABORT;.*"
74
75 proc fetch_auxv {test} {
76 global gdb_prompt
77
78 set auxv_lines {}
79 set bad -1
80 # Former trailing `\[\r\n\]+' may eat just \r leaving \n in the buffer
81 # corrupting the next matches.
82 if {[gdb_test_multiple "info auxv" $test {
83 -re "info auxv\r\n" {
84 exp_continue
85 }
86 -ex "The program has no auxiliary information now" {
87 set bad 1
88 exp_continue
89 }
90 -ex "Auxiliary vector is empty" {
91 set bad 1
92 exp_continue
93 }
94 -ex "No auxiliary vector found" {
95 set bad 1
96 exp_continue
97 }
98 -re "^\[0-9\]+\[ \t\]+(AT_\[^ \t\]+)\[^\r\n\]+\r\n" {
99 lappend auxv_lines $expect_out(0,string)
100 exp_continue
101 }
102 -re "^\[0-9\]+\[ \t\]+\\?\\?\\?\[^\r\n\]+\r\n" {
103 warning "Unrecognized tag value: $expect_out(0,string)"
104 set bad 1
105 lappend auxv_lines $expect_out(0,string)
106 exp_continue
107 }
108 -re "$gdb_prompt $" {
109 incr bad
110 }
111 -re "^\[^\r\n\]+\r\n" {
112 if {!$bad} {
113 warning "Unrecognized output: $expect_out(0,string)"
114 set bad 1
115 }
116 exp_continue
117 }
118 }] != 0} {
119 return {}
120 }
121
122 if {$bad} {
123 fail $test
124 return {}
125 }
126
127 pass $test
128 return $auxv_lines
129 }
130
131 set live_data [fetch_auxv "info auxv on live process"]
132
133 # Now try gcore.
134 set gcore_works 0
135 set escapedfilename [string_to_regexp $gcorefile]
136 gdb_test_multiple "gcore $gcorefile" "gcore" {
137 -re "Saved corefile ${escapedfilename}\[\r\n\]+$gdb_prompt $" {
138 pass "gcore"
139 set gcore_works 1
140 }
141 -re "Can't create a corefile\[\r\n\]+$gdb_prompt $" {
142 unsupported "gcore"
143 }
144 -re "Undefined command: .*\[\r\n\]+$gdb_prompt $" {
145 unsupported "gcore"
146 }
147 }
148
149 # Let the program continue and die.
150 gdb_test continue ".*Program received signal.*"
151 gdb_test continue ".*Program terminated with signal.*"
152
153 # Now collect the core dump it left.
154 set test "generate native core dump"
155 if {$core_works} {
156 # Find the
157 set names [glob -nocomplain -directory $coredir *core*]
158 if {[llength $names] == 1} {
159 set file [file join $coredir [lindex $names 0]]
160 remote_exec build "mv $file $corefile"
161 pass $test
162 } else {
163 set core_works 0
164 warning "can't generate a core file - core tests suppressed - check ulimit -c"
165 fail $test
166 }
167 } else {
168 unsupported $test
169 }
170 remote_exec build "rm -rf $coredir"
171
172 # Now we can examine the core files and check that their data matches what
173 # we saw in the process. Note that the exact data can vary between runs,
174 # so it's important that the native core dump file and the gcore-created dump
175 # both be from the same run of the program as we examined live.
176
177 proc do_core_test {works corefile test1 test2} {
178 if {! $works} {
179 unsupported $test1
180 unsupported $test2
181 } else {
182 gdb_test "core $corefile" "Core was generated by.*" \
183 "load core file for $test1" \
184 "A program is being debugged already.*" "y"
185 set core_data [fetch_auxv $test1]
186 global live_data
187 if {$core_data == $live_data} {
188 pass $test2
189 } else {
190 fail $test2
191 }
192 }
193 }
194
195 do_core_test $core_works $corefile \
196 "info auxv on native core dump" "matching auxv data from live and core"
197
198 do_core_test $gcore_works $gcorefile \
199 "info auxv on gcore-created dump" "matching auxv data from live and gcore"