1 # Test `info auxv' and related functionality.
3 # Copyright (C) 1992-2022 Free Software Foundation, Inc.
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
7 # the Free Software Foundation; either version 3 of the License, or
8 # (at your option) any later version.
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.
15 # You should have received a copy of the GNU General Public License
16 # along with this program. If not, see <http://www.gnu.org/licenses/>.
18 # This file is based on corefile.exp which was written by Fred
19 # Fish. (fnf@cygnus.com)
21 if { ! [istarget "*-*-linux*"] && ! [istarget "*-*-solaris*"] } {
22 verbose "Skipping auxv.exp because of lack of support."
29 set corefile ${binfile}.corefile
30 set gcorefile ${binfile}.gcore
32 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable \
33 {debug additional_flags=-DUSE_RLIMIT}] != ""
34 && [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable \
36 untested "failed to compile"
40 # Use a fresh directory to confine the native core dumps.
41 # Make it the working directory for the inferior.
42 set coredir [standard_output_file coredir.[getpid]]
44 set core_works [expr [isnative] && ! [is_remote target]]
46 # Run GDB on the test program up to where it will dump core.
48 clean_restart ${binfile}
49 gdb_test_no_output "set print sevenbit-strings"
50 gdb_test_no_output "set width 0"
53 if {[gdb_test_no_output "set cwd $coredir" \
54 "set cwd to temporary directory for core dumps"]} {
59 if ![runto_main] then {
62 set print_core_line [gdb_get_line_number "ABORT;"]
63 gdb_test "tbreak $print_core_line"
64 gdb_test continue ".*ABORT;.*"
66 proc fetch_auxv {test} {
71 # Former trailing `\[\r\n\]+' may eat just \r leaving \n in the buffer
72 # corrupting the next matches.
73 if {[gdb_test_multiple "info auxv" $test {
77 -ex "The program has no auxiliary information now" {
81 -ex "Auxiliary vector is empty" {
85 -ex "No auxiliary vector found" {
89 -re "^\[0-9\]+\[ \t\]+(AT_\[^ \t\]+)\[^\r\n\]+\r\n" {
90 lappend auxv_lines $expect_out(0,string)
93 -re "^\[0-9\]+\[ \t\]+\\?\\?\\?\[^\r\n\]+\r\n" {
94 warning "Unrecognized tag value: $expect_out(0,string)"
96 lappend auxv_lines $expect_out(0,string)
102 -re "^\[^\r\n\]+\r\n" {
104 warning "Unrecognized output: $expect_out(0,string)"
122 set live_data [fetch_auxv "info auxv on live process"]
125 set gcore_works [gdb_gcore_cmd "$gcorefile" "gcore"]
127 # Let the program continue and die.
128 gdb_test continue ".*Program received signal.*" "continue until signal"
129 gdb_test continue ".*Program terminated with signal.*" "continue and terminate"
131 # Now collect the core dump it left.
132 set test "generate native core dump"
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"
142 warning "can't generate a core file - core tests suppressed - check ulimit -c"
148 remote_exec build "rm -rf $coredir"
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.
155 proc do_core_test {works corefile test1 test2} {
160 gdb_test "core $corefile" "Core was generated by.*" \
161 "load core file for $test1"
162 set core_data [fetch_auxv $test1]
164 if {$core_data == $live_data} {
172 do_core_test $core_works $corefile \
173 "info auxv on native core dump" "matching auxv data from live and core"
175 do_core_test $gcore_works $gcorefile \
176 "info auxv on gcore-created dump" "matching auxv data from live and gcore"