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