]> Git Repo - binutils.git/blob - gdb/testsuite/gdb.base/relocate.exp
* infrun.c (handle_inferior_event)
[binutils.git] / gdb / testsuite / gdb.base / relocate.exp
1 # Copyright 2002-2003, 2005, 2007-2012 Free Software Foundation, Inc.
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
5 # the Free Software Foundation; either version 3 of the License, or
6 # (at your option) any later version.
7 #
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.
12 #
13 # You should have received a copy of the GNU General Public License
14 # along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
15
16 # relocate.exp -- Expect script to test loading symbols from unrelocated
17 #                 object files.
18
19 set testfile relocate
20 set srcfile ${testfile}.c
21 set binfile ${objdir}/${subdir}/${testfile}.o
22
23 remote_exec build "rm -f ${binfile}"
24 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" object {debug}] != "" } {
25      untested relocate.exp
26      return -1
27 }
28
29 proc get_var_address { var } {
30     global gdb_prompt hex
31
32     # Match output like:
33     # $1 = (int *) 0x0
34     # $5 = (int (*)()) 0
35     # $6 = (int (*)()) 0x24 <function_bar>
36
37     gdb_test_multiple "print &${var}" "get address of ${var}" {
38         -re "\\\$\[0-9\]+ = \\(.*\\) (0|$hex)( <${var}>)?\[\r\n\]+${gdb_prompt} $" {
39             pass "get address of ${var}"
40             if { $expect_out(1,string) == "0" } {
41                 return "0x0"
42             } else {
43                 return $expect_out(1,string)
44             }
45         }
46     }
47     return ""
48 }
49
50
51
52 gdb_exit
53 gdb_start
54 gdb_reinitialize_dir $srcdir/$subdir
55
56 # Load the object file.
57 gdb_test "add-symbol-file ${binfile} 0" \
58         "Reading symbols from .*${testfile}\\.o\\.\\.\\.done\\.(|\r\nUsing host libthread_db library .*libthread_db.so.*\\.)" \
59         "add-symbol-file ${testfile}.o 0" \
60         "add symbol table from file \".*${testfile}\\.o\" at\[ \t\r\n\]+\.text_addr = 0x0\[\r\n\]+\\(y or n\\) " \
61         "y"
62
63 # Print the addresses of static variables.
64 set static_foo_addr [get_var_address static_foo]
65 set static_bar_addr [get_var_address static_bar]
66
67 # Make sure they have different addresses.
68 if { "${static_foo_addr}" == "${static_bar_addr}" } {
69   fail "static variables have different addresses"
70 } else {
71   pass "static variables have different addresses"
72 }
73
74 # Print the addresses of global variables.
75 set global_foo_addr [get_var_address global_foo]
76 set global_bar_addr [get_var_address global_bar]
77
78 # Make sure they have different addresses.
79 if { "${global_foo_addr}" == "${global_bar_addr}" } {
80   fail "global variables have different addresses"
81 } else {
82   pass "global variables have different addresses"
83 }
84
85 # Print the addresses of functions.
86 set function_foo_addr [get_var_address function_foo]
87 set function_bar_addr [get_var_address function_bar]
88
89 # Make sure they have different addresses.
90 if { "${function_foo_addr}" == "${function_bar_addr}" } {
91   fail "functions have different addresses"
92 } else {
93   pass "functions have different addresses"
94 }
95
96 # Now use a variable as an offset to add-symbol-file, and check that
97 # the functions' addresses change.
98
99 gdb_exit
100 gdb_start
101 gdb_reinitialize_dir $srcdir/$subdir
102
103 gdb_test_no_output "set \$offset = 0x10000"
104
105 # Load the object file.
106 gdb_test "add-symbol-file ${binfile} \$offset" \
107         "Reading symbols from .*${testfile}\\.o\\.\\.\\.done\\.(|\r\nUsing host libthread_db library .*libthread_db.so.*\\.)" \
108         "add-symbol-file ${testfile}.o \$offset" \
109         "add symbol table from file \".*${testfile}\\.o\" at\[ \t\r\n\]+\.text_addr = 0x10000\[\r\n\]+\\(y or n\\) " \
110         "y"
111
112 # Print the addresses of functions.
113 set new_function_foo_addr [get_var_address function_foo]
114
115 # Make sure they have different addresses.
116 if { "${function_foo_addr}" == "${new_function_foo_addr}" } {
117   fail "function foo has a different address"
118 } else {
119   pass "function foo has a different address"
120 }
121
122 # Now try loading the object as an exec-file; we should be able to print
123 # the values of variables after we do this.
124
125 gdb_exit
126 gdb_start
127 gdb_reinitialize_dir $srcdir/$subdir
128 gdb_file_cmd ${binfile}
129
130 # Check the values of the variables.
131 gdb_test "print static_foo" "\\\$$decimal = 1"
132 gdb_test "print static_bar" "\\\$$decimal = 2"
133 gdb_test "print global_foo" "\\\$$decimal = 3"
134 gdb_test "print global_bar" "\\\$$decimal = 4"
This page took 0.034878 seconds and 4 git commands to generate.