ld/
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.cp / rtti.exp
CommitLineData
0b302171 1# Copyright 2003-2004, 2007-2012 Free Software Foundation, Inc.
58da2eb2
DC
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
58da2eb2 6# (at your option) any later version.
e22f8b7c 7#
58da2eb2
DC
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#
58da2eb2 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/>.
58da2eb2
DC
15
16# This file is part of the gdb testsuite.
17
18# This contains tests for GDB's use of RTTI information. This stems
19# from a bug reported in PR gdb/488 and other places, which leads to
20# statements like 'warning: can't find class named 'C::D', as given by
21# C++ RTTI'. It arises from GDB not knowing about classes that are
22# defined in namespaces.
23
24# NOTE: carlton/2003-05-16: I suspect it could arise from nested class
25# issues, too, and even once we fix that, there might be situations
26# (involving templates, in particular) where this problem triggers
27# because GDB and GCC have different ideas what a class is called.
28
58da2eb2
DC
29if { [skip_cplus_tests] } { continue }
30
31#
32# test running programs
33#
58da2eb2
DC
34
35set testfile "rtti"
dd8c8ee7
MC
36set srcfile1 "${testfile}1.cc"
37set objfile1 "${testfile}1.o"
38set srcfile2 "${testfile}2.cc"
39set objfile2 "${testfile}2.o"
40set binfile "${objdir}/${subdir}/${testfile}"
58da2eb2 41
dd8c8ee7 42if { [gdb_compile "$srcdir/$subdir/$srcfile1" "$objdir/$subdir/$objfile1" object {debug c++}] != "" } {
b60f0898
JB
43 untested rtti.exp
44 return -1
58da2eb2
DC
45}
46
dd8c8ee7 47if { [gdb_compile "$srcdir/$subdir/$srcfile2" "$objdir/$subdir/$objfile2" object {debug c++}] != "" } {
b60f0898
JB
48 untested rtti.exp
49 return -1
58da2eb2
DC
50}
51
dd8c8ee7 52if { [gdb_compile "$objdir/$subdir/$objfile1 $objdir/$subdir/$objfile2" "${binfile}" executable {debug c++}] != "" } {
b60f0898
JB
53 untested rtti.exp
54 return -1
58da2eb2
DC
55}
56
57if [get_compiler_info ${binfile} "c++"] {
58 return -1
59}
60
61gdb_exit
62gdb_start
63gdb_reinitialize_dir $srcdir/$subdir
64gdb_load ${binfile}
65
66
67if ![runto_main] then {
68 perror "couldn't run to breakpoint"
69 continue
70}
71
72# First, run to after we've constructed the object:
73
dd8c8ee7 74gdb_breakpoint [gdb_get_line_number "main-constructs-done" "$srcfile1"]
b368761e 75gdb_continue_to_breakpoint "end of constructors in main"
58da2eb2
DC
76
77gdb_test_multiple "print *e1" "print *e1" {
374451f0
MC
78 -re "warning: RTTI symbol not found for class 'n1::D1'.*$gdb_prompt $" {
79 # gdb HEAD 2003-12-05
80 kfail "gdb/488" "print *e1"
81 }
58da2eb2 82 -re "warning: can't find class named `n1::D1', as given by C\\+\\+ RTTI.*$gdb_prompt $" {
374451f0 83 # gdb 6.0
58da2eb2
DC
84 kfail "gdb/488" "print *e1"
85 }
86 -re "\\$\[0-9\]* = {<n1::Base1> = .*}\r\n$gdb_prompt $" {
87 pass "print *e1"
88 }
89 -re "\\$\[0-9\]* = {<Base1> = .*}\r\n$gdb_prompt $" {
90 # NOTE: carlton/2003-05-16: If code is compiled by GCC2, we
91 # don't print the warning (for no particular reason), but we
92 # still call the class via the wrong name; PR gdb/57 is our
93 # catch-all PR for nested type problems.
94 kfail "gdb/57" "print *e1"
95 }
96}
97
3e5fc8d2
DC
98# NOTE: carlton/2004-01-14: This test with an "<incomplete type>"
99# message because, within rtt1.cc, GDB has no way of knowing that the
100# class is called 'n2::D2' instead of just 'D2'. This is an artifical
101# test case, though: if we were using these classes in a more
102# substantial way, G++ would emit more debug info. As is, I don't
103# think there's anything that GDB can do about this case until G++
104# starts emitting DW_TAG_namespace info; this should arrive with GCC
105# 3.4.
58da2eb2
DC
106
107gdb_test_multiple "print *e2" "print *e2" {
374451f0
MC
108 -re "warning: RTTI symbol not found for class 'n2::D2'.*$gdb_prompt $" {
109 # gdb HEAD 2003-12-05
110 kfail "gdb/488" "print *e2"
111 }
58da2eb2 112 -re "warning: can't find class named `n2::D2', as given by C\\+\\+ RTTI.*$gdb_prompt $" {
374451f0 113 # gdb 6.0
58da2eb2
DC
114 kfail "gdb/488" "print *e2"
115 }
116 -re "\\$\[0-9\]* = <incomplete type>\r\n$gdb_prompt $" {
3e5fc8d2 117 kfail "gdb/1511" "print *e2"
58da2eb2
DC
118 }
119 -re "\\$\[0-9\]* = {<n2::Base2> = .*}\r\n$gdb_prompt $" {
120 pass "print *e2"
121 }
122 -re "\\$\[0-9\]* = {<Base2> = .*}\r\n$gdb_prompt $" {
123 kfail "gdb/57" "print *e2"
124 }
125}
126
b368761e
DC
127# Now we test the hack that's been implemented to get around some
128# instances of PR gdb/1511.
129
dd8c8ee7 130gdb_breakpoint [gdb_get_line_number "func-constructs-done" "$srcfile1"]
b368761e
DC
131gdb_continue_to_breakpoint "end of constructors in func"
132
133gdb_test "print *obj" "\\$\[0-9\]* = {<n2::Base2> = .*}"
134
dd8c8ee7 135gdb_breakpoint [gdb_get_line_number "func3-constructs-done" "$srcfile1"]
1198ecbe
DC
136gdb_continue_to_breakpoint "end of constructors in func3"
137
138gdb_test "print *obj3" "\\$\[0-9\]* = {<n2::C2> = .*}"
139
58da2eb2
DC
140gdb_exit
141return 0
This page took 0.880061 seconds and 4 git commands to generate.