1 # Copyright 2002, 2003, 2005 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 2 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, write to the Free Software
15 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
17 # Please email any bugs, comments, and/or additions to this file to:
18 # bug-gdb@prep.ai.mit.edu
20 # relocate.exp -- Expect script to test loading symbols from unrelocated
28 set srcfile ${testfile}.c
29 set binfile ${objdir}/${subdir}/${testfile}.o
31 remote_exec build "rm -f ${binfile}"
32 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" object {debug}] != "" } {
33 gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
36 proc get_var_address { var } {
39 send_gdb "print &${var}\n"
43 # $6 = (int (*)()) 0x24 <function_bar>
45 -re "\\\$\[0-9\]+ = \\(.*\\) (0|$hex)( <${var}>)?\[\r\n\]+${gdb_prompt} $"
47 pass "get address of ${var}"
48 if { $expect_out(1,string) == "0" } {
51 return $expect_out(1,string)
55 { fail "get address of ${var} (unknown output)" }
57 { fail "get address of ${var} (timeout)" }
66 gdb_reinitialize_dir $srcdir/$subdir
68 # Load the object file.
69 gdb_test "add-symbol-file ${binfile} 0" \
70 "Reading symbols from .*${testfile}\\.o\\.\\.\\.done\\.(|\r\nUsing host libthread_db library .*libthread_db.so.*\\.)" \
71 "add-symbol-file ${testfile}.o 0" \
72 "add symbol table from file \".*${testfile}\\.o\" at\[ \t\r\n\]+\.text_addr = 0x0\[\r\n\]+\\(y or n\\) " \
75 # Print the addresses of static variables.
76 set static_foo_addr [get_var_address static_foo]
77 set static_bar_addr [get_var_address static_bar]
79 # Make sure they have different addresses.
80 if { "${static_foo_addr}" == "${static_bar_addr}" } {
81 fail "static variables have different addresses"
83 pass "static variables have different addresses"
86 # Print the addresses of global variables.
87 set global_foo_addr [get_var_address global_foo]
88 set global_bar_addr [get_var_address global_bar]
90 # Make sure they have different addresses.
91 if { "${global_foo_addr}" == "${global_bar_addr}" } {
92 fail "global variables have different addresses"
94 pass "global variables have different addresses"
97 # Print the addresses of functions.
98 set function_foo_addr [get_var_address function_foo]
99 set function_bar_addr [get_var_address function_bar]
101 # Make sure they have different addresses.
102 if { "${function_foo_addr}" == "${function_bar_addr}" } {
103 fail "functions have different addresses"
105 pass "functions have different addresses"
108 # Now use a variable as an offset to add-symbol-file, and check that
109 # the functions' addresses change.
113 gdb_reinitialize_dir $srcdir/$subdir
115 gdb_test "set \$offset = 0x10000" ""
117 # Load the object file.
118 gdb_test "add-symbol-file ${binfile} \$offset" \
119 "Reading symbols from .*${testfile}\\.o\\.\\.\\.done\\.(|\r\nUsing host libthread_db library .*libthread_db.so.*\\.)" \
120 "add-symbol-file ${testfile}.o \$offset" \
121 "add symbol table from file \".*${testfile}\\.o\" at\[ \t\r\n\]+\.text_addr = 0x10000\[\r\n\]+\\(y or n\\) " \
124 # Print the addresses of functions.
125 set new_function_foo_addr [get_var_address function_foo]
127 # Make sure they have different addresses.
128 if { "${function_foo_addr}" == "${new_function_foo_addr}" } {
129 fail "function foo has a different address"
131 pass "function foo has a different address"
134 # Now try loading the object as an exec-file; we should be able to print
135 # the values of variables after we do this.
139 gdb_reinitialize_dir $srcdir/$subdir
142 # Check the values of the variables.
143 gdb_test "print static_foo" "\\\$$decimal = 1"
144 gdb_test "print static_bar" "\\\$$decimal = 2"
145 gdb_test "print global_foo" "\\\$$decimal = 3"
146 gdb_test "print global_bar" "\\\$$decimal = 4"