]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/testsuite/gdb.base/relocate.exp
update copyright year range in GDB files
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.base / relocate.exp
1 # Copyright 2002-2017 Free Software Foundation, Inc.
2
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.
7 #
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.
12 #
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/>. */
15
16 # relocate.exp -- Expect script to test loading symbols from unrelocated
17 # object files.
18
19 standard_testfile .c
20 append binfile .o
21
22 remote_exec build "rm -f ${binfile}"
23 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" object {debug}] != "" } {
24 untested "failed to compile"
25 return -1
26 }
27
28 gdb_exit
29 gdb_start
30 gdb_reinitialize_dir $srcdir/$subdir
31
32 #Check that invalid options are rejected.
33 foreach x {"-raednow" "readnow" "foo" "-readnow s"} {
34 gdb_test "add-symbol-file ${binfile} 0 $x" \
35 "USAGE: add-symbol-file <filename> <textaddress>.*-readnow.*-s <secname> <addr>.*" \
36 "add-symbol-file: unknown option $x"
37 }
38
39 # Load the object file.
40 gdb_test "add-symbol-file ${binfile} 0" \
41 "Reading symbols from .*${testfile}\\.o\\.\\.\\.done\\.(|\r\nUsing host libthread_db library .*libthread_db.so.*\\.)" \
42 "add-symbol-file ${testfile}.o 0" \
43 "add symbol table from file \".*${testfile}\\.o\" at\[ \t\r\n\]+\.text_addr = 0x0\[\r\n\]+\\(y or n\\) " \
44 "y"
45
46 # Print the addresses of static variables.
47 set static_foo_addr [get_var_address static_foo]
48 set static_bar_addr [get_var_address static_bar]
49
50 # Make sure they have different addresses.
51 if { "${static_foo_addr}" == "${static_bar_addr}" } {
52 fail "static variables have different addresses"
53 } else {
54 pass "static variables have different addresses"
55 }
56
57 # Print the addresses of global variables.
58 set global_foo_addr [get_var_address global_foo]
59 set global_bar_addr [get_var_address global_bar]
60
61 # Make sure they have different addresses.
62 if { "${global_foo_addr}" == "${global_bar_addr}" } {
63 fail "global variables have different addresses"
64 } else {
65 pass "global variables have different addresses"
66 }
67
68 # Print the addresses of functions.
69 set function_foo_addr [get_var_address function_foo]
70 set function_bar_addr [get_var_address function_bar]
71
72 # Make sure they have different addresses.
73 if { "${function_foo_addr}" == "${function_bar_addr}" } {
74 fail "functions have different addresses"
75 } else {
76 pass "functions have different addresses"
77 }
78
79 # Now use a variable as an offset to add-symbol-file, and check that
80 # the functions' addresses change.
81
82 gdb_exit
83 gdb_start
84 gdb_reinitialize_dir $srcdir/$subdir
85
86 gdb_test_no_output "set \$offset = 0x10000"
87
88 # Load the object file.
89 gdb_test "add-symbol-file ${binfile} \$offset" \
90 "Reading symbols from .*${testfile}\\.o\\.\\.\\.done\\.(|\r\nUsing host libthread_db library .*libthread_db.so.*\\.)" \
91 "add-symbol-file ${testfile}.o \$offset" \
92 "add symbol table from file \".*${testfile}\\.o\" at\[ \t\r\n\]+\.text_addr = 0x10000\[\r\n\]+\\(y or n\\) " \
93 "y"
94
95 # Print the addresses of functions.
96 set new_function_foo_addr [get_var_address function_foo]
97
98 # Make sure they have different addresses.
99 if { "${function_foo_addr}" == "${new_function_foo_addr}" } {
100 fail "function foo has a different address"
101 } else {
102 pass "function foo has a different address"
103 }
104
105 # Now try loading the object as an exec-file; we should be able to print
106 # the values of variables after we do this.
107
108 gdb_exit
109 gdb_start
110 gdb_reinitialize_dir $srcdir/$subdir
111 gdb_file_cmd ${binfile}
112
113 # Check the values of the variables.
114 gdb_test "print static_foo" "\\\$$decimal = 1"
115 gdb_test "print static_bar" "\\\$$decimal = 2"
116 gdb_test "print global_foo" "\\\$$decimal = 3"
117 gdb_test "print global_bar" "\\\$$decimal = 4"