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