]>
Commit | Line | Data |
---|---|---|
61baf725 | 1 | # Copyright 2002-2017 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 | 15 | |
a7d17088 DJ |
16 | # relocate.exp -- Expect script to test loading symbols from unrelocated |
17 | # object files. | |
18 | ||
822bd149 TT |
19 | standard_testfile .c |
20 | append binfile .o | |
a7d17088 DJ |
21 | |
22 | remote_exec build "rm -f ${binfile}" | |
f2dd3617 | 23 | if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" object {debug}] != "" } { |
84c93cd5 | 24 | untested "failed to compile" |
b60f0898 | 25 | return -1 |
a7d17088 DJ |
26 | } |
27 | ||
a7d17088 DJ |
28 | gdb_exit |
29 | gdb_start | |
30 | gdb_reinitialize_dir $srcdir/$subdir | |
31 | ||
41dc8db8 MB |
32 | #Check that invalid options are rejected. |
33 | foreach x {"-raednow" "readnow" "foo" "-readnow s"} { | |
34 | gdb_test "add-symbol-file ${binfile} 0 $x" \ | |
35 | "USAGE: add-symbol-file <filename> <textaddress>.*-readnow.*-s <secname> <addr>.*" \ | |
36 | "add-symbol-file: unknown option $x" | |
37 | } | |
38 | ||
a7d17088 DJ |
39 | # Load the object file. |
40 | gdb_test "add-symbol-file ${binfile} 0" \ | |
1c199746 | 41 | "Reading symbols from .*${testfile}\\.o\\.\\.\\.done\\.(|\r\nUsing host libthread_db library .*libthread_db.so.*\\.)" \ |
a7d17088 DJ |
42 | "add-symbol-file ${testfile}.o 0" \ |
43 | "add symbol table from file \".*${testfile}\\.o\" at\[ \t\r\n\]+\.text_addr = 0x0\[\r\n\]+\\(y or n\\) " \ | |
44 | "y" | |
45 | ||
46 | # Print the addresses of static variables. | |
47 | set static_foo_addr [get_var_address static_foo] | |
48 | set static_bar_addr [get_var_address static_bar] | |
49 | ||
50 | # Make sure they have different addresses. | |
51 | if { "${static_foo_addr}" == "${static_bar_addr}" } { | |
52 | fail "static variables have different addresses" | |
53 | } else { | |
54 | pass "static variables have different addresses" | |
55 | } | |
56 | ||
57 | # Print the addresses of global variables. | |
58 | set global_foo_addr [get_var_address global_foo] | |
59 | set global_bar_addr [get_var_address global_bar] | |
60 | ||
61 | # Make sure they have different addresses. | |
62 | if { "${global_foo_addr}" == "${global_bar_addr}" } { | |
63 | fail "global variables have different addresses" | |
64 | } else { | |
65 | pass "global variables have different addresses" | |
66 | } | |
67 | ||
68 | # Print the addresses of functions. | |
69 | set function_foo_addr [get_var_address function_foo] | |
70 | set function_bar_addr [get_var_address function_bar] | |
71 | ||
72 | # Make sure they have different addresses. | |
73 | if { "${function_foo_addr}" == "${function_bar_addr}" } { | |
74 | fail "functions have different addresses" | |
75 | } else { | |
76 | pass "functions have different addresses" | |
77 | } | |
78 | ||
2f816dda DJ |
79 | # Now use a variable as an offset to add-symbol-file, and check that |
80 | # the functions' addresses change. | |
81 | ||
82 | gdb_exit | |
83 | gdb_start | |
84 | gdb_reinitialize_dir $srcdir/$subdir | |
85 | ||
27d3a1a2 | 86 | gdb_test_no_output "set \$offset = 0x10000" |
2f816dda DJ |
87 | |
88 | # Load the object file. | |
89 | gdb_test "add-symbol-file ${binfile} \$offset" \ | |
1c199746 | 90 | "Reading symbols from .*${testfile}\\.o\\.\\.\\.done\\.(|\r\nUsing host libthread_db library .*libthread_db.so.*\\.)" \ |
2f816dda DJ |
91 | "add-symbol-file ${testfile}.o \$offset" \ |
92 | "add symbol table from file \".*${testfile}\\.o\" at\[ \t\r\n\]+\.text_addr = 0x10000\[\r\n\]+\\(y or n\\) " \ | |
93 | "y" | |
94 | ||
95 | # Print the addresses of functions. | |
96 | set new_function_foo_addr [get_var_address function_foo] | |
97 | ||
98 | # Make sure they have different addresses. | |
99 | if { "${function_foo_addr}" == "${new_function_foo_addr}" } { | |
100 | fail "function foo has a different address" | |
101 | } else { | |
102 | pass "function foo has a different address" | |
103 | } | |
104 | ||
c1bd25fd DJ |
105 | # Now try loading the object as an exec-file; we should be able to print |
106 | # the values of variables after we do this. | |
107 | ||
108 | gdb_exit | |
109 | gdb_start | |
110 | gdb_reinitialize_dir $srcdir/$subdir | |
582e64c2 | 111 | gdb_file_cmd ${binfile} |
c1bd25fd DJ |
112 | |
113 | # Check the values of the variables. | |
114 | gdb_test "print static_foo" "\\\$$decimal = 1" | |
115 | gdb_test "print static_bar" "\\\$$decimal = 2" | |
116 | gdb_test "print global_foo" "\\\$$decimal = 3" | |
117 | gdb_test "print global_bar" "\\\$$decimal = 4" |