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