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