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