]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/testsuite/gdb.base/relocate.exp
run copyright.sh for 2011.
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.base / relocate.exp
1 # Copyright 2002, 2003, 2005, 2007, 2008, 2009, 2010, 2011
2 # Free Software Foundation, Inc.
3
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 3 of the License, or
7 # (at your option) any later version.
8 #
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with this program. If not, see <http://www.gnu.org/licenses/>. */
16
17 # relocate.exp -- Expect script to test loading symbols from unrelocated
18 # object files.
19
20 if $tracelevel then {
21 strace $tracelevel
22 }
23
24 set testfile relocate
25 set srcfile ${testfile}.c
26 set binfile ${objdir}/${subdir}/${testfile}.o
27
28 remote_exec build "rm -f ${binfile}"
29 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" object {debug}] != "" } {
30 untested relocate.exp
31 return -1
32 }
33
34 proc get_var_address { var } {
35 global gdb_prompt hex
36
37 # Match output like:
38 # $1 = (int *) 0x0
39 # $5 = (int (*)()) 0
40 # $6 = (int (*)()) 0x24 <function_bar>
41
42 gdb_test_multiple "print &${var}" "get address of ${var}" {
43 -re "\\\$\[0-9\]+ = \\(.*\\) (0|$hex)( <${var}>)?\[\r\n\]+${gdb_prompt} $" {
44 pass "get address of ${var}"
45 if { $expect_out(1,string) == "0" } {
46 return "0x0"
47 } else {
48 return $expect_out(1,string)
49 }
50 }
51 }
52 return ""
53 }
54
55
56
57 gdb_exit
58 gdb_start
59 gdb_reinitialize_dir $srcdir/$subdir
60
61 # Load the object file.
62 gdb_test "add-symbol-file ${binfile} 0" \
63 "Reading symbols from .*${testfile}\\.o\\.\\.\\.done\\.(|\r\nUsing host libthread_db library .*libthread_db.so.*\\.)" \
64 "add-symbol-file ${testfile}.o 0" \
65 "add symbol table from file \".*${testfile}\\.o\" at\[ \t\r\n\]+\.text_addr = 0x0\[\r\n\]+\\(y or n\\) " \
66 "y"
67
68 # Print the addresses of static variables.
69 set static_foo_addr [get_var_address static_foo]
70 set static_bar_addr [get_var_address static_bar]
71
72 # Make sure they have different addresses.
73 if { "${static_foo_addr}" == "${static_bar_addr}" } {
74 fail "static variables have different addresses"
75 } else {
76 pass "static variables have different addresses"
77 }
78
79 # Print the addresses of global variables.
80 set global_foo_addr [get_var_address global_foo]
81 set global_bar_addr [get_var_address global_bar]
82
83 # Make sure they have different addresses.
84 if { "${global_foo_addr}" == "${global_bar_addr}" } {
85 fail "global variables have different addresses"
86 } else {
87 pass "global variables have different addresses"
88 }
89
90 # Print the addresses of functions.
91 set function_foo_addr [get_var_address function_foo]
92 set function_bar_addr [get_var_address function_bar]
93
94 # Make sure they have different addresses.
95 if { "${function_foo_addr}" == "${function_bar_addr}" } {
96 fail "functions have different addresses"
97 } else {
98 pass "functions have different addresses"
99 }
100
101 # Now use a variable as an offset to add-symbol-file, and check that
102 # the functions' addresses change.
103
104 gdb_exit
105 gdb_start
106 gdb_reinitialize_dir $srcdir/$subdir
107
108 gdb_test_no_output "set \$offset = 0x10000"
109
110 # Load the object file.
111 gdb_test "add-symbol-file ${binfile} \$offset" \
112 "Reading symbols from .*${testfile}\\.o\\.\\.\\.done\\.(|\r\nUsing host libthread_db library .*libthread_db.so.*\\.)" \
113 "add-symbol-file ${testfile}.o \$offset" \
114 "add symbol table from file \".*${testfile}\\.o\" at\[ \t\r\n\]+\.text_addr = 0x10000\[\r\n\]+\\(y or n\\) " \
115 "y"
116
117 # Print the addresses of functions.
118 set new_function_foo_addr [get_var_address function_foo]
119
120 # Make sure they have different addresses.
121 if { "${function_foo_addr}" == "${new_function_foo_addr}" } {
122 fail "function foo has a different address"
123 } else {
124 pass "function foo has a different address"
125 }
126
127 # Now try loading the object as an exec-file; we should be able to print
128 # the values of variables after we do this.
129
130 gdb_exit
131 gdb_start
132 gdb_reinitialize_dir $srcdir/$subdir
133 gdb_file_cmd ${binfile}
134
135 # Check the values of the variables.
136 gdb_test "print static_foo" "\\\$$decimal = 1"
137 gdb_test "print static_bar" "\\\$$decimal = 2"
138 gdb_test "print global_foo" "\\\$$decimal = 3"
139 gdb_test "print global_bar" "\\\$$decimal = 4"