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