gdb: 'maint info sections' - handle the no executable case
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.base / maint-info-sections.exp
1 # Copyright 1998-2021 Free Software Foundation, Inc.
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
16 # Test just for the 'maintenance info sections' command.
17
18 standard_testfile break.c break1.c
19
20 if {[prepare_for_testing "failed to prepare" $testfile \
21 [list $srcfile $srcfile2] {debug nowarnings}]} {
22 return -1
23 }
24
25 if ![runto_main] then {
26 untested "maint info sections"
27 return -1
28 }
29
30 # Check that 'maint info sections' output looks correct. When
31 # checking the lines for each section we reject section names starting
32 # with a '*' character, the internal *COM*, *UND*, *ABS*, and *IND*
33 # sections should not be displayed in this output.
34 set seen_header false
35 set seen_a_section false
36 gdb_test_multiple "maint info sections" "general output check" {
37 -re "Exec file: `\[^'\]+', file type \[^.\]+\.\r\n" {
38 set seen_header true
39 exp_continue
40 }
41 -re "^ \\\[\[0-9\]+\\\]\[\t \]+$hex->$hex at $hex: \[^*\r\]+\r\n" {
42 set seen_a_section true
43 exp_continue
44 }
45 -re "^$gdb_prompt $" {
46 gdb_assert { $seen_header && $seen_a_section }
47 pass $gdb_test_name
48 }
49 }
50
51 # It'd be nice to check for every possible section. However, that's
52 # problematic, since the relative ordering wanders from release to
53 # release of the compilers. Instead, we'll just check for two
54 # sections which appear to always come out in the same relative
55 # order. (If that changes, then we should just check for one
56 # section.)
57 #
58 # And by the way: This testpoint will break for PA64, where a.out's
59 # are ELF files.
60
61 # Standard GNU names.
62 set text_section ".text"
63 set data_section ".data"
64
65 gdb_test_multiple "maint info sections" "" {
66 -re -wrap "Exec file: .*${binfile}., file type.*ER_RO.*" {
67 # Looks like RealView which uses different section names.
68 set text_section ER_RO
69 set data_section ER_RW
70 pass "maint info sections"
71 }
72 -re -wrap "Exec file: .*${binfile}., file type.*neardata.*" {
73 # c6x doesn't have .data section. It has .neardata and .fardata section.
74 set data_section ".neardata"
75 pass "maint info sections"
76 }
77 -re -wrap "Exec file: .*${binfile}., file type.*" {
78 pass "maint info sections"
79 }
80 }
81
82 # Test for new option: maint info sections <section name>
83 # If you don't have a .text section, this will require tweaking.
84
85 gdb_test_multiple "maint info sections $text_section" "" {
86 -re -wrap " \\.bss .*" {
87 fail $gdb_test_name
88 }
89 -re -wrap " $data_section .*" {
90 fail $gdb_test_name
91 }
92 -re -wrap " $text_section .*" {
93 pass $gdb_test_name
94 }
95 }
96
97 # Test for new option: CODE section flag
98 # If your data section is tagged CODE, xfail this test.
99
100 gdb_test_multiple "maint info sections CODE" "" {
101 -re -wrap " $data_section .*" {
102 fail $gdb_test_name
103 }
104 -re -wrap " $text_section .*" {
105 pass $gdb_test_name
106 }
107 }
108
109 # Test for new option: DATA section flag
110 # If your text section is tagged DATA, xfail this test.
111 #
112 # The "maint info sections DATA" test is marked for XFAIL on Windows,
113 # because Windows has text sections marked DATA.
114 setup_xfail "*-*-*cygwin*"
115 setup_xfail "*-*-*mingw*"
116
117 gdb_test_multiple "maint info sections DATA" "" {
118 -re -wrap " $text_section .*" {
119 fail $gdb_test_name
120 }
121 -re -wrap " $data_section .*" {
122 pass $gdb_test_name
123 }
124 -re -wrap " .rodata .*" {
125 pass $gdb_test_name
126 }
127 }
128
129 # Restart GDB, but don't load the executable.
130 clean_restart
131
132 # Now load the executable in as a symbol file.
133 gdb_test "add-symbol-file ${binfile}" ".*" \
134 "load the executable as a symbol file" \
135 "add symbol table from file \"${binfile}\"\r\n\\(y or n\\) " \
136 "y"
137
138 # As we have no object file 'maint info sections' will print nothing.
139 gdb_test_no_output "maint info sections" \
140 "no output when no executable is set"
141
142 # Check that the executable shows up as an object file when ALLOBJ is
143 # used.
144 set seen_header false
145 set seen_a_section false
146 gdb_test_multiple "maint info sections ALLOBJ" "" {
147 -re "Object file: `${binfile}', file type \[^.\]+\.\r\n" {
148 set seen_header true
149 exp_continue
150 }
151 -re "^ \\\[\[0-9\]+\\\]\[\t \]+$hex->$hex at $hex: \[^*\r\]+\r\n" {
152 set seen_a_section true
153 exp_continue
154 }
155 -re "^$gdb_prompt $" {
156 gdb_assert { $seen_header && $seen_a_section } \
157 "ensure header and section seen in ALLOBJ case"
158 pass $gdb_test_name
159 }
160 }
This page took 0.04085 seconds and 5 git commands to generate.