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}] != "" } {
37 proc get_var_address { var } {
40 send_gdb "print &${var}\n"
44 # $6 = (int (*)()) 0x24 <function_bar>
46 -re "\\\$\[0-9\]+ = \\(.*\\) (0|$hex)( <${var}>)?\[\r\n\]+${gdb_prompt} $"
48 pass "get address of ${var}"
49 if { $expect_out(1,string) == "0" } {
52 return $expect_out(1,string)
56 { fail "get address of ${var} (unknown output)" }
58 { fail "get address of ${var} (timeout)" }
67 gdb_reinitialize_dir $srcdir/$subdir
69 # Load the object file.
70 gdb_test "add-symbol-file ${binfile} 0" \
71 "Reading symbols from .*${testfile}\\.o\\.\\.\\.done\\.(|\r\nUsing host libthread_db library .*libthread_db.so.*\\.)" \
72 "add-symbol-file ${testfile}.o 0" \
73 "add symbol table from file \".*${testfile}\\.o\" at\[ \t\r\n\]+\.text_addr = 0x0\[\r\n\]+\\(y or n\\) " \
76 # Print the addresses of static variables.
77 set static_foo_addr [get_var_address static_foo]
78 set static_bar_addr [get_var_address static_bar]
80 # Make sure they have different addresses.
81 if { "${static_foo_addr}" == "${static_bar_addr}" } {
82 fail "static variables have different addresses"
84 pass "static variables have different addresses"
87 # Print the addresses of global variables.
88 set global_foo_addr [get_var_address global_foo]
89 set global_bar_addr [get_var_address global_bar]
91 # Make sure they have different addresses.
92 if { "${global_foo_addr}" == "${global_bar_addr}" } {
93 fail "global variables have different addresses"
95 pass "global variables have different addresses"
98 # Print the addresses of functions.
99 set function_foo_addr [get_var_address function_foo]
100 set function_bar_addr [get_var_address function_bar]
102 # Make sure they have different addresses.
103 if { "${function_foo_addr}" == "${function_bar_addr}" } {
104 fail "functions have different addresses"
106 pass "functions have different addresses"
109 # Now use a variable as an offset to add-symbol-file, and check that
110 # the functions' addresses change.
114 gdb_reinitialize_dir $srcdir/$subdir
116 gdb_test "set \$offset = 0x10000" ""
118 # Load the object file.
119 gdb_test "add-symbol-file ${binfile} \$offset" \
120 "Reading symbols from .*${testfile}\\.o\\.\\.\\.done\\.(|\r\nUsing host libthread_db library .*libthread_db.so.*\\.)" \
121 "add-symbol-file ${testfile}.o \$offset" \
122 "add symbol table from file \".*${testfile}\\.o\" at\[ \t\r\n\]+\.text_addr = 0x10000\[\r\n\]+\\(y or n\\) " \
125 # Print the addresses of functions.
126 set new_function_foo_addr [get_var_address function_foo]
128 # Make sure they have different addresses.
129 if { "${function_foo_addr}" == "${new_function_foo_addr}" } {
130 fail "function foo has a different address"
132 pass "function foo has a different address"
135 # Now try loading the object as an exec-file; we should be able to print
136 # the values of variables after we do this.
140 gdb_reinitialize_dir $srcdir/$subdir
141 gdb_file_cmd ${binfile}
143 # Check the values of the variables.
144 gdb_test "print static_foo" "\\\$$decimal = 1"
145 gdb_test "print static_bar" "\\\$$decimal = 2"
146 gdb_test "print global_foo" "\\\$$decimal = 3"
147 gdb_test "print global_bar" "\\\$$decimal = 4"