]>
Commit | Line | Data |
---|---|---|
4c38e0a4 JB |
1 | # Copyright 2002, 2003, 2005, 2007, 2008, 2009, 2010 |
2 | # Free Software Foundation, Inc. | |
a7d17088 DJ |
3 | |
4 | # This program is free software; you can redistribute it and/or modify | |
5 | # it under the terms of the GNU General Public License as published by | |
e22f8b7c | 6 | # the Free Software Foundation; either version 3 of the License, or |
a7d17088 | 7 | # (at your option) any later version. |
e22f8b7c | 8 | # |
a7d17088 DJ |
9 | # This program is distributed in the hope that it will be useful, |
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | # GNU General Public License for more details. | |
e22f8b7c | 13 | # |
a7d17088 | 14 | # You should have received a copy of the GNU General Public License |
e22f8b7c | 15 | # along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
a7d17088 | 16 | |
a7d17088 DJ |
17 | # relocate.exp -- Expect script to test loading symbols from unrelocated |
18 | # object files. | |
19 | ||
20 | if $tracelevel then { | |
21 | strace $tracelevel | |
22 | } | |
23 | ||
24 | set testfile relocate | |
f2dd3617 | 25 | set srcfile ${testfile}.c |
a7d17088 DJ |
26 | set binfile ${objdir}/${subdir}/${testfile}.o |
27 | ||
28 | remote_exec build "rm -f ${binfile}" | |
f2dd3617 | 29 | if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" object {debug}] != "" } { |
b60f0898 JB |
30 | untested relocate.exp |
31 | return -1 | |
a7d17088 DJ |
32 | } |
33 | ||
34 | proc get_var_address { var } { | |
35 | global gdb_prompt hex | |
36 | ||
37 | send_gdb "print &${var}\n" | |
38 | # Match output like: | |
39 | # $1 = (int *) 0x0 | |
40 | # $5 = (int (*)()) 0 | |
41 | # $6 = (int (*)()) 0x24 <function_bar> | |
42 | gdb_expect { | |
43 | -re "\\\$\[0-9\]+ = \\(.*\\) (0|$hex)( <${var}>)?\[\r\n\]+${gdb_prompt} $" | |
44 | { | |
45 | pass "get address of ${var}" | |
46 | if { $expect_out(1,string) == "0" } { | |
47 | return "0x0" | |
48 | } else { | |
49 | return $expect_out(1,string) | |
50 | } | |
51 | } | |
52 | -re "${gdb_prompt} $" | |
53 | { fail "get address of ${var} (unknown output)" } | |
54 | timeout | |
55 | { fail "get address of ${var} (timeout)" } | |
56 | } | |
57 | return "" | |
58 | } | |
59 | ||
60 | ||
61 | ||
62 | gdb_exit | |
63 | gdb_start | |
64 | gdb_reinitialize_dir $srcdir/$subdir | |
65 | ||
66 | # Load the object file. | |
67 | gdb_test "add-symbol-file ${binfile} 0" \ | |
1c199746 | 68 | "Reading symbols from .*${testfile}\\.o\\.\\.\\.done\\.(|\r\nUsing host libthread_db library .*libthread_db.so.*\\.)" \ |
a7d17088 DJ |
69 | "add-symbol-file ${testfile}.o 0" \ |
70 | "add symbol table from file \".*${testfile}\\.o\" at\[ \t\r\n\]+\.text_addr = 0x0\[\r\n\]+\\(y or n\\) " \ | |
71 | "y" | |
72 | ||
73 | # Print the addresses of static variables. | |
74 | set static_foo_addr [get_var_address static_foo] | |
75 | set static_bar_addr [get_var_address static_bar] | |
76 | ||
77 | # Make sure they have different addresses. | |
78 | if { "${static_foo_addr}" == "${static_bar_addr}" } { | |
79 | fail "static variables have different addresses" | |
80 | } else { | |
81 | pass "static variables have different addresses" | |
82 | } | |
83 | ||
84 | # Print the addresses of global variables. | |
85 | set global_foo_addr [get_var_address global_foo] | |
86 | set global_bar_addr [get_var_address global_bar] | |
87 | ||
88 | # Make sure they have different addresses. | |
89 | if { "${global_foo_addr}" == "${global_bar_addr}" } { | |
90 | fail "global variables have different addresses" | |
91 | } else { | |
92 | pass "global variables have different addresses" | |
93 | } | |
94 | ||
95 | # Print the addresses of functions. | |
96 | set function_foo_addr [get_var_address function_foo] | |
97 | set function_bar_addr [get_var_address function_bar] | |
98 | ||
99 | # Make sure they have different addresses. | |
100 | if { "${function_foo_addr}" == "${function_bar_addr}" } { | |
101 | fail "functions have different addresses" | |
102 | } else { | |
103 | pass "functions have different addresses" | |
104 | } | |
105 | ||
2f816dda DJ |
106 | # Now use a variable as an offset to add-symbol-file, and check that |
107 | # the functions' addresses change. | |
108 | ||
109 | gdb_exit | |
110 | gdb_start | |
111 | gdb_reinitialize_dir $srcdir/$subdir | |
112 | ||
113 | gdb_test "set \$offset = 0x10000" "" | |
114 | ||
115 | # Load the object file. | |
116 | gdb_test "add-symbol-file ${binfile} \$offset" \ | |
1c199746 | 117 | "Reading symbols from .*${testfile}\\.o\\.\\.\\.done\\.(|\r\nUsing host libthread_db library .*libthread_db.so.*\\.)" \ |
2f816dda DJ |
118 | "add-symbol-file ${testfile}.o \$offset" \ |
119 | "add symbol table from file \".*${testfile}\\.o\" at\[ \t\r\n\]+\.text_addr = 0x10000\[\r\n\]+\\(y or n\\) " \ | |
120 | "y" | |
121 | ||
122 | # Print the addresses of functions. | |
123 | set new_function_foo_addr [get_var_address function_foo] | |
124 | ||
125 | # Make sure they have different addresses. | |
126 | if { "${function_foo_addr}" == "${new_function_foo_addr}" } { | |
127 | fail "function foo has a different address" | |
128 | } else { | |
129 | pass "function foo has a different address" | |
130 | } | |
131 | ||
c1bd25fd DJ |
132 | # Now try loading the object as an exec-file; we should be able to print |
133 | # the values of variables after we do this. | |
134 | ||
135 | gdb_exit | |
136 | gdb_start | |
137 | gdb_reinitialize_dir $srcdir/$subdir | |
582e64c2 | 138 | gdb_file_cmd ${binfile} |
c1bd25fd DJ |
139 | |
140 | # Check the values of the variables. | |
141 | gdb_test "print static_foo" "\\\$$decimal = 1" | |
142 | gdb_test "print static_bar" "\\\$$decimal = 2" | |
143 | gdb_test "print global_foo" "\\\$$decimal = 3" | |
144 | gdb_test "print global_bar" "\\\$$decimal = 4" |