* gdb.arch/altivec-abi.exp: Replace gdb_suppress_entire_file with
[external/binutils.git] / gdb / testsuite / gdb.base / relocate.exp
1 # Copyright 2002, 2003, 2005 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 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
23 if $tracelevel then {
24     strace $tracelevel
25 }
26
27 set testfile relocate
28 set srcfile ${testfile}.c
29 set binfile ${objdir}/${subdir}/${testfile}.o
30
31 remote_exec build "rm -f ${binfile}"
32 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" object {debug}] != "" } {
33      untested relocate.exp
34      return -1
35 }
36
37 proc 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
65 gdb_exit
66 gdb_start
67 gdb_reinitialize_dir $srcdir/$subdir
68
69 # Load the object file.
70 gdb_test "add-symbol-file ${binfile} 0" \
71         "Reading symbols from .*${testfile}\\.o\\.\\.\\.done\\.(|\r\nUsing host libthread_db library .*libthread_db.so.*\\.)" \
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.
77 set static_foo_addr [get_var_address static_foo]
78 set static_bar_addr [get_var_address static_bar]
79
80 # Make sure they have different addresses.
81 if { "${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.
88 set global_foo_addr [get_var_address global_foo]
89 set global_bar_addr [get_var_address global_bar]
90
91 # Make sure they have different addresses.
92 if { "${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.
99 set function_foo_addr [get_var_address function_foo]
100 set function_bar_addr [get_var_address function_bar]
101
102 # Make sure they have different addresses.
103 if { "${function_foo_addr}" == "${function_bar_addr}" } {
104   fail "functions have different addresses"
105 } else {
106   pass "functions have different addresses"
107 }
108
109 # Now use a variable as an offset to add-symbol-file, and check that
110 # the functions' addresses change.
111
112 gdb_exit
113 gdb_start
114 gdb_reinitialize_dir $srcdir/$subdir
115
116 gdb_test "set \$offset = 0x10000" ""
117
118 # Load the object file.
119 gdb_test "add-symbol-file ${binfile} \$offset" \
120         "Reading symbols from .*${testfile}\\.o\\.\\.\\.done\\.(|\r\nUsing host libthread_db library .*libthread_db.so.*\\.)" \
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.
126 set new_function_foo_addr [get_var_address function_foo]
127
128 # Make sure they have different addresses.
129 if { "${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
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
138 gdb_exit
139 gdb_start
140 gdb_reinitialize_dir $srcdir/$subdir
141 gdb_file_cmd ${binfile}
142
143 # Check the values of the variables.
144 gdb_test "print static_foo" "\\\$$decimal = 1"
145 gdb_test "print static_bar" "\\\$$decimal = 2"
146 gdb_test "print global_foo" "\\\$$decimal = 3"
147 gdb_test "print global_bar" "\\\$$decimal = 4"