]>
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 } { | |
02746bbc | 35 | global gdb_prompt hex |
a7d17088 | 36 | |
02746bbc MS |
37 | # Match output like: |
38 | # $1 = (int *) 0x0 | |
39 | # $5 = (int (*)()) 0 | |
40 | # $6 = (int (*)()) 0x24 <function_bar> | |
41 | ||
42 | gdb_test_multiple "print &${var}" "get address of ${var}" { | |
43 | -re "\\\$\[0-9\]+ = \\(.*\\) (0|$hex)( <${var}>)?\[\r\n\]+${gdb_prompt} $" { | |
44 | pass "get address of ${var}" | |
45 | if { $expect_out(1,string) == "0" } { | |
46 | return "0x0" | |
47 | } else { | |
48 | return $expect_out(1,string) | |
49 | } | |
a7d17088 | 50 | } |
02746bbc MS |
51 | } |
52 | return "" | |
a7d17088 DJ |
53 | } |
54 | ||
55 | ||
56 | ||
57 | gdb_exit | |
58 | gdb_start | |
59 | gdb_reinitialize_dir $srcdir/$subdir | |
60 | ||
61 | # Load the object file. | |
62 | gdb_test "add-symbol-file ${binfile} 0" \ | |
1c199746 | 63 | "Reading symbols from .*${testfile}\\.o\\.\\.\\.done\\.(|\r\nUsing host libthread_db library .*libthread_db.so.*\\.)" \ |
a7d17088 DJ |
64 | "add-symbol-file ${testfile}.o 0" \ |
65 | "add symbol table from file \".*${testfile}\\.o\" at\[ \t\r\n\]+\.text_addr = 0x0\[\r\n\]+\\(y or n\\) " \ | |
66 | "y" | |
67 | ||
68 | # Print the addresses of static variables. | |
69 | set static_foo_addr [get_var_address static_foo] | |
70 | set static_bar_addr [get_var_address static_bar] | |
71 | ||
72 | # Make sure they have different addresses. | |
73 | if { "${static_foo_addr}" == "${static_bar_addr}" } { | |
74 | fail "static variables have different addresses" | |
75 | } else { | |
76 | pass "static variables have different addresses" | |
77 | } | |
78 | ||
79 | # Print the addresses of global variables. | |
80 | set global_foo_addr [get_var_address global_foo] | |
81 | set global_bar_addr [get_var_address global_bar] | |
82 | ||
83 | # Make sure they have different addresses. | |
84 | if { "${global_foo_addr}" == "${global_bar_addr}" } { | |
85 | fail "global variables have different addresses" | |
86 | } else { | |
87 | pass "global variables have different addresses" | |
88 | } | |
89 | ||
90 | # Print the addresses of functions. | |
91 | set function_foo_addr [get_var_address function_foo] | |
92 | set function_bar_addr [get_var_address function_bar] | |
93 | ||
94 | # Make sure they have different addresses. | |
95 | if { "${function_foo_addr}" == "${function_bar_addr}" } { | |
96 | fail "functions have different addresses" | |
97 | } else { | |
98 | pass "functions have different addresses" | |
99 | } | |
100 | ||
2f816dda DJ |
101 | # Now use a variable as an offset to add-symbol-file, and check that |
102 | # the functions' addresses change. | |
103 | ||
104 | gdb_exit | |
105 | gdb_start | |
106 | gdb_reinitialize_dir $srcdir/$subdir | |
107 | ||
108 | gdb_test "set \$offset = 0x10000" "" | |
109 | ||
110 | # Load the object file. | |
111 | gdb_test "add-symbol-file ${binfile} \$offset" \ | |
1c199746 | 112 | "Reading symbols from .*${testfile}\\.o\\.\\.\\.done\\.(|\r\nUsing host libthread_db library .*libthread_db.so.*\\.)" \ |
2f816dda DJ |
113 | "add-symbol-file ${testfile}.o \$offset" \ |
114 | "add symbol table from file \".*${testfile}\\.o\" at\[ \t\r\n\]+\.text_addr = 0x10000\[\r\n\]+\\(y or n\\) " \ | |
115 | "y" | |
116 | ||
117 | # Print the addresses of functions. | |
118 | set new_function_foo_addr [get_var_address function_foo] | |
119 | ||
120 | # Make sure they have different addresses. | |
121 | if { "${function_foo_addr}" == "${new_function_foo_addr}" } { | |
122 | fail "function foo has a different address" | |
123 | } else { | |
124 | pass "function foo has a different address" | |
125 | } | |
126 | ||
c1bd25fd DJ |
127 | # Now try loading the object as an exec-file; we should be able to print |
128 | # the values of variables after we do this. | |
129 | ||
130 | gdb_exit | |
131 | gdb_start | |
132 | gdb_reinitialize_dir $srcdir/$subdir | |
582e64c2 | 133 | gdb_file_cmd ${binfile} |
c1bd25fd DJ |
134 | |
135 | # Check the values of the variables. | |
136 | gdb_test "print static_foo" "\\\$$decimal = 1" | |
137 | gdb_test "print static_bar" "\\\$$decimal = 2" | |
138 | gdb_test "print global_foo" "\\\$$decimal = 3" | |
139 | gdb_test "print global_bar" "\\\$$decimal = 4" |