]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/testsuite/gdb.base/relocate.exp
This commit was manufactured by cvs2svn to create branch
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.base / relocate.exp
CommitLineData
9b254dd1 1# Copyright 2002, 2003, 2005, 2007, 2008 Free Software Foundation, Inc.
a7d17088
DJ
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
e22f8b7c 5# the Free Software Foundation; either version 3 of the License, or
a7d17088 6# (at your option) any later version.
e22f8b7c 7#
a7d17088
DJ
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.
e22f8b7c 12#
a7d17088 13# You should have received a copy of the GNU General Public License
e22f8b7c 14# along with this program. If not, see <http://www.gnu.org/licenses/>. */
a7d17088 15
a7d17088
DJ
16# relocate.exp -- Expect script to test loading symbols from unrelocated
17# object files.
18
19if $tracelevel then {
20 strace $tracelevel
21}
22
23set testfile relocate
f2dd3617 24set srcfile ${testfile}.c
a7d17088
DJ
25set binfile ${objdir}/${subdir}/${testfile}.o
26
27remote_exec build "rm -f ${binfile}"
f2dd3617 28if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" object {debug}] != "" } {
b60f0898
JB
29 untested relocate.exp
30 return -1
a7d17088
DJ
31}
32
33proc get_var_address { var } {
34 global gdb_prompt hex
35
36 send_gdb "print &${var}\n"
37 # Match output like:
38 # $1 = (int *) 0x0
39 # $5 = (int (*)()) 0
40 # $6 = (int (*)()) 0x24 <function_bar>
41 gdb_expect {
42 -re "\\\$\[0-9\]+ = \\(.*\\) (0|$hex)( <${var}>)?\[\r\n\]+${gdb_prompt} $"
43 {
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 -re "${gdb_prompt} $"
52 { fail "get address of ${var} (unknown output)" }
53 timeout
54 { fail "get address of ${var} (timeout)" }
55 }
56 return ""
57}
58
59
60
61gdb_exit
62gdb_start
63gdb_reinitialize_dir $srcdir/$subdir
64
65# Load the object file.
66gdb_test "add-symbol-file ${binfile} 0" \
1c199746 67 "Reading symbols from .*${testfile}\\.o\\.\\.\\.done\\.(|\r\nUsing host libthread_db library .*libthread_db.so.*\\.)" \
a7d17088
DJ
68 "add-symbol-file ${testfile}.o 0" \
69 "add symbol table from file \".*${testfile}\\.o\" at\[ \t\r\n\]+\.text_addr = 0x0\[\r\n\]+\\(y or n\\) " \
70 "y"
71
72# Print the addresses of static variables.
73set static_foo_addr [get_var_address static_foo]
74set static_bar_addr [get_var_address static_bar]
75
76# Make sure they have different addresses.
77if { "${static_foo_addr}" == "${static_bar_addr}" } {
78 fail "static variables have different addresses"
79} else {
80 pass "static variables have different addresses"
81}
82
83# Print the addresses of global variables.
84set global_foo_addr [get_var_address global_foo]
85set global_bar_addr [get_var_address global_bar]
86
87# Make sure they have different addresses.
88if { "${global_foo_addr}" == "${global_bar_addr}" } {
89 fail "global variables have different addresses"
90} else {
91 pass "global variables have different addresses"
92}
93
94# Print the addresses of functions.
95set function_foo_addr [get_var_address function_foo]
96set function_bar_addr [get_var_address function_bar]
97
98# Make sure they have different addresses.
99if { "${function_foo_addr}" == "${function_bar_addr}" } {
100 fail "functions have different addresses"
101} else {
102 pass "functions have different addresses"
103}
104
2f816dda
DJ
105# Now use a variable as an offset to add-symbol-file, and check that
106# the functions' addresses change.
107
108gdb_exit
109gdb_start
110gdb_reinitialize_dir $srcdir/$subdir
111
112gdb_test "set \$offset = 0x10000" ""
113
114# Load the object file.
115gdb_test "add-symbol-file ${binfile} \$offset" \
1c199746 116 "Reading symbols from .*${testfile}\\.o\\.\\.\\.done\\.(|\r\nUsing host libthread_db library .*libthread_db.so.*\\.)" \
2f816dda
DJ
117 "add-symbol-file ${testfile}.o \$offset" \
118 "add symbol table from file \".*${testfile}\\.o\" at\[ \t\r\n\]+\.text_addr = 0x10000\[\r\n\]+\\(y or n\\) " \
119 "y"
120
121# Print the addresses of functions.
122set new_function_foo_addr [get_var_address function_foo]
123
124# Make sure they have different addresses.
125if { "${function_foo_addr}" == "${new_function_foo_addr}" } {
126 fail "function foo has a different address"
127} else {
128 pass "function foo has a different address"
129}
130
c1bd25fd
DJ
131# Now try loading the object as an exec-file; we should be able to print
132# the values of variables after we do this.
133
134gdb_exit
135gdb_start
136gdb_reinitialize_dir $srcdir/$subdir
582e64c2 137gdb_file_cmd ${binfile}
c1bd25fd
DJ
138
139# Check the values of the variables.
140gdb_test "print static_foo" "\\\$$decimal = 1"
141gdb_test "print static_bar" "\\\$$decimal = 2"
142gdb_test "print global_foo" "\\\$$decimal = 3"
143gdb_test "print global_bar" "\\\$$decimal = 4"