1 # Test `info auxv' and related functionality.
3 # Copyright (C) 1992-2000, 2004, 2007-2010, 2012 Free Software
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.
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.
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/>.
19 # This file is based on corefile.exp which was written by Fred
20 # Fish. (fnf@cygnus.com)
22 if { ! [istarget "*-*-linux*"] && ! [istarget "*-*-solaris*"] } {
23 verbose "Skipping auxv.exp because of lack of support."
33 set srcfile ${testfile}.c
34 set binfile ${objdir}/${subdir}/${testfile}
35 set corefile ${objdir}/${subdir}/${testfile}.corefile
36 set gcorefile ${objdir}/${subdir}/${testfile}.gcore
38 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
39 untested "couldn't compile ${srcdir}/${subdir}/${srcfile}"
43 # Use a fresh directory to confine the native core dumps.
44 # Make it the working directory for gdb and its child.
45 set coredir "${objdir}/${subdir}/coredir.[getpid]"
47 set core_works [expr [isnative] && ! [is_remote target]]
49 # Run GDB on the test program up to where it will dump core.
53 gdb_reinitialize_dir $srcdir/$subdir
55 gdb_test_no_output "set print sevenbit-strings"
56 gdb_test_no_output "set width 0"
59 if {[gdb_test "cd $coredir" ".*Working directory .*" \
60 "cd to temporary directory for core dumps"]} {
65 if { ![runto_main] } then {
68 set print_core_line [gdb_get_line_number "ABORT;"]
69 gdb_test "tbreak $print_core_line"
70 gdb_test continue ".*ABORT;.*"
72 proc fetch_auxv {test} {
77 # Former trailing `\[\r\n\]+' may eat just \r leaving \n in the buffer
78 # corrupting the next matches.
79 if {[gdb_test_multiple "info auxv" $test {
83 -ex "The program has no auxiliary information now" {
87 -ex "Auxiliary vector is empty" {
91 -ex "No auxiliary vector found" {
95 -re "^\[0-9\]+\[ \t\]+(AT_\[^ \t\]+)\[^\r\n\]+\r\n" {
96 lappend auxv_lines $expect_out(0,string)
99 -re "^\[0-9\]+\[ \t\]+\\?\\?\\?\[^\r\n\]+\r\n" {
100 warning "Unrecognized tag value: $expect_out(0,string)"
102 lappend auxv_lines $expect_out(0,string)
105 -re "$gdb_prompt $" {
108 -re "^\[^\r\n\]+\r\n" {
110 warning "Unrecognized output: $expect_out(0,string)"
128 set live_data [fetch_auxv "info auxv on live process"]
132 set escapedfilename [string_to_regexp $gcorefile]
133 gdb_test_multiple "gcore $gcorefile" "gcore" {
134 -re "Saved corefile ${escapedfilename}\[\r\n\]+$gdb_prompt $" {
138 -re "Can't create a corefile\[\r\n\]+$gdb_prompt $" {
141 -re "Undefined command: .*\[\r\n\]+$gdb_prompt $" {
146 # Let the program continue and die.
147 gdb_test continue ".*Program received signal.*"
148 gdb_test continue ".*Program terminated with signal.*"
150 # Now collect the core dump it left.
151 set test "generate native core dump"
154 set names [glob -nocomplain -directory $coredir *core*]
155 if {[llength $names] == 1} {
156 set file [file join $coredir [lindex $names 0]]
157 remote_exec build "mv $file $corefile"
161 warning "can't generate a core file - core tests suppressed - check ulimit -c"
167 remote_exec build "rm -rf $coredir"
169 # Now we can examine the core files and check that their data matches what
170 # we saw in the process. Note that the exact data can vary between runs,
171 # so it's important that the native core dump file and the gcore-created dump
172 # both be from the same run of the program as we examined live.
174 proc do_core_test {works corefile test1 test2} {
179 gdb_test "core $corefile" "Core was generated by.*" \
180 "load core file for $test1" \
181 "A program is being debugged already.*" "y"
182 set core_data [fetch_auxv $test1]
184 if {$core_data == $live_data} {
192 do_core_test $core_works $corefile \
193 "info auxv on native core dump" "matching auxv data from live and core"
195 do_core_test $gcore_works $gcorefile \
196 "info auxv on gcore-created dump" "matching auxv data from live and gcore"