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