GDB copyright headers update after running GDB's copyright.py script.
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.base / auxv.exp
CommitLineData
d65308ae
RM
1# Test `info auxv' and related functionality.
2
618f726f 3# Copyright (C) 1992-2016 Free Software Foundation, Inc.
d65308ae
RM
4
5# This program is free software; you can redistribute it and/or modify
6# it under the terms of the GNU General Public License as published by
e22f8b7c 7# the Free Software Foundation; either version 3 of the License, or
d65308ae
RM
8# (at your option) any later version.
9#
10# This program is distributed in the hope that it will be useful,
11# but WITHOUT ANY WARRANTY; without even the implied warranty of
12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13# GNU General Public License for more details.
14#
15# You should have received a copy of the GNU General Public License
e22f8b7c 16# along with this program. If not, see <http://www.gnu.org/licenses/>.
d65308ae 17
d65308ae
RM
18# This file is based on corefile.exp which was written by Fred
19# Fish. (fnf@cygnus.com)
20
0155cc76
NS
21if { ! [istarget "*-*-linux*"] && ! [istarget "*-*-solaris*"] } {
22 verbose "Skipping auxv.exp because of lack of support."
23 return
24}
25
d65308ae 26
a64d2530
TT
27standard_testfile .c
28
29set corefile ${binfile}.corefile
30set gcorefile ${binfile}.gcore
d65308ae 31
2e98ca53
JK
32if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable \
33 {debug additional_flags=-DUSE_RLIMIT}] != ""
34 && [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable \
35 {debug}] != "" } {
78df6c56
JB
36 untested "couldn't compile ${srcdir}/${subdir}/${srcfile}"
37 return -1
d65308ae
RM
38}
39
40# Use a fresh directory to confine the native core dumps.
41# Make it the working directory for gdb and its child.
a64d2530 42set coredir [standard_output_file coredir.[getpid]]
d65308ae 43file mkdir $coredir
db9d7fc5 44set core_works [expr [isnative] && ! [is_remote target]]
d65308ae
RM
45
46# Run GDB on the test program up to where it will dump core.
47
a64d2530 48clean_restart ${binfile}
27d3a1a2
MS
49gdb_test_no_output "set print sevenbit-strings"
50gdb_test_no_output "set width 0"
d65308ae
RM
51
52if {$core_works} {
53 if {[gdb_test "cd $coredir" ".*Working directory .*" \
54 "cd to temporary directory for core dumps"]} {
55 set core_works 0
56 }
57}
58
59if { ![runto_main] } then {
4ec70201 60 gdb_suppress_tests
d65308ae
RM
61}
62set print_core_line [gdb_get_line_number "ABORT;"]
63gdb_test "tbreak $print_core_line"
64gdb_test continue ".*ABORT;.*"
65
66proc fetch_auxv {test} {
67 global gdb_prompt
68
69 set auxv_lines {}
70 set bad -1
bcd5727b
JK
71 # Former trailing `\[\r\n\]+' may eat just \r leaving \n in the buffer
72 # corrupting the next matches.
d65308ae 73 if {[gdb_test_multiple "info auxv" $test {
bcd5727b 74 -re "info auxv\r\n" {
d65308ae
RM
75 exp_continue
76 }
c1b5970d 77 -ex "The program has no auxiliary information now" {
d65308ae 78 set bad 1
f1ed375c 79 exp_continue
d65308ae 80 }
c1b5970d 81 -ex "Auxiliary vector is empty" {
d65308ae 82 set bad 1
f1ed375c 83 exp_continue
d65308ae 84 }
c1b5970d 85 -ex "No auxiliary vector found" {
d65308ae 86 set bad 1
f1ed375c 87 exp_continue
d65308ae 88 }
bcd5727b 89 -re "^\[0-9\]+\[ \t\]+(AT_\[^ \t\]+)\[^\r\n\]+\r\n" {
d65308ae
RM
90 lappend auxv_lines $expect_out(0,string)
91 exp_continue
92 }
bcd5727b 93 -re "^\[0-9\]+\[ \t\]+\\?\\?\\?\[^\r\n\]+\r\n" {
d65308ae
RM
94 warning "Unrecognized tag value: $expect_out(0,string)"
95 set bad 1
96 lappend auxv_lines $expect_out(0,string)
97 exp_continue
98 }
bcd5727b 99 -re "$gdb_prompt $" {
f1ed375c 100 incr bad
d65308ae 101 }
bcd5727b 102 -re "^\[^\r\n\]+\r\n" {
c1b5970d
RM
103 if {!$bad} {
104 warning "Unrecognized output: $expect_out(0,string)"
105 set bad 1
106 }
107 exp_continue
108 }
d65308ae
RM
109 }] != 0} {
110 return {}
111 }
112
113 if {$bad} {
114 fail $test
115 return {}
116 }
117
118 pass $test
119 return $auxv_lines
120}
121
122set live_data [fetch_auxv "info auxv on live process"]
123
124# Now try gcore.
2d338fa9 125set gcore_works [gdb_gcore_cmd "$gcorefile" "gcore"]
d65308ae
RM
126
127# Let the program continue and die.
128gdb_test continue ".*Program received signal.*"
129gdb_test continue ".*Program terminated with signal.*"
130
131# Now collect the core dump it left.
132set test "generate native core dump"
133if {$core_works} {
134 # Find the
135 set names [glob -nocomplain -directory $coredir *core*]
136 if {[llength $names] == 1} {
137 set file [file join $coredir [lindex $names 0]]
138 remote_exec build "mv $file $corefile"
139 pass $test
140 } else {
141 set core_works 0
142 warning "can't generate a core file - core tests suppressed - check ulimit -c"
2e98ca53 143 unsupported $test
d65308ae
RM
144 }
145} else {
146 unsupported $test
147}
148remote_exec build "rm -rf $coredir"
149
150# Now we can examine the core files and check that their data matches what
151# we saw in the process. Note that the exact data can vary between runs,
152# so it's important that the native core dump file and the gcore-created dump
153# both be from the same run of the program as we examined live.
154
155proc do_core_test {works corefile test1 test2} {
156 if {! $works} {
157 unsupported $test1
158 unsupported $test2
159 } else {
160 gdb_test "core $corefile" "Core was generated by.*" \
161 "load core file for $test1" \
162 "A program is being debugged already.*" "y"
163 set core_data [fetch_auxv $test1]
164 global live_data
165 if {$core_data == $live_data} {
166 pass $test2
167 } else {
168 fail $test2
169 }
170 }
171}
172
173do_core_test $core_works $corefile \
174 "info auxv on native core dump" "matching auxv data from live and core"
175
176do_core_test $gcore_works $gcorefile \
177 "info auxv on gcore-created dump" "matching auxv data from live and gcore"
This page took 1.218849 seconds and 4 git commands to generate.