2004-06-04 Roland McGrath <roland@redhat.com>
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.base / auxv.exp
1 # Test `info auxv' and related functionality.
2
3 # Copyright 1992,1993,1994,1995,1996,1997,1998,1999,2000,2004
4 # Free Software Foundation, Inc.
5
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 2 of the License, or
9 # (at your option) any later version.
10 #
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.
15 #
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19
20 # Please email any bugs, comments, and/or additions to this file to:
21 # bug-gdb@prep.ai.mit.edu
22
23 # This file is based on corefile.exp which was written by Fred
24 # Fish. (fnf@cygnus.com)
25
26 if $tracelevel then {
27 strace $tracelevel
28 }
29
30 set prms_id 0
31 set bug_id 0
32
33 set testfile "auxv"
34 set srcfile ${testfile}.c
35 set binfile ${objdir}/${subdir}/${testfile}
36 set corefile ${objdir}/${subdir}/${testfile}.corefile
37 set gcorefile ${objdir}/${subdir}/${testfile}.gcore
38
39 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
40 gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
41 }
42
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]"
46 file mkdir $coredir
47 set core_works [isnative]
48
49 # Run GDB on the test program up to where it will dump core.
50
51 gdb_exit
52 gdb_start
53 gdb_reinitialize_dir $srcdir/$subdir
54 gdb_load ${binfile}
55 gdb_test "set print sevenbit-strings" "" \
56 "set print sevenbit-strings; ${testfile}"
57 gdb_test "set width 0" "" \
58 "set width 0; ${testfile}"
59
60 if {$core_works} {
61 if {[gdb_test "cd $coredir" ".*Working directory .*" \
62 "cd to temporary directory for core dumps"]} {
63 set core_works 0
64 }
65 }
66
67 if { ![runto_main] } then {
68 gdb_suppress_tests;
69 }
70 set print_core_line [gdb_get_line_number "ABORT;"]
71 gdb_test "tbreak $print_core_line"
72 gdb_test continue ".*ABORT;.*"
73
74 proc fetch_auxv {test} {
75 global gdb_prompt
76
77 set auxv_lines {}
78 set bad -1
79 if {[gdb_test_multiple "info auxv" $test {
80 -re "info auxv\[\r\n\]+" {
81 exp_continue
82 }
83 -re "The program has no auxiliary information now.*$" {
84 set bad 1
85 exp_continue
86 }
87 -re "Auxiliary vector is empty.*$" {
88 set bad 1
89 exp_continue
90 }
91 -re "No auxiliary vector found.*$" {
92 set bad 1
93 exp_continue
94 }
95 -re "^\[0-9\]+\[ \t\]+(AT_\[^ \t\]+)\[^\r\n\]+\[\r\n\]+" {
96 lappend auxv_lines $expect_out(0,string)
97 exp_continue
98 }
99 -re "^\[0-9\]+\[ \t\]+\\?\\?\\?\[^\r\n\]+\[\r\n\]+" {
100 warning "Unrecognized tag value: $expect_out(0,string)"
101 set bad 1
102 lappend auxv_lines $expect_out(0,string)
103 exp_continue
104 }
105 -re "^\[^\r\n\]+\[\r\n\]+" {
106 warning "Unrecognized output: $expect_out(0,string)"
107 set bad 1
108 exp_continue
109 }
110 -re ".*$gdb_prompt $" {
111 incr bad
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 0
130 set escapedfilename [string_to_regexp $gcorefile]
131 gdb_test_multiple "gcore $gcorefile" "gcore" {
132 -re "Saved corefile ${escapedfilename}\[\r\n\]+$gdb_prompt $" {
133 pass "gcore"
134 set gcore_works 1
135 }
136 -re "Can't create a corefile\[\r\n\]+$gdb_prompt $" {
137 unsupported "gcore"
138 }
139 }
140
141 # Let the program continue and die.
142 gdb_test continue ".*Program received signal.*"
143 gdb_test continue ".*Program terminated with signal.*"
144
145 # Now collect the core dump it left.
146 set test "generate native core dump"
147 if {$core_works} {
148 # Find the
149 set names [glob -nocomplain -directory $coredir *core*]
150 if {[llength $names] == 1} {
151 set file [file join $coredir [lindex $names 0]]
152 remote_exec build "mv $file $corefile"
153 pass $test
154 } else {
155 set core_works 0
156 warning "can't generate a core file - core tests suppressed - check ulimit -c"
157 fail $test
158 }
159 } else {
160 unsupported $test
161 }
162 remote_exec build "rm -rf $coredir"
163
164 # Now we can examine the core files and check that their data matches what
165 # we saw in the process. Note that the exact data can vary between runs,
166 # so it's important that the native core dump file and the gcore-created dump
167 # both be from the same run of the program as we examined live.
168
169 proc do_core_test {works corefile test1 test2} {
170 if {! $works} {
171 unsupported $test1
172 unsupported $test2
173 } else {
174 gdb_test "core $corefile" "Core was generated by.*" \
175 "load core file for $test1" \
176 "A program is being debugged already.*" "y"
177 set core_data [fetch_auxv $test1]
178 global live_data
179 if {$core_data == $live_data} {
180 pass $test2
181 } else {
182 fail $test2
183 }
184 }
185 }
186
187 do_core_test $core_works $corefile \
188 "info auxv on native core dump" "matching auxv data from live and core"
189
190 do_core_test $gcore_works $gcorefile \
191 "info auxv on gcore-created dump" "matching auxv data from live and gcore"
This page took 0.034636 seconds and 5 git commands to generate.