* gdb.base/maint.exp: Remove full paths from test names.
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.cp / cp-relocate.exp
1 # Copyright 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 2 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, write to the Free Software
15 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
16
17 # Test loading symbols from unrelocated C++ object files.
18
19 set testfile cp-relocate
20 set srcfile ${testfile}.cc
21 set binfile ${objdir}/${subdir}/${testfile}.o
22
23 if { [skip_cplus_tests] } { continue }
24
25 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" object {c++ debug}] != "" } {
26 untested cp-relocate.exp
27 return -1
28 }
29
30 proc get_func_address { func } {
31 global gdb_prompt hex
32
33 set rfunc [string_to_regexp $func]
34 gdb_test_multiple "print '${func}'" "get address of ${func}" {
35 -re "\\\$\[0-9\]+ = \\{.*\\} (0|($hex) <${rfunc}>)\[\r\n\]+${gdb_prompt} $" {
36 # $1 = {int ()} 0x24 <function_bar>
37 # But if the function is at zero, the name may be omitted.
38 pass "get address of ${func}"
39 if { $expect_out(1,string) == "0" } {
40 return "0x0"
41 } else {
42 return $expect_out(2,string)
43 }
44 }
45 }
46 return ""
47 }
48
49 # Load the file as an executable; GDB should assign non-overlapping
50 # section offsets.
51 gdb_exit
52 gdb_start
53 gdb_reinitialize_dir $srcdir/$subdir
54 gdb_file_cmd ${binfile}
55
56 # Find the interesting functions. We go to a little effort to find
57 # the right function names here, to work around PR c++/40.
58 set func1_name ""
59 set func2_name ""
60 gdb_test_multiple "info functions func<.>" "info functions" {
61 -re "\r\nint (\[^\r\]*func<1>\[^\r]*);" {
62 set func1_name $expect_out(1,string)
63 exp_continue
64 }
65 -re "\r\nint (\[^\r\]*func<2>\[^\r]*);" {
66 set func2_name $expect_out(1,string)
67 exp_continue
68 }
69 -re "$gdb_prompt $" {
70 if { ${func1_name} != "" && ${func2_name} != "" } {
71 pass "info functions"
72 } else {
73 fail "info functions"
74 return -1
75 }
76 }
77 }
78
79 # Check that all the functions have different addresses.
80 set func1_addr [get_func_address "$func1_name"]
81 set func2_addr [get_func_address "$func2_name"]
82 set caller_addr [get_func_address "caller"]
83
84 if { "${func1_addr}" == "${func2_addr}"
85 || "${func1_addr}" == "${func2_addr}"
86 || "${func2_addr}" == "${caller_addr}" } {
87 fail "C++ functions have different addresses"
88 } else {
89 pass "C++ functions have different addresses"
90 }
91
92 # Figure out the names of the sections containing the template
93 # functions.
94 set func1_sec ""
95 set func2_sec ""
96 gdb_test_multiple "info file" "info file" {
97 -re "($hex) - ($hex) is (\[^\r\]*)\r" {
98 if { $expect_out(1,string) <= $func1_addr
99 && $expect_out(2,string) > $func1_addr } {
100 set func1_sec $expect_out(3,string)
101 } elseif { $expect_out(1,string) <= $func2_addr
102 && $expect_out(2,string) > $func2_addr } {
103 set func2_sec $expect_out(3,string)
104 }
105 exp_continue
106 }
107 -re "$gdb_prompt $" {
108 if { ${func1_sec} != "" && ${func2_sec} != "" } {
109 pass "info file"
110 } else {
111 fail "info file"
112 return -1
113 }
114 }
115 }
116
117 if { $func1_sec == $func2_sec } {
118 untested "cp-relocate.exp - template functions in same sections"
119 return -1
120 }
121
122 # Now start a clean GDB, for add-symbol-file tests.
123 gdb_exit
124 gdb_start
125 gdb_reinitialize_dir $srcdir/$subdir
126
127 gdb_test "add-symbol-file ${binfile} 0 -s ${func1_sec} 0x40000 -s ${func2_sec} 0x80000" \
128 "Reading symbols from .*${testfile}\\.o\\.\\.\\.done\\.(|\r\nUsing host libthread_db library .*libthread_db.so.*\\.)" \
129 "add-symbol-file ${testfile}.o" \
130 "add symbol table from file \".*${testfile}\\.o\" at.*\\(y or n\\) " \
131 "y"
132
133 # Make sure the function addresses were updated.
134 gdb_test "break *'$func1_name'" \
135 "Breakpoint $decimal at 0x4....: file .*"
136 gdb_test "break *'$func2_name'" \
137 "Breakpoint $decimal at 0x8....: file .*"
This page took 0.032995 seconds and 5 git commands to generate.