Automatic Copyright Year update after running gdb/copyright.py
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.base / maint-info-sections.exp
CommitLineData
88b9d363 1# Copyright 1998-2022 Free Software Foundation, Inc.
f4be6772
AB
2
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.
7#
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.
12#
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/>.
15
02a79309
AB
16# Test just for the 'maintenance info sections' command and the
17# 'maintenance info target-sections' command.
f4be6772 18
bf3386f0
AB
19load_lib completion-support.exp
20
f4be6772
AB
21standard_testfile break.c break1.c
22
23if {[prepare_for_testing "failed to prepare" $testfile \
24 [list $srcfile $srcfile2] {debug nowarnings}]} {
25 return -1
26}
27
28if ![runto_main] then {
29 untested "maint info sections"
30 return -1
31}
32
02a79309
AB
33# Check the output of 'maint info target-sections' command.
34proc check_maint_info_target_sections_output {prefix} {
35 global hex gdb_prompt
36
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.
41 #
42 # We also check that every bfd section has the ALLOC flag.
43 set seen_header false
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
50 # back.
51 exp_continue
52 }
53 -re "^From '\[^\r\n\]+', file type \[^\r\n\]+:\r\n" {
54 # There might be more than one header, but there should be at
55 # least one.
56 set seen_header true
57 if { $expecting_aux_info } {
58 fail $gdb_test_name
59 } else {
60 exp_continue
61 }
62 }
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 } {
67 fail $gdb_test_name
68 } else {
69 set expecting_aux_info true
70 exp_continue
71 }
72 }
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 } {
77 fail $gdb_test_name
78 } else {
79 set expecting_aux_info false
80 exp_continue
81 }
82 }
83 -re "^$gdb_prompt $" {
84 gdb_assert { $seen_header && $seen_a_section && $seen_aux_info }
85 gdb_assert { !$expecting_aux_info }
86 pass $gdb_test_name
87 }
88 }
89 }
90}
91
f4be6772
AB
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.
96set seen_header false
97set seen_a_section false
98gdb_test_multiple "maint info sections" "general output check" {
4790db14 99 -re "Exec file: `\[^'\]+', file type \[^.\]+\.\r\n" {
f4be6772
AB
100 set seen_header true
101 exp_continue
102 }
103 -re "^ \\\[\[0-9\]+\\\]\[\t \]+$hex->$hex at $hex: \[^*\r\]+\r\n" {
104 set seen_a_section true
105 exp_continue
106 }
107 -re "^$gdb_prompt $" {
108 gdb_assert { $seen_header && $seen_a_section }
109 pass $gdb_test_name
110 }
111}
112
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
118# section.)
119#
120# And by the way: This testpoint will break for PA64, where a.out's
121# are ELF files.
122
123# Standard GNU names.
124set text_section ".text"
125set data_section ".data"
126
127gdb_test_multiple "maint info sections" "" {
4790db14 128 -re -wrap "Exec file: .*${binfile}., file type.*ER_RO.*" {
f4be6772
AB
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"
133 }
4790db14 134 -re -wrap "Exec file: .*${binfile}., file type.*neardata.*" {
f4be6772
AB
135 # c6x doesn't have .data section. It has .neardata and .fardata section.
136 set data_section ".neardata"
137 pass "maint info sections"
138 }
4790db14 139 -re -wrap "Exec file: .*${binfile}., file type.*" {
f4be6772
AB
140 pass "maint info sections"
141 }
142}
143
144# Test for new option: maint info sections <section name>
145# If you don't have a .text section, this will require tweaking.
146
147gdb_test_multiple "maint info sections $text_section" "" {
148 -re -wrap " \\.bss .*" {
149 fail $gdb_test_name
150 }
151 -re -wrap " $data_section .*" {
152 fail $gdb_test_name
153 }
154 -re -wrap " $text_section .*" {
155 pass $gdb_test_name
156 }
157}
158
159# Test for new option: CODE section flag
160# If your data section is tagged CODE, xfail this test.
161
162gdb_test_multiple "maint info sections CODE" "" {
163 -re -wrap " $data_section .*" {
164 fail $gdb_test_name
165 }
166 -re -wrap " $text_section .*" {
167 pass $gdb_test_name
168 }
169}
170
171# Test for new option: DATA section flag
172# If your text section is tagged DATA, xfail this test.
173#
174# The "maint info sections DATA" test is marked for XFAIL on Windows,
175# because Windows has text sections marked DATA.
176setup_xfail "*-*-*cygwin*"
177setup_xfail "*-*-*mingw*"
178
179gdb_test_multiple "maint info sections DATA" "" {
180 -re -wrap " $text_section .*" {
181 fail $gdb_test_name
182 }
183 -re -wrap " $data_section .*" {
184 pass $gdb_test_name
185 }
186 -re -wrap " .rodata .*" {
187 pass $gdb_test_name
188 }
189}
4790db14 190
02a79309
AB
191check_maint_info_target_sections_output "with executable"
192
4790db14
AB
193# Restart GDB, but don't load the executable.
194clean_restart
195
196# Now load the executable in as a symbol file.
197gdb_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\\) " \
200 "y"
201
202# As we have no object file 'maint info sections' will print nothing.
203gdb_test_no_output "maint info sections" \
204 "no output when no executable is set"
205
bf3386f0
AB
206# Check that the executable shows up as an object file when
207# -all-objects is used.
4790db14
AB
208set seen_header false
209set seen_a_section false
bf3386f0 210gdb_test_multiple "maint info sections -all-objects" "" {
4790db14
AB
211 -re "Object file: `${binfile}', file type \[^.\]+\.\r\n" {
212 set seen_header true
213 exp_continue
214 }
215 -re "^ \\\[\[0-9\]+\\\]\[\t \]+$hex->$hex at $hex: \[^*\r\]+\r\n" {
216 set seen_a_section true
217 exp_continue
218 }
219 -re "^$gdb_prompt $" {
220 gdb_assert { $seen_header && $seen_a_section } \
bf3386f0 221 "ensure header and section seen in -all-objects case"
4790db14
AB
222 pass $gdb_test_name
223 }
224}
bf3386f0 225
336aa7b7 226check_maint_info_target_sections_output "with loaded symbol file"
02a79309 227
bf3386f0
AB
228# Test the command line completion on 'maint info sections'. First
229# the command line flag.
230test_gdb_complete_unique \
231 "maintenance info sections -" \
232 "maintenance info sections -all-objects"
233
234# Now check the section flags complete.
235test_gdb_complete_multiple "maintenance info sections " "" "" {
236 "ALLOC"
237 "CODE"
238 "COFF_SHARED_LIBRARY"
239 "CONSTRUCTOR"
240 "DATA"
241 "HAS_CONTENTS"
242 "IS_COMMON"
243 "LOAD"
244 "NEVER_LOAD"
245 "READONLY"
246 "RELOC"
247 "ROM"
248}
This page took 0.128649 seconds and 4 git commands to generate.