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