1 # Copyright
1998-2023 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
}]} {
32 # Check the output of
'maint info target-sections' command.
33 proc check_maint_info_target_sections_output
{prefix
} {
36 with_test_prefix $prefix
{
37 # Check the output of the
'maint info target-sections' command.
38 # Ensures that all the lines have the expected format
, and that we see
39 # an auxiliary information line after
every section information line.
41 # We also check that
every bfd section has the ALLOC flag.
43 set seen_a_section false
44 set seen_aux_info false
45 set expecting_aux_info false
46 gdb_test_multiple
"maint info target-sections" "" {
47 -re
"^maint info target-sections\r\n" {
48 # Consume the command we sent to GDB that the terminal echo
'd
52 -re "^From '\
[^
\r\n\
]+', file type \[^\r\n\]+:\r\n" {
53 # There might be more than one header, but there should be at
56 if { $expecting_aux_info } {
62 -re "^ \\\[\[0-9\]+\\\]\\s+$hex->$hex at $hex: \[^*\r\]+\\yALLOC\\y\[^*\r\]*\r\n" {
63 # A bfd section description line.
64 set seen_a_section true
65 if { $expecting_aux_info } {
68 set expecting_aux_info true
72 -re "^\\s+Start: $hex, End: $hex, Owner token: $hex\r\n" {
73 # A target section auxiliary information line.
74 set seen_aux_info true
75 if { !$expecting_aux_info } {
78 set expecting_aux_info false
82 -re "^$gdb_prompt $" {
83 gdb_assert { $seen_header && $seen_a_section && $seen_aux_info }
84 gdb_assert { !$expecting_aux_info }
91 # Check that 'maint
info sections
' output looks correct. When
92 # checking the lines for each section we reject section names starting
93 # with a '*' character, the internal *COM*, *UND*, *ABS*, and *IND*
94 # sections should not be displayed in this output.
96 set seen_a_section false
97 gdb_test_multiple "maint info sections" "general output check" {
98 -re "Exec file: `\[^'\
]+', file type \[^.\]+\.\r\n" {
102 -re "^ \\\[\[0-9\]+\\\]\[\t \]+$hex->$hex at $hex: \[^*\r\]+\r\n" {
103 set seen_a_section true
106 -re "^$gdb_prompt $" {
107 gdb_assert { $seen_header && $seen_a_section }
112 # It'd be nice to check
for every possible section. However
, that
's
113 # problematic, since the relative ordering wanders from release to
114 # release of the compilers. Instead, we'll just check
for two
115 # sections which appear to always come out in the same relative
116 # order.
(If that changes
, then we should just check
for one
119 # And by the way
: This testpoint will
break for PA64
, where a.out
's
122 # Standard GNU names.
123 set text_section ".text"
124 set data_section ".data"
126 gdb_test_multiple "maint info sections" "" {
127 -re -wrap "Exec file: .*${binfile}., file type.*ER_RO.*" {
128 # Looks like RealView which uses different section names.
129 set text_section ER_RO
130 set data_section ER_RW
131 pass "maint info sections"
133 -re -wrap "Exec file: .*${binfile}., file type.*neardata.*" {
134 # c6x doesn't have .data section. It has .neardata and .fardata section.
135 set data_section
".neardata"
136 pass
"maint info sections"
138 -re
-wrap
"Exec file: .*${binfile}., file type.*" {
139 pass
"maint info sections"
143 # Test
for new option
: maint
info sections
<section
name>
144 #
If you don
't have a .text section, this will require tweaking.
146 gdb_test_multiple "maint info sections $text_section" "" {
147 -re -wrap " \\.bss .*" {
150 -re -wrap " $data_section .*" {
153 -re -wrap " $text_section .*" {
158 # Test for new option: CODE section flag
159 # If your data section is tagged CODE, xfail this test.
161 gdb_test_multiple "maint info sections CODE" "" {
162 -re -wrap " $data_section .*" {
165 -re -wrap " $text_section .*" {
170 # Test for new option: DATA section flag
171 # If your text section is tagged DATA, xfail this test.
173 # The "maint info sections DATA" test is marked for XFAIL on Windows,
174 # because Windows has text sections marked DATA.
175 setup_xfail "*-*-*cygwin*"
176 setup_xfail "*-*-*mingw*"
178 gdb_test_multiple "maint info sections DATA" "" {
179 -re -wrap " $text_section .*" {
182 -re -wrap " $data_section .*" {
185 -re -wrap " .rodata .*" {
190 check_maint_info_target_sections_output "with executable"
192 # Restart GDB, but don't
load the executable.
195 # Now
load the executable in as a symbol file.
196 gdb_test
"add-symbol-file ${binfile}" ".*" \
197 "load the executable as a symbol file" \
198 "add symbol table from file \"${binfile}\"\r\n\\(y or n\\) " \
201 # As we have no object file
'maint info sections' will print nothing.
202 gdb_test_no_output
"maint info sections" \
203 "no output when no executable is set"
205 # Check that the executable shows up as an object file when
206 #
-all
-objects is used.
207 set seen_header false
208 set seen_a_section false
209 gdb_test_multiple
"maint info sections -all-objects" "" {
210 -re
"Object file: `${binfile}', file type \[^.\]+\.\r\n" {
214 -re
"^ \\\[\[0-9\]+\\\]\[\t \]+$hex->$hex at $hex: \[^*\r\]+\r\n" {
215 set seen_a_section true
218 -re
"^$gdb_prompt $" {
219 gdb_assert
{ $seen_header
&& $seen_a_section
} \
220 "ensure header and section seen in -all-objects case"
225 check_maint_info_target_sections_output
"with loaded symbol file"
227 # Test the command line completion
on 'maint info sections'. First
228 # the command line flag.
229 test_gdb_complete_unique \
230 "maintenance info sections -" \
231 "maintenance info sections -all-objects"
233 # Now check the section flags complete.
234 test_gdb_complete_multiple
"maintenance info sections " "" "" {
237 "COFF_SHARED_LIBRARY"