• Home
  • History
  • Annotate
  • Line#
  • Navigate
  • Raw
  • Download
  • only in /asuswrt-rt-n18u-9.0.0.4.380.2695/release/src-rt-6.x.4708/router/gdb/gdb/testsuite/gdb.base/
1# Copyright 2002, 2003, 2005, 2007 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# 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
22if $tracelevel then {
23    strace $tracelevel
24}
25
26set testfile relocate
27set srcfile ${testfile}.c
28set binfile ${objdir}/${subdir}/${testfile}.o
29
30remote_exec build "rm -f ${binfile}"
31if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" object {debug}] != "" } {
32     untested relocate.exp
33     return -1
34}
35
36proc 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
64gdb_exit
65gdb_start
66gdb_reinitialize_dir $srcdir/$subdir
67
68# Load the object file.
69gdb_test "add-symbol-file ${binfile} 0" \
70	"Reading symbols from .*${testfile}\\.o\\.\\.\\.done\\.(|\r\nUsing host libthread_db library .*libthread_db.so.*\\.)" \
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.
76set static_foo_addr [get_var_address static_foo]
77set static_bar_addr [get_var_address static_bar]
78
79# Make sure they have different addresses.
80if { "${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.
87set global_foo_addr [get_var_address global_foo]
88set global_bar_addr [get_var_address global_bar]
89
90# Make sure they have different addresses.
91if { "${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.
98set function_foo_addr [get_var_address function_foo]
99set function_bar_addr [get_var_address function_bar]
100
101# Make sure they have different addresses.
102if { "${function_foo_addr}" == "${function_bar_addr}" } {
103  fail "functions have different addresses"
104} else {
105  pass "functions have different addresses"
106}
107
108# Now use a variable as an offset to add-symbol-file, and check that
109# the functions' addresses change.
110
111gdb_exit
112gdb_start
113gdb_reinitialize_dir $srcdir/$subdir
114
115gdb_test "set \$offset = 0x10000" ""
116
117# Load the object file.
118gdb_test "add-symbol-file ${binfile} \$offset" \
119	"Reading symbols from .*${testfile}\\.o\\.\\.\\.done\\.(|\r\nUsing host libthread_db library .*libthread_db.so.*\\.)" \
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.
125set new_function_foo_addr [get_var_address function_foo]
126
127# Make sure they have different addresses.
128if { "${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
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
137gdb_exit
138gdb_start
139gdb_reinitialize_dir $srcdir/$subdir
140gdb_file_cmd ${binfile}
141
142# Check the values of the variables.
143gdb_test "print static_foo" "\\\$$decimal = 1"
144gdb_test "print static_bar" "\\\$$decimal = 2"
145gdb_test "print global_foo" "\\\$$decimal = 3"
146gdb_test "print global_bar" "\\\$$decimal = 4"
147