1 # Copyright 1998-2022 Free Software Foundation, Inc.
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 3 of the License, or
6 # (at your option) any later version.
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License
14 # along with this program. If not, see <http://www.gnu.org/licenses/>.
16 # Test just for the 'maintenance info sections' command and the
17 # 'maintenance info target-sections' command.
19 load_lib completion-support.exp
21 standard_testfile break.c break1.c
23 if {[prepare_for_testing "failed to prepare" $testfile \
24 [list $srcfile $srcfile2] {debug nowarnings}]} {
28 if ![runto_main] then {
29 untested "maint info sections"
33 # Check the output of 'maint info target-sections' command.
34 proc check_maint_info_target_sections_output {prefix} {
37 with_test_prefix $prefix {
38 # Check the output of the 'maint info target-sections' command.
39 # Ensures that all the lines have the expected format, and that we see
40 # an auxiliary information line after every section information line.
42 # We also check that every bfd section has the ALLOC flag.
44 set seen_a_section false
45 set seen_aux_info false
46 set expecting_aux_info false
47 gdb_test_multiple "maint info target-sections" "" {
48 -re "^maint info target-sections\r\n" {
49 # Consume the command we sent to GDB that the terminal echo'd
53 -re "^From '\[^\r\n\]+', file type \[^\r\n\]+:\r\n" {
54 # There might be more than one header, but there should be at
57 if { $expecting_aux_info } {
63 -re "^ \\\[\[0-9\]+\\\]\\s+$hex->$hex at $hex: \[^*\r\]+\\yALLOC\\y\[^*\r\]*\r\n" {
64 # A bfd section description line.
65 set seen_a_section true
66 if { $expecting_aux_info } {
69 set expecting_aux_info true
73 -re "^\\s+Start: $hex, End: $hex, Owner token: $hex\r\n" {
74 # A target section auxiliary information line.
75 set seen_aux_info true
76 if { !$expecting_aux_info } {
79 set expecting_aux_info false
83 -re "^$gdb_prompt $" {
84 gdb_assert { $seen_header && $seen_a_section && $seen_aux_info }
85 gdb_assert { !$expecting_aux_info }
92 # Check that 'maint info sections' output looks correct. When
93 # checking the lines for each section we reject section names starting
94 # with a '*' character, the internal *COM*, *UND*, *ABS*, and *IND*
95 # sections should not be displayed in this output.
97 set seen_a_section false
98 gdb_test_multiple "maint info sections" "general output check" {
99 -re "Exec file: `\[^'\]+', file type \[^.\]+\.\r\n" {
103 -re "^ \\\[\[0-9\]+\\\]\[\t \]+$hex->$hex at $hex: \[^*\r\]+\r\n" {
104 set seen_a_section true
107 -re "^$gdb_prompt $" {
108 gdb_assert { $seen_header && $seen_a_section }
113 # It'd be nice to check for every possible section. However, that's
114 # problematic, since the relative ordering wanders from release to
115 # release of the compilers. Instead, we'll just check for two
116 # sections which appear to always come out in the same relative
117 # order. (If that changes, then we should just check for one
120 # And by the way: This testpoint will break for PA64, where a.out's
123 # Standard GNU names.
124 set text_section ".text"
125 set data_section ".data"
127 gdb_test_multiple "maint info sections" "" {
128 -re -wrap "Exec file: .*${binfile}., file type.*ER_RO.*" {
129 # Looks like RealView which uses different section names.
130 set text_section ER_RO
131 set data_section ER_RW
132 pass "maint info sections"
134 -re -wrap "Exec file: .*${binfile}., file type.*neardata.*" {
135 # c6x doesn't have .data section. It has .neardata and .fardata section.
136 set data_section ".neardata"
137 pass "maint info sections"
139 -re -wrap "Exec file: .*${binfile}., file type.*" {
140 pass "maint info sections"
144 # Test for new option: maint info sections <section name>
145 # If you don't have a .text section, this will require tweaking.
147 gdb_test_multiple "maint info sections $text_section" "" {
148 -re -wrap " \\.bss .*" {
151 -re -wrap " $data_section .*" {
154 -re -wrap " $text_section .*" {
159 # Test for new option: CODE section flag
160 # If your data section is tagged CODE, xfail this test.
162 gdb_test_multiple "maint info sections CODE" "" {
163 -re -wrap " $data_section .*" {
166 -re -wrap " $text_section .*" {
171 # Test for new option: DATA section flag
172 # If your text section is tagged DATA, xfail this test.
174 # The "maint info sections DATA" test is marked for XFAIL on Windows,
175 # because Windows has text sections marked DATA.
176 setup_xfail "*-*-*cygwin*"
177 setup_xfail "*-*-*mingw*"
179 gdb_test_multiple "maint info sections DATA" "" {
180 -re -wrap " $text_section .*" {
183 -re -wrap " $data_section .*" {
186 -re -wrap " .rodata .*" {
191 check_maint_info_target_sections_output "with executable"
193 # Restart GDB, but don't load the executable.
196 # Now load the executable in as a symbol file.
197 gdb_test "add-symbol-file ${binfile}" ".*" \
198 "load the executable as a symbol file" \
199 "add symbol table from file \"${binfile}\"\r\n\\(y or n\\) " \
202 # As we have no object file 'maint info sections' will print nothing.
203 gdb_test_no_output "maint info sections" \
204 "no output when no executable is set"
206 # Check that the executable shows up as an object file when
207 # -all-objects is used.
208 set seen_header false
209 set seen_a_section false
210 gdb_test_multiple "maint info sections -all-objects" "" {
211 -re "Object file: `${binfile}', file type \[^.\]+\.\r\n" {
215 -re "^ \\\[\[0-9\]+\\\]\[\t \]+$hex->$hex at $hex: \[^*\r\]+\r\n" {
216 set seen_a_section true
219 -re "^$gdb_prompt $" {
220 gdb_assert { $seen_header && $seen_a_section } \
221 "ensure header and section seen in -all-objects case"
226 check_maint_info_target_sections_output "with loaded symbol file"
228 # Test the command line completion on 'maint info sections'. First
229 # the command line flag.
230 test_gdb_complete_unique \
231 "maintenance info sections -" \
232 "maintenance info sections -all-objects"
234 # Now check the section flags complete.
235 test_gdb_complete_multiple "maintenance info sections " "" "" {
238 "COFF_SHARED_LIBRARY"