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