Target FP: Make use of MPFR if available
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.base / code_elim.exp
CommitLineData
61baf725 1# Copyright 2002-2017 Free Software Foundation, Inc.
a04ba985
JG
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# code_elim.exp -- tests that GDB can handle executables where some data/code
17# has been eliminated by the linker.
18
a04ba985
JG
19set testfile1 code_elim1
20set testfile2 code_elim2
21set srcfile1 ${testfile1}.c
22set srcfile2 ${testfile2}.c
f76495c8
TT
23set binfile1 [standard_output_file ${testfile1}]
24set binfile2 [standard_output_file ${testfile2}]
a04ba985
JG
25set opts [list debug]
26lappend opts "additional_flags=-ffunction-sections"
27lappend opts "additional_flags=-fdata-sections"
28lappend opts "additional_flags=-Wl,-gc-sections"
29lappend opts "additional_flags=-Wl,-e,main"
30
31remote_exec build "rm -f ${binfile1}"
32remote_exec build "rm -f ${binfile2}"
33
34if { [gdb_compile "${srcdir}/${subdir}/${srcfile1}" "${binfile1}" executable $opts] != "" } {
5b362f04 35 untested "failed to compile"
a04ba985
JG
36 return -1
37}
38
39if { [gdb_compile "${srcdir}/${subdir}/${srcfile2}" "${binfile2}" executable $opts] != "" } {
5b362f04 40 untested "failed to compile"
a04ba985
JG
41 return -1
42}
43
a04ba985
JG
44proc not_null_var_address { var } {
45
46 # Same as get_var_address, expect that it reports a failure if a null
47 # address is returned by gdb.
48
49 set address [get_var_address $var]
50 regexp "0x\[0-9a-fA-F\]+" $address address
51 if { "$address" == "0x0" } {
52 fail "$var has null address"
53 }
54}
55
56proc test_eliminated_var { var } {
57 global gdb_prompt hex
58
59 # Match output 'No symbol "${var}" in current context'
60
61 gdb_test_multiple "print &${var}" "test eliminated var ${var}" {
62 -re "No symbol \"${var}\" in current context\\.\[\r\n\]+${gdb_prompt} $" {
63 pass "test eliminated var ${var}"
64 }
65 -re "\\\$\[0-9\]+ = \\(.*\\) (0|$hex)( <${var}>)?\[\r\n\]+${gdb_prompt} $" {
66 fail "test eliminated var ${var}"
67 }
68 }
69}
70
71# Check that the code and data eliminated in binfile1 are not included
72# into partial symtab... and that non-eliminated symbols are still there.
73
74gdb_exit
75gdb_start
76
d0d86158 77gdb_test "symbol-file ${binfile1}" \
a04ba985 78 "Reading symbols from .*${testfile1}\\.\\.\\.done\\.(|\r\nUsing host libthread_db library .*libthread_db.so.*\\.)" \
d0d86158 79 "symbol-file ${testfile1}"
a04ba985 80
d0d86158
JK
81with_test_prefix "single psymtabs" {
82 test_eliminated_var my_global_symbol
83 test_eliminated_var my_static_symbol
84 test_eliminated_var my_global_func
85 not_null_var_address main
86}
a04ba985
JG
87
88# Same thing for symtabs
89
90gdb_exit
91global GDBFLAGS
92set saved_gdbflags $GDBFLAGS
93set GDBFLAGS "$GDBFLAGS --readnow $binfile1"
94gdb_start
95set GDBFLAGS $saved_gdbflags
96
d0d86158
JK
97with_test_prefix "single symtabs" {
98 test_eliminated_var my_global_symbol
99 test_eliminated_var my_static_symbol
100 test_eliminated_var my_global_func
101 not_null_var_address main
102}
a04ba985
JG
103
104# binfile2 contains the symbols that have been eliminated in binfile1. Check
105# the eliminated symbols does not hide these valid ones.
106
107gdb_exit
108gdb_start
109
d0d86158 110with_test_prefix "order1" {
952cf74c
JK
111 gdb_test "add-symbol-file ${binfile1} 0x100000 -s .bss 0x120000" \
112 "Reading symbols from .*${testfile1}\\.\\.\\.done\\." \
113 "add-symbol-file ${testfile1} 0x100000" \
114 "add symbol table from file \".*${testfile1}\" at.*\\(y or n\\) " \
115 "y"
116
117 gdb_test "add-symbol-file ${binfile2} 0x200000 -s .data 0x210000 -s .bss 0x220000" \
118 "Reading symbols from .*${testfile2}\\.\\.\\.done\\." \
119 "add-symbol-file ${testfile2} 0x200000" \
120 "add symbol table from file \".*${testfile2}\" at.*\\(y or n\\) " \
121 "y"
122
d0d86158
JK
123 not_null_var_address my_global_symbol
124 not_null_var_address my_static_symbol
125 not_null_var_address my_global_func
126 not_null_var_address main
127}
a04ba985
JG
128
129# Same thing, but loading binfile2 before binfile1.
130
131gdb_exit
132gdb_start
133
d0d86158 134with_test_prefix "order2" {
952cf74c
JK
135 gdb_test "add-symbol-file ${binfile2} 0x200000 -s .data 0x210000 -s .bss 0x220000" \
136 "Reading symbols from .*${testfile2}\\.\\.\\.done\\." \
137 "add-symbol-file ${testfile2} 0x200000" \
138 "add symbol table from file \".*${testfile2}\" at.*\\(y or n\\) " \
139 "y"
140
141 gdb_test "add-symbol-file ${binfile1} 0x100000 -s .bss 0x120000" \
142 "Reading symbols from .*${testfile1}\\.\\.\\.done\\." \
143 "add-symbol-file ${testfile1} 0x100000" \
144 "add symbol table from file \".*${testfile1}\" at.*\\(y or n\\) " \
145 "y"
146
d0d86158
JK
147 not_null_var_address my_global_symbol
148 not_null_var_address my_static_symbol
149 not_null_var_address my_global_func
150 not_null_var_address main
151}
This page took 0.834676 seconds and 4 git commands to generate.