1 # Copyright 2002-2003, 2005, 2007-2012 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
20 set srcfile ${testfile}.c
21 set binfile ${objdir}/${subdir}/${testfile}.o
23 remote_exec build "rm -f ${binfile}"
24 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" object {debug}] != "" } {
29 proc get_var_address { var } {
35 # $6 = (int (*)()) 0x24 <function_bar>
37 gdb_test_multiple "print &${var}" "get address of ${var}" {
38 -re "\\\$\[0-9\]+ = \\(.*\\) (0|$hex)( <${var}>)?\[\r\n\]+${gdb_prompt} $" {
39 pass "get address of ${var}"
40 if { $expect_out(1,string) == "0" } {
43 return $expect_out(1,string)
54 gdb_reinitialize_dir $srcdir/$subdir
56 # Load the object file.
57 gdb_test "add-symbol-file ${binfile} 0" \
58 "Reading symbols from .*${testfile}\\.o\\.\\.\\.done\\.(|\r\nUsing host libthread_db library .*libthread_db.so.*\\.)" \
59 "add-symbol-file ${testfile}.o 0" \
60 "add symbol table from file \".*${testfile}\\.o\" at\[ \t\r\n\]+\.text_addr = 0x0\[\r\n\]+\\(y or n\\) " \
63 # Print the addresses of static variables.
64 set static_foo_addr [get_var_address static_foo]
65 set static_bar_addr [get_var_address static_bar]
67 # Make sure they have different addresses.
68 if { "${static_foo_addr}" == "${static_bar_addr}" } {
69 fail "static variables have different addresses"
71 pass "static variables have different addresses"
74 # Print the addresses of global variables.
75 set global_foo_addr [get_var_address global_foo]
76 set global_bar_addr [get_var_address global_bar]
78 # Make sure they have different addresses.
79 if { "${global_foo_addr}" == "${global_bar_addr}" } {
80 fail "global variables have different addresses"
82 pass "global variables have different addresses"
85 # Print the addresses of functions.
86 set function_foo_addr [get_var_address function_foo]
87 set function_bar_addr [get_var_address function_bar]
89 # Make sure they have different addresses.
90 if { "${function_foo_addr}" == "${function_bar_addr}" } {
91 fail "functions have different addresses"
93 pass "functions have different addresses"
96 # Now use a variable as an offset to add-symbol-file, and check that
97 # the functions' addresses change.
101 gdb_reinitialize_dir $srcdir/$subdir
103 gdb_test_no_output "set \$offset = 0x10000"
105 # Load the object file.
106 gdb_test "add-symbol-file ${binfile} \$offset" \
107 "Reading symbols from .*${testfile}\\.o\\.\\.\\.done\\.(|\r\nUsing host libthread_db library .*libthread_db.so.*\\.)" \
108 "add-symbol-file ${testfile}.o \$offset" \
109 "add symbol table from file \".*${testfile}\\.o\" at\[ \t\r\n\]+\.text_addr = 0x10000\[\r\n\]+\\(y or n\\) " \
112 # Print the addresses of functions.
113 set new_function_foo_addr [get_var_address function_foo]
115 # Make sure they have different addresses.
116 if { "${function_foo_addr}" == "${new_function_foo_addr}" } {
117 fail "function foo has a different address"
119 pass "function foo has a different address"
122 # Now try loading the object as an exec-file; we should be able to print
123 # the values of variables after we do this.
127 gdb_reinitialize_dir $srcdir/$subdir
128 gdb_file_cmd ${binfile}
130 # Check the values of the variables.
131 gdb_test "print static_foo" "\\\$$decimal = 1"
132 gdb_test "print static_bar" "\\\$$decimal = 2"
133 gdb_test "print global_foo" "\\\$$decimal = 3"
134 gdb_test "print global_bar" "\\\$$decimal = 4"