1# Copyright 2007-2023 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# When gdb resolves type information for class "derived" from objfile
17# gdb2384, it use to fill in the TYPE_VPTR_BASETYPE field with class "base"
18# from objfile gdb2384-base.so.  When the program is rerun the type
19# information for base-in-so-base.so is discarded leaving
20# TYPE_VPTR_BASETYPE dangling.
21#
22# PR c++/9489.
23
24if { [skip_cplus_tests] } { continue }
25if { [skip_shlib_tests] } { continue }
26
27standard_testfile .cc gdb2384-base.cc
28
29set sofile [standard_output_file gdb2384-base.so]
30
31if { [gdb_compile_shlib $srcdir/$subdir/$srcfile2 $sofile {debug c++}] != ""
32     || [gdb_compile $srcdir/$subdir/$srcfile $binfile executable [list debug "c++" shlib=${sofile}]] != ""} {
33    untested "failed to compile"
34    return -1
35}
36
37clean_restart ${binfile}
38gdb_load_shlib ${sofile}
39
40
41if {![runto_main]} {
42    return -1
43}
44
45gdb_breakpoint [gdb_get_line_number "First breakpoint"]
46gdb_continue_to_breakpoint "run to 'First breakpoint', first time"
47
48gdb_test "print d1.meth ()" \
49    ".*42.*"
50
51# Now try again.  gdb's without the fix will hopefully segv here
52
53runto_main
54gdb_breakpoint [gdb_get_line_number "First breakpoint"]
55gdb_continue_to_breakpoint "run to 'First breakpoint', second time"
56gdb_test "print d1.meth ()" \
57    ".*42.*" \
58    "gdb2384 at 'First breakpoint'"
59
60# second case
61
62runto_main
63gdb_breakpoint [gdb_get_line_number "Second breakpoint"]
64gdb_continue_to_breakpoint "run to 'Second breakpoint', first time"
65gdb_test "print d2.meth ()" \
66    ".*24.*" \
67    "print d2.meth()"
68
69runto_main
70gdb_breakpoint [gdb_get_line_number "Second breakpoint"]
71gdb_continue_to_breakpoint "run to 'Second breakpoint', second time"
72gdb_test "print d2.meth ()" \
73    ".*24.*" \
74    "gdb2384 at 'Second breakpoint'"
75
76