]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/testsuite/gdb.base/relocate.exp
GDB copyright headers update after running GDB's copyright.py script.
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.base / relocate.exp
1 # Copyright 2002-2016 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 relocate.exp
25 return -1
26 }
27
28 proc get_var_address { var } {
29 global gdb_prompt hex
30
31 # Match output like:
32 # $1 = (int *) 0x0
33 # $5 = (int (*)()) 0
34 # $6 = (int (*)()) 0x24 <function_bar>
35
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" } {
40 return "0x0"
41 } else {
42 return $expect_out(1,string)
43 }
44 }
45 }
46 return ""
47 }
48
49
50
51 gdb_exit
52 gdb_start
53 gdb_reinitialize_dir $srcdir/$subdir
54
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"
60 }
61
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\\) " \
67 "y"
68
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]
72
73 # Make sure they have different addresses.
74 if { "${static_foo_addr}" == "${static_bar_addr}" } {
75 fail "static variables have different addresses"
76 } else {
77 pass "static variables have different addresses"
78 }
79
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]
83
84 # Make sure they have different addresses.
85 if { "${global_foo_addr}" == "${global_bar_addr}" } {
86 fail "global variables have different addresses"
87 } else {
88 pass "global variables have different addresses"
89 }
90
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]
94
95 # Make sure they have different addresses.
96 if { "${function_foo_addr}" == "${function_bar_addr}" } {
97 fail "functions have different addresses"
98 } else {
99 pass "functions have different addresses"
100 }
101
102 # Now use a variable as an offset to add-symbol-file, and check that
103 # the functions' addresses change.
104
105 gdb_exit
106 gdb_start
107 gdb_reinitialize_dir $srcdir/$subdir
108
109 gdb_test_no_output "set \$offset = 0x10000"
110
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\\) " \
116 "y"
117
118 # Print the addresses of functions.
119 set new_function_foo_addr [get_var_address function_foo]
120
121 # Make sure they have different addresses.
122 if { "${function_foo_addr}" == "${new_function_foo_addr}" } {
123 fail "function foo has a different address"
124 } else {
125 pass "function foo has a different address"
126 }
127
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.
130
131 gdb_exit
132 gdb_start
133 gdb_reinitialize_dir $srcdir/$subdir
134 gdb_file_cmd ${binfile}
135
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"