[gdb/syscalls] Sync with strace v6.13
[binutils-gdb.git] / gdb / testsuite / gdb.base / auxv.exp
blob0759a4f9a821b5a6f44e25d5ce81393d194fa9c3
1 # Test `info auxv' and related functionality.
3 # Copyright (C) 1992-2024 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 require {is_any_target "*-*-linux*" "*-*-solaris*"}
23 standard_testfile .c
25 set corefile ${binfile}.corefile
26 set gcorefile ${binfile}.gcore
28 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable \
29                   {debug additional_flags=-DUSE_RLIMIT}] != ""
30      && [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable \
31                   {debug}] != "" } {
32     untested "failed to compile"
33     return -1
36 # Use a fresh directory to confine the native core dumps.
37 # Make it the working directory for the inferior.
38 set coredir [standard_output_file coredir.[getpid]]
39 file mkdir $coredir
40 set core_works [expr [isnative] && ! [is_remote target]]
42 # Run GDB on the test program up to where it will dump core.
44 clean_restart ${binfile}
45 gdb_test_no_output "set print sevenbit-strings"
46 gdb_test_no_output "set width 0"
48 if {$core_works} {
49     if {[gdb_test_no_output "set cwd $coredir" \
50              "set cwd to temporary directory for core dumps"]} {
51         set core_works 0
52     }
55 if {![runto_main]} {
56     return 0
58 set print_core_line [gdb_get_line_number "ABORT;"]
59 gdb_test "tbreak $print_core_line"
60 gdb_test continue ".*ABORT;.*"
62 proc fetch_auxv {test} {
63     global gdb_prompt
65     set auxv_lines {}
66     set bad -1
67     # Former trailing `\[\r\n\]+' may eat just \r leaving \n in the buffer
68     # corrupting the next matches.
69     if {[gdb_test_multiple "info auxv" $test {
70         -re "info auxv\r\n" {
71             exp_continue
72         }
73         -ex "The program has no auxiliary information now" {
74             set bad 1
75             exp_continue
76         }
77         -ex "Auxiliary vector is empty" {
78             set bad 1
79             exp_continue
80         }
81         -ex "No auxiliary vector found" {
82             set bad 1
83             exp_continue
84         }
85         -re "^\[0-9\]+\[ \t\]+(AT_\[^ \t\]+)\[^\r\n\]+\r\n" {
86             lappend auxv_lines $expect_out(0,string)
87             exp_continue
88         }
89         -re "^\[0-9\]+\[ \t\]+\\?\\?\\?\[^\r\n\]+\r\n" {
90             warning "Unrecognized tag value: $expect_out(0,string)"
91             set bad 1
92             lappend auxv_lines $expect_out(0,string)
93             exp_continue
94         }
95         -re "$gdb_prompt $" {
96             incr bad
97         }
98         -re "^\[^\r\n\]+\r\n" {
99             if {!$bad} {
100                 warning "Unrecognized output: $expect_out(0,string)"
101                 set bad 1
102             }
103             exp_continue
104         }
105     }] != 0} {
106         return {}
107     }
109     if {$bad} {
110         fail $test
111         return {}
112     }
114     pass $test
115     return $auxv_lines
118 set live_data [fetch_auxv "info auxv on live process"]
120 # Now try gcore.
121 set gcore_works [gdb_gcore_cmd "$gcorefile" "gcore"]
123 # Let the program continue and die.
124 gdb_test continue ".*Program received signal.*" "continue until signal"
125 gdb_test continue ".*Program terminated with signal.*" "continue and terminate"
127 # Now collect the core dump it left.
128 set test "generate native core dump"
129 if {$core_works} {
130     # Find the
131     set names [glob -nocomplain -directory $coredir *core*]
132     if {[llength $names] == 1} {
133         set file [file join $coredir [lindex $names 0]]
134         remote_exec build "mv $file $corefile"
135         pass $test
136     } else {
137         set core_works 0
138         warning "can't generate a core file - core tests suppressed - check ulimit -c"
139         unsupported $test
140     }
141 } else {
142     unsupported $test
144 remote_exec build "rm -rf $coredir"
146 # Now we can examine the core files and check that their data matches what
147 # we saw in the process.  Note that the exact data can vary between runs,
148 # so it's important that the native core dump file and the gcore-created dump
149 # both be from the same run of the program as we examined live.
151 proc do_core_test {works corefile test1 test2} {
152     if {! $works} {
153         unsupported $test1
154         unsupported $test2
155     } else {
156         gdb_test "core $corefile" "Core was generated by.*" \
157             "load core file for $test1"
158         set core_data [fetch_auxv $test1]
159         global live_data
160         if {$core_data == $live_data} {
161             pass $test2
162         } else {
163             fail $test2
164         }
165     }
168 do_core_test $core_works $corefile \
169     "info auxv on native core dump" "matching auxv data from live and core"
171 do_core_test $gcore_works $gcorefile \
172     "info auxv on gcore-created dump" "matching auxv data from live and gcore"