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,2009
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 # Former trailing `\[\r\n\]+' may eat just \r leaving \n in the buffer
82 # corrupting the next matches.
83 if {[gdb_test_multiple "info auxv" $test {
84 -re "info auxv\r\n" {
85 exp_continue
86 }
87 -ex "The program has no auxiliary information now" {
88 set bad 1
89 exp_continue
90 }
91 -ex "Auxiliary vector is empty" {
92 set bad 1
93 exp_continue
94 }
95 -ex "No auxiliary vector found" {
96 set bad 1
97 exp_continue
98 }
99 -re "^\[0-9\]+\[ \t\]+(AT_\[^ \t\]+)\[^\r\n\]+\r\n" {
100 lappend auxv_lines $expect_out(0,string)
101 exp_continue
102 }
103 -re "^\[0-9\]+\[ \t\]+\\?\\?\\?\[^\r\n\]+\r\n" {
104 warning "Unrecognized tag value: $expect_out(0,string)"
105 set bad 1
106 lappend auxv_lines $expect_out(0,string)
107 exp_continue
108 }
109 -re "$gdb_prompt $" {
110 incr bad
111 }
112 -re "^\[^\r\n\]+\r\n" {
113 if {!$bad} {
114 warning "Unrecognized output: $expect_out(0,string)"
115 set bad 1
116 }
117 exp_continue
118 }
119 }] != 0} {
120 return {}
121 }
122
123 if {$bad} {
124 fail $test
125 return {}
126 }
127
128 pass $test
129 return $auxv_lines
130 }
131
132 set live_data [fetch_auxv "info auxv on live process"]
133
134 # Now try gcore.
135 set gcore_works 0
136 set escapedfilename [string_to_regexp $gcorefile]
137 gdb_test_multiple "gcore $gcorefile" "gcore" {
138 -re "Saved corefile ${escapedfilename}\[\r\n\]+$gdb_prompt $" {
139 pass "gcore"
140 set gcore_works 1
141 }
142 -re "Can't create a corefile\[\r\n\]+$gdb_prompt $" {
143 unsupported "gcore"
144 }
145 -re "Undefined command: .*\[\r\n\]+$gdb_prompt $" {
146 unsupported "gcore"
147 }
148 }
149
150 # Let the program continue and die.
151 gdb_test continue ".*Program received signal.*"
152 gdb_test continue ".*Program terminated with signal.*"
153
154 # Now collect the core dump it left.
155 set test "generate native core dump"
156 if {$core_works} {
157 # Find the
158 set names [glob -nocomplain -directory $coredir *core*]
159 if {[llength $names] == 1} {
160 set file [file join $coredir [lindex $names 0]]
161 remote_exec build "mv $file $corefile"
162 pass $test
163 } else {
164 set core_works 0
165 warning "can't generate a core file - core tests suppressed - check ulimit -c"
166 fail $test
167 }
168 } else {
169 unsupported $test
170 }
171 remote_exec build "rm -rf $coredir"
172
173 # Now we can examine the core files and check that their data matches what
174 # we saw in the process. Note that the exact data can vary between runs,
175 # so it's important that the native core dump file and the gcore-created dump
176 # both be from the same run of the program as we examined live.
177
178 proc do_core_test {works corefile test1 test2} {
179 if {! $works} {
180 unsupported $test1
181 unsupported $test2
182 } else {
183 gdb_test "core $corefile" "Core was generated by.*" \
184 "load core file for $test1" \
185 "A program is being debugged already.*" "y"
186 set core_data [fetch_auxv $test1]
187 global live_data
188 if {$core_data == $live_data} {
189 pass $test2
190 } else {
191 fail $test2
192 }
193 }
194 }
195
196 do_core_test $core_works $corefile \
197 "info auxv on native core dump" "matching auxv data from live and core"
198
199 do_core_test $gcore_works $gcorefile \
200 "info auxv on gcore-created dump" "matching auxv data from live and gcore"
This page took 0.034657 seconds and 4 git commands to generate.