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