Update copyright year in most headers.
[deliverable/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 set prms_id 0
33 set bug_id 0
34
35 set testfile "auxv"
36 set srcfile ${testfile}.c
37 set binfile ${objdir}/${subdir}/${testfile}
38 set corefile ${objdir}/${subdir}/${testfile}.corefile
39 set gcorefile ${objdir}/${subdir}/${testfile}.gcore
40
41 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
42 untested "couldn't compile ${srcdir}/${subdir}/${srcfile}"
43 return -1
44 }
45
46 # Use a fresh directory to confine the native core dumps.
47 # Make it the working directory for gdb and its child.
48 set coredir "${objdir}/${subdir}/coredir.[getpid]"
49 file mkdir $coredir
50 set core_works [expr [isnative] && ! [is_remote target]]
51
52 # Run GDB on the test program up to where it will dump core.
53
54 gdb_exit
55 gdb_start
56 gdb_reinitialize_dir $srcdir/$subdir
57 gdb_load ${binfile}
58 gdb_test "set print sevenbit-strings" "" \
59 "set print sevenbit-strings; ${testfile}"
60 gdb_test "set width 0" "" \
61 "set width 0; ${testfile}"
62
63 if {$core_works} {
64 if {[gdb_test "cd $coredir" ".*Working directory .*" \
65 "cd to temporary directory for core dumps"]} {
66 set core_works 0
67 }
68 }
69
70 if { ![runto_main] } then {
71 gdb_suppress_tests;
72 }
73 set print_core_line [gdb_get_line_number "ABORT;"]
74 gdb_test "tbreak $print_core_line"
75 gdb_test continue ".*ABORT;.*"
76
77 proc fetch_auxv {test} {
78 global gdb_prompt
79
80 set auxv_lines {}
81 set bad -1
82 # Former trailing `\[\r\n\]+' may eat just \r leaving \n in the buffer
83 # corrupting the next matches.
84 if {[gdb_test_multiple "info auxv" $test {
85 -re "info auxv\r\n" {
86 exp_continue
87 }
88 -ex "The program has no auxiliary information now" {
89 set bad 1
90 exp_continue
91 }
92 -ex "Auxiliary vector is empty" {
93 set bad 1
94 exp_continue
95 }
96 -ex "No auxiliary vector found" {
97 set bad 1
98 exp_continue
99 }
100 -re "^\[0-9\]+\[ \t\]+(AT_\[^ \t\]+)\[^\r\n\]+\r\n" {
101 lappend auxv_lines $expect_out(0,string)
102 exp_continue
103 }
104 -re "^\[0-9\]+\[ \t\]+\\?\\?\\?\[^\r\n\]+\r\n" {
105 warning "Unrecognized tag value: $expect_out(0,string)"
106 set bad 1
107 lappend auxv_lines $expect_out(0,string)
108 exp_continue
109 }
110 -re "$gdb_prompt $" {
111 incr bad
112 }
113 -re "^\[^\r\n\]+\r\n" {
114 if {!$bad} {
115 warning "Unrecognized output: $expect_out(0,string)"
116 set bad 1
117 }
118 exp_continue
119 }
120 }] != 0} {
121 return {}
122 }
123
124 if {$bad} {
125 fail $test
126 return {}
127 }
128
129 pass $test
130 return $auxv_lines
131 }
132
133 set live_data [fetch_auxv "info auxv on live process"]
134
135 # Now try gcore.
136 set gcore_works 0
137 set escapedfilename [string_to_regexp $gcorefile]
138 gdb_test_multiple "gcore $gcorefile" "gcore" {
139 -re "Saved corefile ${escapedfilename}\[\r\n\]+$gdb_prompt $" {
140 pass "gcore"
141 set gcore_works 1
142 }
143 -re "Can't create a corefile\[\r\n\]+$gdb_prompt $" {
144 unsupported "gcore"
145 }
146 -re "Undefined command: .*\[\r\n\]+$gdb_prompt $" {
147 unsupported "gcore"
148 }
149 }
150
151 # Let the program continue and die.
152 gdb_test continue ".*Program received signal.*"
153 gdb_test continue ".*Program terminated with signal.*"
154
155 # Now collect the core dump it left.
156 set test "generate native core dump"
157 if {$core_works} {
158 # Find the
159 set names [glob -nocomplain -directory $coredir *core*]
160 if {[llength $names] == 1} {
161 set file [file join $coredir [lindex $names 0]]
162 remote_exec build "mv $file $corefile"
163 pass $test
164 } else {
165 set core_works 0
166 warning "can't generate a core file - core tests suppressed - check ulimit -c"
167 fail $test
168 }
169 } else {
170 unsupported $test
171 }
172 remote_exec build "rm -rf $coredir"
173
174 # Now we can examine the core files and check that their data matches what
175 # we saw in the process. Note that the exact data can vary between runs,
176 # so it's important that the native core dump file and the gcore-created dump
177 # both be from the same run of the program as we examined live.
178
179 proc do_core_test {works corefile test1 test2} {
180 if {! $works} {
181 unsupported $test1
182 unsupported $test2
183 } else {
184 gdb_test "core $corefile" "Core was generated by.*" \
185 "load core file for $test1" \
186 "A program is being debugged already.*" "y"
187 set core_data [fetch_auxv $test1]
188 global live_data
189 if {$core_data == $live_data} {
190 pass $test2
191 } else {
192 fail $test2
193 }
194 }
195 }
196
197 do_core_test $core_works $corefile \
198 "info auxv on native core dump" "matching auxv data from live and core"
199
200 do_core_test $gcore_works $gcorefile \
201 "info auxv on gcore-created dump" "matching auxv data from live and gcore"
This page took 0.035235 seconds and 4 git commands to generate.