1 # Copyright 2002, 2003, 2005, 2007, 2008, 2009 Free Software Foundation, Inc.
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.
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.
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/>. */
16 # relocate.exp -- Expect script to test loading symbols from unrelocated
24 set srcfile ${testfile}.c
25 set binfile ${objdir}/${subdir}/${testfile}.o
27 remote_exec build "rm -f ${binfile}"
28 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" object {debug}] != "" } {
33 proc get_var_address { var } {
36 send_gdb "print &${var}\n"
40 # $6 = (int (*)()) 0x24 <function_bar>
42 -re "\\\$\[0-9\]+ = \\(.*\\) (0|$hex)( <${var}>)?\[\r\n\]+${gdb_prompt} $"
44 pass "get address of ${var}"
45 if { $expect_out(1,string) == "0" } {
48 return $expect_out(1,string)
52 { fail "get address of ${var} (unknown output)" }
54 { fail "get address of ${var} (timeout)" }
63 gdb_reinitialize_dir $srcdir/$subdir
65 # Load the object file.
66 gdb_test "add-symbol-file ${binfile} 0" \
67 "Reading symbols from .*${testfile}\\.o\\.\\.\\.done\\.(|\r\nUsing host libthread_db library .*libthread_db.so.*\\.)" \
68 "add-symbol-file ${testfile}.o 0" \
69 "add symbol table from file \".*${testfile}\\.o\" at\[ \t\r\n\]+\.text_addr = 0x0\[\r\n\]+\\(y or n\\) " \
72 # Print the addresses of static variables.
73 set static_foo_addr [get_var_address static_foo]
74 set static_bar_addr [get_var_address static_bar]
76 # Make sure they have different addresses.
77 if { "${static_foo_addr}" == "${static_bar_addr}" } {
78 fail "static variables have different addresses"
80 pass "static variables have different addresses"
83 # Print the addresses of global variables.
84 set global_foo_addr [get_var_address global_foo]
85 set global_bar_addr [get_var_address global_bar]
87 # Make sure they have different addresses.
88 if { "${global_foo_addr}" == "${global_bar_addr}" } {
89 fail "global variables have different addresses"
91 pass "global variables have different addresses"
94 # Print the addresses of functions.
95 set function_foo_addr [get_var_address function_foo]
96 set function_bar_addr [get_var_address function_bar]
98 # Make sure they have different addresses.
99 if { "${function_foo_addr}" == "${function_bar_addr}" } {
100 fail "functions have different addresses"
102 pass "functions have different addresses"
105 # Now use a variable as an offset to add-symbol-file, and check that
106 # the functions' addresses change.
110 gdb_reinitialize_dir $srcdir/$subdir
112 gdb_test "set \$offset = 0x10000" ""
114 # Load the object file.
115 gdb_test "add-symbol-file ${binfile} \$offset" \
116 "Reading symbols from .*${testfile}\\.o\\.\\.\\.done\\.(|\r\nUsing host libthread_db library .*libthread_db.so.*\\.)" \
117 "add-symbol-file ${testfile}.o \$offset" \
118 "add symbol table from file \".*${testfile}\\.o\" at\[ \t\r\n\]+\.text_addr = 0x10000\[\r\n\]+\\(y or n\\) " \
121 # Print the addresses of functions.
122 set new_function_foo_addr [get_var_address function_foo]
124 # Make sure they have different addresses.
125 if { "${function_foo_addr}" == "${new_function_foo_addr}" } {
126 fail "function foo has a different address"
128 pass "function foo has a different address"
131 # Now try loading the object as an exec-file; we should be able to print
132 # the values of variables after we do this.
136 gdb_reinitialize_dir $srcdir/$subdir
137 gdb_file_cmd ${binfile}
139 # Check the values of the variables.
140 gdb_test "print static_foo" "\\\$$decimal = 1"
141 gdb_test "print static_bar" "\\\$$decimal = 2"
142 gdb_test "print global_foo" "\\\$$decimal = 3"
143 gdb_test "print global_bar" "\\\$$decimal = 4"