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