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