]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/testsuite/gdb.base/code_elim.exp
Update Copyright year range in all files maintained by GDB.
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.base / code_elim.exp
CommitLineData
ecd75fc8 1# Copyright 2002-2014 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] != "" } {
35 untested code_elim.exp
36 return -1
37}
38
39if { [gdb_compile "${srcdir}/${subdir}/${srcfile2}" "${binfile2}" executable $opts] != "" } {
40 untested code_elim.exp
41 return -1
42}
43
44proc get_var_address { var } {
45 global gdb_prompt hex
46
47 # Match output like:
48 # $1 = (int *) 0x0
49 # $5 = (int (*)()) 0
50 # $6 = (int (*)()) 0x24 <function_bar>
51
52 gdb_test_multiple "print &${var}" "get address of ${var}" {
53 -re "\\\$\[0-9\]+ = \\(.*\\) (0|$hex)( <${var}>)?\[\r\n\]+${gdb_prompt} $" {
54 pass "get address of ${var}"
55 if { $expect_out(1,string) == "0" } {
56 return "0x0"
57 } else {
58 return $expect_out(1,string)
59 }
60 }
61 }
62 return ""
63}
64
65proc not_null_var_address { var } {
66
67 # Same as get_var_address, expect that it reports a failure if a null
68 # address is returned by gdb.
69
70 set address [get_var_address $var]
71 regexp "0x\[0-9a-fA-F\]+" $address address
72 if { "$address" == "0x0" } {
73 fail "$var has null address"
74 }
75}
76
77proc test_eliminated_var { var } {
78 global gdb_prompt hex
79
80 # Match output 'No symbol "${var}" in current context'
81
82 gdb_test_multiple "print &${var}" "test eliminated var ${var}" {
83 -re "No symbol \"${var}\" in current context\\.\[\r\n\]+${gdb_prompt} $" {
84 pass "test eliminated var ${var}"
85 }
86 -re "\\\$\[0-9\]+ = \\(.*\\) (0|$hex)( <${var}>)?\[\r\n\]+${gdb_prompt} $" {
87 fail "test eliminated var ${var}"
88 }
89 }
90}
91
92# Check that the code and data eliminated in binfile1 are not included
93# into partial symtab... and that non-eliminated symbols are still there.
94
95gdb_exit
96gdb_start
97
d0d86158 98gdb_test "symbol-file ${binfile1}" \
a04ba985 99 "Reading symbols from .*${testfile1}\\.\\.\\.done\\.(|\r\nUsing host libthread_db library .*libthread_db.so.*\\.)" \
d0d86158 100 "symbol-file ${testfile1}"
a04ba985 101
d0d86158
JK
102with_test_prefix "single psymtabs" {
103 test_eliminated_var my_global_symbol
104 test_eliminated_var my_static_symbol
105 test_eliminated_var my_global_func
106 not_null_var_address main
107}
a04ba985
JG
108
109# Same thing for symtabs
110
111gdb_exit
112global GDBFLAGS
113set saved_gdbflags $GDBFLAGS
114set GDBFLAGS "$GDBFLAGS --readnow $binfile1"
115gdb_start
116set GDBFLAGS $saved_gdbflags
117
d0d86158
JK
118with_test_prefix "single symtabs" {
119 test_eliminated_var my_global_symbol
120 test_eliminated_var my_static_symbol
121 test_eliminated_var my_global_func
122 not_null_var_address main
123}
a04ba985
JG
124
125# binfile2 contains the symbols that have been eliminated in binfile1. Check
126# the eliminated symbols does not hide these valid ones.
127
128gdb_exit
129gdb_start
130
d0d86158 131with_test_prefix "order1" {
952cf74c
JK
132 gdb_test "add-symbol-file ${binfile1} 0x100000 -s .bss 0x120000" \
133 "Reading symbols from .*${testfile1}\\.\\.\\.done\\." \
134 "add-symbol-file ${testfile1} 0x100000" \
135 "add symbol table from file \".*${testfile1}\" at.*\\(y or n\\) " \
136 "y"
137
138 gdb_test "add-symbol-file ${binfile2} 0x200000 -s .data 0x210000 -s .bss 0x220000" \
139 "Reading symbols from .*${testfile2}\\.\\.\\.done\\." \
140 "add-symbol-file ${testfile2} 0x200000" \
141 "add symbol table from file \".*${testfile2}\" at.*\\(y or n\\) " \
142 "y"
143
d0d86158
JK
144 not_null_var_address my_global_symbol
145 not_null_var_address my_static_symbol
146 not_null_var_address my_global_func
147 not_null_var_address main
148}
a04ba985
JG
149
150# Same thing, but loading binfile2 before binfile1.
151
152gdb_exit
153gdb_start
154
d0d86158 155with_test_prefix "order2" {
952cf74c
JK
156 gdb_test "add-symbol-file ${binfile2} 0x200000 -s .data 0x210000 -s .bss 0x220000" \
157 "Reading symbols from .*${testfile2}\\.\\.\\.done\\." \
158 "add-symbol-file ${testfile2} 0x200000" \
159 "add symbol table from file \".*${testfile2}\" at.*\\(y or n\\) " \
160 "y"
161
162 gdb_test "add-symbol-file ${binfile1} 0x100000 -s .bss 0x120000" \
163 "Reading symbols from .*${testfile1}\\.\\.\\.done\\." \
164 "add-symbol-file ${testfile1} 0x100000" \
165 "add symbol table from file \".*${testfile1}\" at.*\\(y or n\\) " \
166 "y"
167
d0d86158
JK
168 not_null_var_address my_global_symbol
169 not_null_var_address my_static_symbol
170 not_null_var_address my_global_func
171 not_null_var_address main
172}