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