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