OpenCores
URL https://opencores.org/ocsvn/scarts/scarts/trunk

Subversion Repositories scarts

[/] [scarts/] [trunk/] [toolchain/] [scarts-gdb/] [gdb-6.8/] [gdb/] [testsuite/] [gdb.base/] [relocate.exp] - Blame information for rev 25

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 25 jlechner
# Copyright 2002, 2003, 2005, 2007, 2008 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 .  */
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
 
22
if $tracelevel then {
23
    strace $tracelevel
24
}
25
 
26
set testfile relocate
27
set srcfile ${testfile}.c
28
set binfile ${objdir}/${subdir}/${testfile}.o
29
 
30
remote_exec build "rm -f ${binfile}"
31
if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" object {debug}] != "" } {
32
     untested relocate.exp
33
     return -1
34
}
35
 
36
proc 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 
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
 
64
gdb_exit
65
gdb_start
66
gdb_reinitialize_dir $srcdir/$subdir
67
 
68
# Load the object file.
69
gdb_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.
76
set static_foo_addr [get_var_address static_foo]
77
set static_bar_addr [get_var_address static_bar]
78
 
79
# Make sure they have different addresses.
80
if { "${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.
87
set global_foo_addr [get_var_address global_foo]
88
set global_bar_addr [get_var_address global_bar]
89
 
90
# Make sure they have different addresses.
91
if { "${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.
98
set function_foo_addr [get_var_address function_foo]
99
set function_bar_addr [get_var_address function_bar]
100
 
101
# Make sure they have different addresses.
102
if { "${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
 
111
gdb_exit
112
gdb_start
113
gdb_reinitialize_dir $srcdir/$subdir
114
 
115
gdb_test "set \$offset = 0x10000" ""
116
 
117
# Load the object file.
118
gdb_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.
125
set new_function_foo_addr [get_var_address function_foo]
126
 
127
# Make sure they have different addresses.
128
if { "${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
 
137
gdb_exit
138
gdb_start
139
gdb_reinitialize_dir $srcdir/$subdir
140
gdb_file_cmd ${binfile}
141
 
142
# Check the values of the variables.
143
gdb_test "print static_foo" "\\\$$decimal = 1"
144
gdb_test "print static_bar" "\\\$$decimal = 2"
145
gdb_test "print global_foo" "\\\$$decimal = 3"
146
gdb_test "print global_bar" "\\\$$decimal = 4"

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.