1 # Copyright 2002, 2003, 2005, 2007, 2008, 2009, 2010
2 # Free Software Foundation, Inc.
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.
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.
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/>. */
17 # relocate.exp -- Expect script to test loading symbols from unrelocated
25 set srcfile ${testfile}.c
26 set binfile ${objdir}/${subdir}/${testfile}.o
28 remote_exec build "rm -f ${binfile}"
29 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" object {debug}] != "" } {
34 proc get_var_address { var } {
40 # $6 = (int (*)()) 0x24 <function_bar>
42 gdb_test_multiple "print &${var}" "get address of ${var}" {
43 -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)
59 gdb_reinitialize_dir $srcdir/$subdir
61 # Load the object file.
62 gdb_test "add-symbol-file ${binfile} 0" \
63 "Reading symbols from .*${testfile}\\.o\\.\\.\\.done\\.(|\r\nUsing host libthread_db library .*libthread_db.so.*\\.)" \
64 "add-symbol-file ${testfile}.o 0" \
65 "add symbol table from file \".*${testfile}\\.o\" at\[ \t\r\n\]+\.text_addr = 0x0\[\r\n\]+\\(y or n\\) " \
68 # Print the addresses of static variables.
69 set static_foo_addr [get_var_address static_foo]
70 set static_bar_addr [get_var_address static_bar]
72 # Make sure they have different addresses.
73 if { "${static_foo_addr}" == "${static_bar_addr}" } {
74 fail "static variables have different addresses"
76 pass "static variables have different addresses"
79 # Print the addresses of global variables.
80 set global_foo_addr [get_var_address global_foo]
81 set global_bar_addr [get_var_address global_bar]
83 # Make sure they have different addresses.
84 if { "${global_foo_addr}" == "${global_bar_addr}" } {
85 fail "global variables have different addresses"
87 pass "global variables have different addresses"
90 # Print the addresses of functions.
91 set function_foo_addr [get_var_address function_foo]
92 set function_bar_addr [get_var_address function_bar]
94 # Make sure they have different addresses.
95 if { "${function_foo_addr}" == "${function_bar_addr}" } {
96 fail "functions have different addresses"
98 pass "functions have different addresses"
101 # Now use a variable as an offset to add-symbol-file, and check that
102 # the functions' addresses change.
106 gdb_reinitialize_dir $srcdir/$subdir
108 gdb_test_no_output "set \$offset = 0x10000"
110 # Load the object file.
111 gdb_test "add-symbol-file ${binfile} \$offset" \
112 "Reading symbols from .*${testfile}\\.o\\.\\.\\.done\\.(|\r\nUsing host libthread_db library .*libthread_db.so.*\\.)" \
113 "add-symbol-file ${testfile}.o \$offset" \
114 "add symbol table from file \".*${testfile}\\.o\" at\[ \t\r\n\]+\.text_addr = 0x10000\[\r\n\]+\\(y or n\\) " \
117 # Print the addresses of functions.
118 set new_function_foo_addr [get_var_address function_foo]
120 # Make sure they have different addresses.
121 if { "${function_foo_addr}" == "${new_function_foo_addr}" } {
122 fail "function foo has a different address"
124 pass "function foo has a different address"
127 # Now try loading the object as an exec-file; we should be able to print
128 # the values of variables after we do this.
132 gdb_reinitialize_dir $srcdir/$subdir
133 gdb_file_cmd ${binfile}
135 # Check the values of the variables.
136 gdb_test "print static_foo" "\\\$$decimal = 1"
137 gdb_test "print static_bar" "\\\$$decimal = 2"
138 gdb_test "print global_foo" "\\\$$decimal = 3"
139 gdb_test "print global_bar" "\\\$$decimal = 4"