This commit was generated by cvs2svn to track changes on a CVS vendor
[external/binutils.git] / gdb / testsuite / gdb.base / relocate.exp
1 # Copyright 2002 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 ${srcdir}/${subdir}/${testfile}.c
29 set binfile ${objdir}/${subdir}/${testfile}.o
30
31 remote_exec build "rm -f ${binfile}"
32 if { [gdb_compile "${srcfile}" "${binfile}" object {debug}] != "" } {
33      gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
34 }
35
36 proc get_var_address { var } {
37   global gdb_prompt hex
38
39   send_gdb "print &${var}\n"
40   # Match output like:
41   # $1 = (int *) 0x0
42   # $5 = (int (*)()) 0
43   # $6 = (int (*)()) 0x24 <function_bar>
44   gdb_expect {
45     -re "\\\$\[0-9\]+ = \\(.*\\) (0|$hex)( <${var}>)?\[\r\n\]+${gdb_prompt} $"
46         {
47           pass "get address of ${var}"
48           if { $expect_out(1,string) == "0" } {
49             return "0x0"
50           } else {
51             return $expect_out(1,string)
52           }
53         }
54     -re "${gdb_prompt} $"
55         { fail "get address of ${var} (unknown output)" }
56     timeout
57         { fail "get address of ${var} (timeout)" }
58   }
59   return ""
60 }
61
62
63
64 gdb_exit
65 gdb_start
66 gdb_reinitialize_dir $srcdir/$subdir
67
68 # Load the object file.
69 gdb_test "add-symbol-file ${binfile} 0" \
70         "Reading symbols from .*${testfile}\\.o\\.\\.\\.done\\." \
71         "add-symbol-file ${testfile}.o 0" \
72         "add symbol table from file \".*${testfile}\\.o\" at\[ \t\r\n\]+\.text_addr = 0x0\[\r\n\]+\\(y or n\\) " \
73         "y"
74
75 # Print the addresses of static variables.
76 set static_foo_addr [get_var_address static_foo]
77 set static_bar_addr [get_var_address static_bar]
78
79 # Make sure they have different addresses.
80 if { "${static_foo_addr}" == "${static_bar_addr}" } {
81   fail "static variables have different addresses"
82 } else {
83   pass "static variables have different addresses"
84 }
85
86 # Print the addresses of global variables.
87 set global_foo_addr [get_var_address global_foo]
88 set global_bar_addr [get_var_address global_bar]
89
90 # Make sure they have different addresses.
91 if { "${global_foo_addr}" == "${global_bar_addr}" } {
92   fail "global variables have different addresses"
93 } else {
94   pass "global variables have different addresses"
95 }
96
97 # Print the addresses of functions.
98 set function_foo_addr [get_var_address function_foo]
99 set function_bar_addr [get_var_address function_bar]
100
101 # Make sure they have different addresses.
102 if { "${function_foo_addr}" == "${function_bar_addr}" } {
103   fail "functions have different addresses"
104 } else {
105   pass "functions have different addresses"
106 }
107
108 return 0