]> Git Repo - binutils.git/blame - gdb/testsuite/gdb.base/relocate.exp
* infrun.c (handle_inferior_event)
[binutils.git] / gdb / testsuite / gdb.base / relocate.exp
CommitLineData
0b302171 1# Copyright 2002-2003, 2005, 2007-2012 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
a7d17088 19set testfile relocate
f2dd3617 20set srcfile ${testfile}.c
a7d17088
DJ
21set binfile ${objdir}/${subdir}/${testfile}.o
22
23remote_exec build "rm -f ${binfile}"
f2dd3617 24if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" object {debug}] != "" } {
b60f0898
JB
25 untested relocate.exp
26 return -1
a7d17088
DJ
27}
28
29proc get_var_address { var } {
02746bbc 30 global gdb_prompt hex
a7d17088 31
02746bbc
MS
32 # Match output like:
33 # $1 = (int *) 0x0
34 # $5 = (int (*)()) 0
35 # $6 = (int (*)()) 0x24 <function_bar>
36
37 gdb_test_multiple "print &${var}" "get address of ${var}" {
38 -re "\\\$\[0-9\]+ = \\(.*\\) (0|$hex)( <${var}>)?\[\r\n\]+${gdb_prompt} $" {
39 pass "get address of ${var}"
40 if { $expect_out(1,string) == "0" } {
41 return "0x0"
42 } else {
43 return $expect_out(1,string)
44 }
a7d17088 45 }
02746bbc
MS
46 }
47 return ""
a7d17088
DJ
48}
49
50
51
52gdb_exit
53gdb_start
54gdb_reinitialize_dir $srcdir/$subdir
55
56# Load the object file.
57gdb_test "add-symbol-file ${binfile} 0" \
1c199746 58 "Reading symbols from .*${testfile}\\.o\\.\\.\\.done\\.(|\r\nUsing host libthread_db library .*libthread_db.so.*\\.)" \
a7d17088
DJ
59 "add-symbol-file ${testfile}.o 0" \
60 "add symbol table from file \".*${testfile}\\.o\" at\[ \t\r\n\]+\.text_addr = 0x0\[\r\n\]+\\(y or n\\) " \
61 "y"
62
63# Print the addresses of static variables.
64set static_foo_addr [get_var_address static_foo]
65set static_bar_addr [get_var_address static_bar]
66
67# Make sure they have different addresses.
68if { "${static_foo_addr}" == "${static_bar_addr}" } {
69 fail "static variables have different addresses"
70} else {
71 pass "static variables have different addresses"
72}
73
74# Print the addresses of global variables.
75set global_foo_addr [get_var_address global_foo]
76set global_bar_addr [get_var_address global_bar]
77
78# Make sure they have different addresses.
79if { "${global_foo_addr}" == "${global_bar_addr}" } {
80 fail "global variables have different addresses"
81} else {
82 pass "global variables have different addresses"
83}
84
85# Print the addresses of functions.
86set function_foo_addr [get_var_address function_foo]
87set function_bar_addr [get_var_address function_bar]
88
89# Make sure they have different addresses.
90if { "${function_foo_addr}" == "${function_bar_addr}" } {
91 fail "functions have different addresses"
92} else {
93 pass "functions have different addresses"
94}
95
2f816dda
DJ
96# Now use a variable as an offset to add-symbol-file, and check that
97# the functions' addresses change.
98
99gdb_exit
100gdb_start
101gdb_reinitialize_dir $srcdir/$subdir
102
27d3a1a2 103gdb_test_no_output "set \$offset = 0x10000"
2f816dda
DJ
104
105# Load the object file.
106gdb_test "add-symbol-file ${binfile} \$offset" \
1c199746 107 "Reading symbols from .*${testfile}\\.o\\.\\.\\.done\\.(|\r\nUsing host libthread_db library .*libthread_db.so.*\\.)" \
2f816dda
DJ
108 "add-symbol-file ${testfile}.o \$offset" \
109 "add symbol table from file \".*${testfile}\\.o\" at\[ \t\r\n\]+\.text_addr = 0x10000\[\r\n\]+\\(y or n\\) " \
110 "y"
111
112# Print the addresses of functions.
113set new_function_foo_addr [get_var_address function_foo]
114
115# Make sure they have different addresses.
116if { "${function_foo_addr}" == "${new_function_foo_addr}" } {
117 fail "function foo has a different address"
118} else {
119 pass "function foo has a different address"
120}
121
c1bd25fd
DJ
122# Now try loading the object as an exec-file; we should be able to print
123# the values of variables after we do this.
124
125gdb_exit
126gdb_start
127gdb_reinitialize_dir $srcdir/$subdir
582e64c2 128gdb_file_cmd ${binfile}
c1bd25fd
DJ
129
130# Check the values of the variables.
131gdb_test "print static_foo" "\\\$$decimal = 1"
132gdb_test "print static_bar" "\\\$$decimal = 2"
133gdb_test "print global_foo" "\\\$$decimal = 3"
134gdb_test "print global_bar" "\\\$$decimal = 4"
This page took 2.410562 seconds and 4 git commands to generate.