1 # Copyright 2002-2017 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}] != "" } {
24 untested "failed to compile"
30 gdb_reinitialize_dir $srcdir/$subdir
32 #Check that invalid options are rejected.
33 foreach x {"-raednow" "readnow" "foo" "-readnow s"} {
34 set word [lindex $x [expr [llength $x]-1]]
35 gdb_test "add-symbol-file ${binfile} 0 $x" \
36 "Unrecognized argument \"$word\"" \
37 "add-symbol-file: unknown option $word"
40 gdb_test "add-symbol-file ${binfile} 0 -s" \
41 "Missing section name after .-s." \
42 "add-symbol-file bare -s"
43 gdb_test "add-symbol-file ${binfile} 0 -s .whatever" \
44 "Missing section address after .-s." \
45 "add-symbol-file missing address"
47 # Load the object file.
48 gdb_test "add-symbol-file ${binfile} 0" \
49 "Reading symbols from .*${testfile}\\.o\\.\\.\\.done\\.(|\r\nUsing host libthread_db library .*libthread_db.so.*\\.)" \
50 "add-symbol-file ${testfile}.o 0" \
51 "add symbol table from file \".*${testfile}\\.o\" at\[ \t\r\n\]+\.text_addr = 0x0\[\r\n\]+\\(y or n\\) " \
54 # Print the addresses of static variables.
55 set static_foo_addr [get_var_address static_foo]
56 set static_bar_addr [get_var_address static_bar]
58 # Make sure they have different addresses.
59 if { "${static_foo_addr}" == "${static_bar_addr}" } {
60 fail "static variables have different addresses"
62 pass "static variables have different addresses"
65 # Print the addresses of global variables.
66 set global_foo_addr [get_var_address global_foo]
67 set global_bar_addr [get_var_address global_bar]
69 # Make sure they have different addresses.
70 if { "${global_foo_addr}" == "${global_bar_addr}" } {
71 fail "global variables have different addresses"
73 pass "global variables have different addresses"
76 # Print the addresses of functions.
77 set function_foo_addr [get_var_address function_foo]
78 set function_bar_addr [get_var_address function_bar]
80 # Make sure they have different addresses.
81 if { "${function_foo_addr}" == "${function_bar_addr}" } {
82 fail "functions have different addresses"
84 pass "functions have different addresses"
87 # Now use a variable as an offset to add-symbol-file, and check that
88 # the functions' addresses change.
92 gdb_reinitialize_dir $srcdir/$subdir
94 gdb_test_no_output "set \$offset = 0x10000"
96 # Load the object file.
97 gdb_test "add-symbol-file ${binfile} \$offset" \
98 "Reading symbols from .*${testfile}\\.o\\.\\.\\.done\\.(|\r\nUsing host libthread_db library .*libthread_db.so.*\\.)" \
99 "add-symbol-file ${testfile}.o \$offset" \
100 "add symbol table from file \".*${testfile}\\.o\" at\[ \t\r\n\]+\.text_addr = 0x10000\[\r\n\]+\\(y or n\\) " \
103 # Print the addresses of functions.
104 set new_function_foo_addr [get_var_address function_foo]
106 # Make sure they have different addresses.
107 if { "${function_foo_addr}" == "${new_function_foo_addr}" } {
108 fail "function foo has a different address"
110 pass "function foo has a different address"
113 # Now try loading the object as an exec-file; we should be able to print
114 # the values of variables after we do this.
118 gdb_reinitialize_dir $srcdir/$subdir
119 gdb_file_cmd ${binfile}
121 # Check the values of the variables.
122 gdb_test "print static_foo" "\\\$$decimal = 1"
123 gdb_test "print static_bar" "\\\$$decimal = 2"
124 gdb_test "print global_foo" "\\\$$decimal = 3"
125 gdb_test "print global_bar" "\\\$$decimal = 4"