Commit | Line | Data |
---|---|---|
9b254dd1 | 1 | # Copyright 2002, 2003, 2005, 2007, 2008 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 DJ |
15 | |
16 | # Please email any bugs, comments, and/or additions to this file to: | |
17 | # bug-gdb@prep.ai.mit.edu | |
18 | ||
19 | # relocate.exp -- Expect script to test loading symbols from unrelocated | |
20 | # object files. | |
21 | ||
22 | if $tracelevel then { | |
23 | strace $tracelevel | |
24 | } | |
25 | ||
26 | set testfile relocate | |
f2dd3617 | 27 | set srcfile ${testfile}.c |
a7d17088 DJ |
28 | set binfile ${objdir}/${subdir}/${testfile}.o |
29 | ||
30 | remote_exec build "rm -f ${binfile}" | |
f2dd3617 | 31 | if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" object {debug}] != "" } { |
b60f0898 JB |
32 | untested relocate.exp |
33 | return -1 | |
a7d17088 DJ |
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" \ | |
1c199746 | 70 | "Reading symbols from .*${testfile}\\.o\\.\\.\\.done\\.(|\r\nUsing host libthread_db library .*libthread_db.so.*\\.)" \ |
a7d17088 DJ |
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 | ||
2f816dda DJ |
108 | # Now use a variable as an offset to add-symbol-file, and check that |
109 | # the functions' addresses change. | |
110 | ||
111 | gdb_exit | |
112 | gdb_start | |
113 | gdb_reinitialize_dir $srcdir/$subdir | |
114 | ||
115 | gdb_test "set \$offset = 0x10000" "" | |
116 | ||
117 | # Load the object file. | |
118 | gdb_test "add-symbol-file ${binfile} \$offset" \ | |
1c199746 | 119 | "Reading symbols from .*${testfile}\\.o\\.\\.\\.done\\.(|\r\nUsing host libthread_db library .*libthread_db.so.*\\.)" \ |
2f816dda DJ |
120 | "add-symbol-file ${testfile}.o \$offset" \ |
121 | "add symbol table from file \".*${testfile}\\.o\" at\[ \t\r\n\]+\.text_addr = 0x10000\[\r\n\]+\\(y or n\\) " \ | |
122 | "y" | |
123 | ||
124 | # Print the addresses of functions. | |
125 | set new_function_foo_addr [get_var_address function_foo] | |
126 | ||
127 | # Make sure they have different addresses. | |
128 | if { "${function_foo_addr}" == "${new_function_foo_addr}" } { | |
129 | fail "function foo has a different address" | |
130 | } else { | |
131 | pass "function foo has a different address" | |
132 | } | |
133 | ||
c1bd25fd DJ |
134 | # Now try loading the object as an exec-file; we should be able to print |
135 | # the values of variables after we do this. | |
136 | ||
137 | gdb_exit | |
138 | gdb_start | |
139 | gdb_reinitialize_dir $srcdir/$subdir | |
582e64c2 | 140 | gdb_file_cmd ${binfile} |
c1bd25fd DJ |
141 | |
142 | # Check the values of the variables. | |
143 | gdb_test "print static_foo" "\\\$$decimal = 1" | |
144 | gdb_test "print static_bar" "\\\$$decimal = 2" | |
145 | gdb_test "print global_foo" "\\\$$decimal = 3" | |
146 | gdb_test "print global_bar" "\\\$$decimal = 4" |