OSDN Git Service

2012-01-16 Pedro Alves <palves@redhat.com>
[pf3gnuchains/pf3gnuchains4x.git] / gdb / testsuite / gdb.base / code_elim.exp
1 # Copyright 2002-2003, 2005, 2007-2012 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 # code_elim.exp -- tests that GDB can handle executables where some data/code
17 #                  has been eliminated by the linker.
18
19 set testfile1 code_elim1
20 set testfile2 code_elim2
21 set srcfile1 ${testfile1}.c
22 set srcfile2 ${testfile2}.c
23 set binfile1 ${objdir}/${subdir}/${testfile1}
24 set binfile2 ${objdir}/${subdir}/${testfile2}
25 set opts [list debug]
26 lappend opts "additional_flags=-ffunction-sections"
27 lappend opts "additional_flags=-fdata-sections"
28 lappend opts "additional_flags=-Wl,-gc-sections"
29 lappend opts "additional_flags=-Wl,-e,main"
30
31 remote_exec build "rm -f ${binfile1}"
32 remote_exec build "rm -f ${binfile2}"
33
34 if { [gdb_compile "${srcdir}/${subdir}/${srcfile1}" "${binfile1}" executable $opts] != "" } {
35      untested code_elim.exp
36      return -1
37 }
38
39 if { [gdb_compile "${srcdir}/${subdir}/${srcfile2}" "${binfile2}" executable $opts] != "" } {
40      untested code_elim.exp
41      return -1
42 }
43
44 proc 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
65 proc 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
77 proc 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
95 gdb_exit
96 gdb_start
97
98 gdb_test "add-symbol-file ${binfile1} 0x100000" \
99         "Reading symbols from .*${testfile1}\\.\\.\\.done\\.(|\r\nUsing host libthread_db library .*libthread_db.so.*\\.)" \
100         "add-symbol-file ${testfile1} 0x100000" \
101         "add symbol table from file \".*${testfile1}\" at\[ \t\r\n\]+\.text_addr = 0x100000\[\r\n\]+\\(y or n\\) " \
102         "y"
103
104 test_eliminated_var my_global_symbol
105 test_eliminated_var my_static_symbol
106 test_eliminated_var my_global_func
107 not_null_var_address main
108
109 # Same thing for symtabs
110
111 gdb_exit
112 global GDBFLAGS
113 set saved_gdbflags $GDBFLAGS
114 set GDBFLAGS "$GDBFLAGS --readnow $binfile1"
115 gdb_start
116 set GDBFLAGS $saved_gdbflags
117
118 test_eliminated_var my_global_symbol
119 test_eliminated_var my_static_symbol
120 test_eliminated_var my_global_func
121 not_null_var_address main
122
123 # binfile2 contains the symbols that have been eliminated in binfile1. Check
124 # the eliminated symbols does not hide these valid ones.
125
126 gdb_exit
127 gdb_start
128
129 gdb_test "add-symbol-file ${binfile1} 0x100000" \
130         "Reading symbols from .*${testfile1}\\.\\.\\.done\\." \
131         "add-symbol-file ${testfile1} 0x100000" \
132         "add symbol table from file \".*${testfile1}\" at\[ \t\r\n\]+\.text_addr = 0x100000\[\r\n\]+\\(y or n\\) " \
133         "y"
134
135 gdb_test "add-symbol-file ${binfile2} 0x200000" \
136         "Reading symbols from .*${testfile2}\\.\\.\\.done\\." \
137         "add-symbol-file ${testfile2} 0x200000" \
138         "add symbol table from file \".*${testfile2}\" at\[ \t\r\n\]+\.text_addr = 0x200000\[\r\n\]+\\(y or n\\) " \
139         "y"
140
141 not_null_var_address my_global_symbol
142 not_null_var_address my_static_symbol
143 not_null_var_address my_global_func
144 not_null_var_address main
145
146 # Same thing, but loading binfile2 before binfile1.
147
148 gdb_exit
149 gdb_start
150
151 gdb_test "add-symbol-file ${binfile2} 0x200000" \
152         "Reading symbols from .*${testfile2}\\.\\.\\.done\\." \
153         "add-symbol-file ${testfile2} 0x200000" \
154         "add symbol table from file \".*${testfile2}\" at\[ \t\r\n\]+\.text_addr = 0x200000\[\r\n\]+\\(y or n\\) " \
155         "y"
156
157 gdb_test "add-symbol-file ${binfile1} 0x100000" \
158         "Reading symbols from .*${testfile1}\\.\\.\\.done\\." \
159         "add-symbol-file ${testfile1} 0x100000" \
160         "add symbol table from file \".*${testfile1}\" at\[ \t\r\n\]+\.text_addr = 0x100000\[\r\n\]+\\(y or n\\) " \
161         "y"
162
163 not_null_var_address my_global_symbol
164 not_null_var_address my_static_symbol
165 not_null_var_address my_global_func
166 not_null_var_address main
167
168