2011-05-30 Yao Qi <yao@codesourcery.com>
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.base / code_elim.exp
1 # Copyright 2002, 2003, 2005, 2007, 2008, 2009, 2010, 2011
2 # Free Software Foundation, Inc.
3
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 3 of the License, or
7 # (at your option) any later version.
8 #
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with this program. If not, see <http://www.gnu.org/licenses/>. */
16
17 # code_elim.exp -- tests that GDB can handle executables where some data/code
18 # has been eliminated by the linker.
19
20 if $tracelevel then {
21 strace $tracelevel
22 }
23
24 set testfile1 code_elim1
25 set testfile2 code_elim2
26 set srcfile1 ${testfile1}.c
27 set srcfile2 ${testfile2}.c
28 set binfile1 ${objdir}/${subdir}/${testfile1}
29 set binfile2 ${objdir}/${subdir}/${testfile2}
30 set opts [list debug]
31 lappend opts "additional_flags=-ffunction-sections"
32 lappend opts "additional_flags=-fdata-sections"
33 lappend opts "additional_flags=-Wl,-gc-sections"
34 lappend opts "additional_flags=-Wl,-e,main"
35
36 remote_exec build "rm -f ${binfile1}"
37 remote_exec build "rm -f ${binfile2}"
38
39 if { [gdb_compile "${srcdir}/${subdir}/${srcfile1}" "${binfile1}" executable $opts] != "" } {
40 untested code_elim.exp
41 return -1
42 }
43
44 if { [gdb_compile "${srcdir}/${subdir}/${srcfile2}" "${binfile2}" executable $opts] != "" } {
45 untested code_elim.exp
46 return -1
47 }
48
49 proc get_var_address { var } {
50 global gdb_prompt hex
51
52 # Match output like:
53 # $1 = (int *) 0x0
54 # $5 = (int (*)()) 0
55 # $6 = (int (*)()) 0x24 <function_bar>
56
57 gdb_test_multiple "print &${var}" "get address of ${var}" {
58 -re "\\\$\[0-9\]+ = \\(.*\\) (0|$hex)( <${var}>)?\[\r\n\]+${gdb_prompt} $" {
59 pass "get address of ${var}"
60 if { $expect_out(1,string) == "0" } {
61 return "0x0"
62 } else {
63 return $expect_out(1,string)
64 }
65 }
66 }
67 return ""
68 }
69
70 proc not_null_var_address { var } {
71
72 # Same as get_var_address, expect that it reports a failure if a null
73 # address is returned by gdb.
74
75 set address [get_var_address $var]
76 regexp "0x\[0-9a-fA-F\]+" $address address
77 if { "$address" == "0x0" } {
78 fail "$var has null address"
79 }
80 }
81
82 proc test_eliminated_var { var } {
83 global gdb_prompt hex
84
85 # Match output 'No symbol "${var}" in current context'
86
87 gdb_test_multiple "print &${var}" "test eliminated var ${var}" {
88 -re "No symbol \"${var}\" in current context\\.\[\r\n\]+${gdb_prompt} $" {
89 pass "test eliminated var ${var}"
90 }
91 -re "\\\$\[0-9\]+ = \\(.*\\) (0|$hex)( <${var}>)?\[\r\n\]+${gdb_prompt} $" {
92 fail "test eliminated var ${var}"
93 }
94 }
95 }
96
97 # Check that the code and data eliminated in binfile1 are not included
98 # into partial symtab... and that non-eliminated symbols are still there.
99
100 gdb_exit
101 gdb_start
102
103 gdb_test "add-symbol-file ${binfile1} 0x100000" \
104 "Reading symbols from .*${testfile1}\\.\\.\\.done\\.(|\r\nUsing host libthread_db library .*libthread_db.so.*\\.)" \
105 "add-symbol-file ${testfile1} 0x100000" \
106 "add symbol table from file \".*${testfile1}\" at\[ \t\r\n\]+\.text_addr = 0x100000\[\r\n\]+\\(y or n\\) " \
107 "y"
108
109 test_eliminated_var my_global_symbol
110 test_eliminated_var my_static_symbol
111 test_eliminated_var my_global_func
112 not_null_var_address main
113
114 # Same thing for symtabs
115
116 gdb_exit
117 global GDBFLAGS
118 set saved_gdbflags $GDBFLAGS
119 set GDBFLAGS "$GDBFLAGS --readnow $binfile1"
120 gdb_start
121 set GDBFLAGS $saved_gdbflags
122
123 test_eliminated_var my_global_symbol
124 test_eliminated_var my_static_symbol
125 test_eliminated_var my_global_func
126 not_null_var_address main
127
128 # binfile2 contains the symbols that have been eliminated in binfile1. Check
129 # the eliminated symbols does not hide these valid ones.
130
131 gdb_exit
132 gdb_start
133
134 gdb_test "add-symbol-file ${binfile1} 0x100000" \
135 "Reading symbols from .*${testfile1}\\.\\.\\.done\\." \
136 "add-symbol-file ${testfile1} 0x100000" \
137 "add symbol table from file \".*${testfile1}\" at\[ \t\r\n\]+\.text_addr = 0x100000\[\r\n\]+\\(y or n\\) " \
138 "y"
139
140 gdb_test "add-symbol-file ${binfile2} 0x200000" \
141 "Reading symbols from .*${testfile2}\\.\\.\\.done\\." \
142 "add-symbol-file ${testfile2} 0x200000" \
143 "add symbol table from file \".*${testfile2}\" at\[ \t\r\n\]+\.text_addr = 0x200000\[\r\n\]+\\(y or n\\) " \
144 "y"
145
146 not_null_var_address my_global_symbol
147 not_null_var_address my_static_symbol
148 not_null_var_address my_global_func
149 not_null_var_address main
150
151 # Same thing, but loading binfile2 before binfile1.
152
153 gdb_exit
154 gdb_start
155
156 gdb_test "add-symbol-file ${binfile2} 0x200000" \
157 "Reading symbols from .*${testfile2}\\.\\.\\.done\\." \
158 "add-symbol-file ${testfile2} 0x200000" \
159 "add symbol table from file \".*${testfile2}\" at\[ \t\r\n\]+\.text_addr = 0x200000\[\r\n\]+\\(y or n\\) " \
160 "y"
161
162 gdb_test "add-symbol-file ${binfile1} 0x100000" \
163 "Reading symbols from .*${testfile1}\\.\\.\\.done\\." \
164 "add-symbol-file ${testfile1} 0x100000" \
165 "add symbol table from file \".*${testfile1}\" at\[ \t\r\n\]+\.text_addr = 0x100000\[\r\n\]+\\(y or n\\) " \
166 "y"
167
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
173
This page took 0.035924 seconds and 4 git commands to generate.