2011-05-30 Yao Qi <yao@codesourcery.com>
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.base / auxv.exp
CommitLineData
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
23if { ! [istarget "*-*-linux*"] && ! [istarget "*-*-solaris*"] } {
24 verbose "Skipping auxv.exp because of lack of support."
25 return
26}
27
d65308ae
RM
28if $tracelevel then {
29 strace $tracelevel
30}
31
d65308ae
RM
32
33set testfile "auxv"
34set srcfile ${testfile}.c
35set binfile ${objdir}/${subdir}/${testfile}
36set corefile ${objdir}/${subdir}/${testfile}.corefile
37set gcorefile ${objdir}/${subdir}/${testfile}.gcore
38
39if { [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.
46set coredir "${objdir}/${subdir}/coredir.[getpid]"
47file mkdir $coredir
db9d7fc5 48set 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
52gdb_exit
53gdb_start
54gdb_reinitialize_dir $srcdir/$subdir
55gdb_load ${binfile}
27d3a1a2
MS
56gdb_test_no_output "set print sevenbit-strings"
57gdb_test_no_output "set width 0"
d65308ae
RM
58
59if {$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
66if { ![runto_main] } then {
67 gdb_suppress_tests;
68}
69set print_core_line [gdb_get_line_number "ABORT;"]
70gdb_test "tbreak $print_core_line"
71gdb_test continue ".*ABORT;.*"
72
73proc 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
129set live_data [fetch_auxv "info auxv on live process"]
130
131# Now try gcore.
132set gcore_works 0
133set escapedfilename [string_to_regexp $gcorefile]
134gdb_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.
148gdb_test continue ".*Program received signal.*"
149gdb_test continue ".*Program terminated with signal.*"
150
151# Now collect the core dump it left.
152set test "generate native core dump"
153if {$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}
168remote_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
175proc 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
193do_core_test $core_works $corefile \
194 "info auxv on native core dump" "matching auxv data from live and core"
195
196do_core_test $gcore_works $gcorefile \
197 "info auxv on gcore-created dump" "matching auxv data from live and gcore"
This page took 0.683301 seconds and 4 git commands to generate.