1 # Copyright 2002-2015 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
22 remote_exec build "rm -f ${binfile}"
23 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" object {debug}] != "" } {
28 proc get_var_address { var } {
34 # $6 = (int (*)()) 0x24 <function_bar>
36 gdb_test_multiple "print &${var}" "get address of ${var}" {
37 -re "\\\$\[0-9\]+ = \\(.*\\) (0|$hex)( <${var}>)?\[\r\n\]+${gdb_prompt} $" {
38 pass "get address of ${var}"
39 if { $expect_out(1,string) == "0" } {
42 return $expect_out(1,string)
53 gdb_reinitialize_dir $srcdir/$subdir
55 #Check that invalid options are rejected.
56 foreach x {"-raednow" "readnow" "foo" "-readnow s"} {
57 gdb_test "add-symbol-file ${binfile} 0 $x" \
58 "USAGE: add-symbol-file <filename> <textaddress>.*-readnow.*-s <secname> <addr>.*" \
59 "add-symbol-file: unknown option $x"
62 # Load the object file.
63 gdb_test "add-symbol-file ${binfile} 0" \
64 "Reading symbols from .*${testfile}\\.o\\.\\.\\.done\\.(|\r\nUsing host libthread_db library .*libthread_db.so.*\\.)" \
65 "add-symbol-file ${testfile}.o 0" \
66 "add symbol table from file \".*${testfile}\\.o\" at\[ \t\r\n\]+\.text_addr = 0x0\[\r\n\]+\\(y or n\\) " \
69 # Print the addresses of static variables.
70 set static_foo_addr [get_var_address static_foo]
71 set static_bar_addr [get_var_address static_bar]
73 # Make sure they have different addresses.
74 if { "${static_foo_addr}" == "${static_bar_addr}" } {
75 fail "static variables have different addresses"
77 pass "static variables have different addresses"
80 # Print the addresses of global variables.
81 set global_foo_addr [get_var_address global_foo]
82 set global_bar_addr [get_var_address global_bar]
84 # Make sure they have different addresses.
85 if { "${global_foo_addr}" == "${global_bar_addr}" } {
86 fail "global variables have different addresses"
88 pass "global variables have different addresses"
91 # Print the addresses of functions.
92 set function_foo_addr [get_var_address function_foo]
93 set function_bar_addr [get_var_address function_bar]
95 # Make sure they have different addresses.
96 if { "${function_foo_addr}" == "${function_bar_addr}" } {
97 fail "functions have different addresses"
99 pass "functions have different addresses"
102 # Now use a variable as an offset to add-symbol-file, and check that
103 # the functions' addresses change.
107 gdb_reinitialize_dir $srcdir/$subdir
109 gdb_test_no_output "set \$offset = 0x10000"
111 # Load the object file.
112 gdb_test "add-symbol-file ${binfile} \$offset" \
113 "Reading symbols from .*${testfile}\\.o\\.\\.\\.done\\.(|\r\nUsing host libthread_db library .*libthread_db.so.*\\.)" \
114 "add-symbol-file ${testfile}.o \$offset" \
115 "add symbol table from file \".*${testfile}\\.o\" at\[ \t\r\n\]+\.text_addr = 0x10000\[\r\n\]+\\(y or n\\) " \
118 # Print the addresses of functions.
119 set new_function_foo_addr [get_var_address function_foo]
121 # Make sure they have different addresses.
122 if { "${function_foo_addr}" == "${new_function_foo_addr}" } {
123 fail "function foo has a different address"
125 pass "function foo has a different address"
128 # Now try loading the object as an exec-file; we should be able to print
129 # the values of variables after we do this.
133 gdb_reinitialize_dir $srcdir/$subdir
134 gdb_file_cmd ${binfile}
136 # Check the values of the variables.
137 gdb_test "print static_foo" "\\\$$decimal = 1"
138 gdb_test "print static_bar" "\\\$$decimal = 2"
139 gdb_test "print global_foo" "\\\$$decimal = 3"
140 gdb_test "print global_bar" "\\\$$decimal = 4"