1# Copyright 2003-2017 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# 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 29if { [skip_cplus_tests] } { continue } 30 31# 32# test running programs 33# 34 35standard_testfile rtti1.cc rtti2.cc 36 37if [get_compiler_info "c++"] { 38 return -1 39} 40 41if {[prepare_for_testing "failed to prepare" $testfile \ 42 [list $srcfile $srcfile2] {debug c++}]} { 43 return -1 44} 45 46if ![runto_main] then { 47 perror "couldn't run to breakpoint" 48 continue 49} 50 51# First, run to after we've constructed the object: 52 53gdb_breakpoint [gdb_get_line_number "main-constructs-done" "$srcfile"] 54gdb_continue_to_breakpoint "end of constructors in main" 55 56gdb_test_multiple "print *e1" "print *e1" { 57 -re "warning: RTTI symbol not found for class 'n1::D1'.*$gdb_prompt $" { 58 # gdb HEAD 2003-12-05 59 kfail "gdb/488" "print *e1" 60 } 61 -re "warning: can't find class named `n1::D1', as given by C\\+\\+ RTTI.*$gdb_prompt $" { 62 # gdb 6.0 63 kfail "gdb/488" "print *e1" 64 } 65 -re "\\$\[0-9\]* = {<n1::Base1> = .*}\r\n$gdb_prompt $" { 66 pass "print *e1" 67 } 68 -re "\\$\[0-9\]* = {<Base1> = .*}\r\n$gdb_prompt $" { 69 # NOTE: carlton/2003-05-16: If code is compiled by GCC2, we 70 # don't print the warning (for no particular reason), but we 71 # still call the class via the wrong name; PR gdb/57 is our 72 # catch-all PR for nested type problems. 73 kfail "gdb/57" "print *e1" 74 } 75} 76 77# NOTE: carlton/2004-01-14: This test with an "<incomplete type>" 78# message because, within rtt1.cc, GDB has no way of knowing that the 79# class is called 'n2::D2' instead of just 'D2'. This is an artifical 80# test case, though: if we were using these classes in a more 81# substantial way, G++ would emit more debug info. As is, I don't 82# think there's anything that GDB can do about this case until G++ 83# starts emitting DW_TAG_namespace info; this should arrive with GCC 84# 3.4. 85 86gdb_test_multiple "print *e2" "print *e2" { 87 -re "warning: RTTI symbol not found for class 'n2::D2'.*$gdb_prompt $" { 88 # gdb HEAD 2003-12-05 89 kfail "gdb/488" "print *e2" 90 } 91 -re "warning: can't find class named `n2::D2', as given by C\\+\\+ RTTI.*$gdb_prompt $" { 92 # gdb 6.0 93 kfail "gdb/488" "print *e2" 94 } 95 -re "\\$\[0-9\]* = <incomplete type>\r\n$gdb_prompt $" { 96 kfail "gdb/1511" "print *e2" 97 } 98 -re "\\$\[0-9\]* = {<n2::Base2> = .*}\r\n$gdb_prompt $" { 99 pass "print *e2" 100 } 101 -re "\\$\[0-9\]* = {<Base2> = .*}\r\n$gdb_prompt $" { 102 kfail "gdb/57" "print *e2" 103 } 104} 105 106# Now we test the hack that's been implemented to get around some 107# instances of PR gdb/1511. 108 109gdb_breakpoint [gdb_get_line_number "func-constructs-done" "$srcfile"] 110gdb_continue_to_breakpoint "end of constructors in func" 111 112gdb_test "print *obj" "\\$\[0-9\]* = {<n2::Base2> = .*}" 113 114gdb_breakpoint [gdb_get_line_number "func3-constructs-done" "$srcfile"] 115gdb_continue_to_breakpoint "end of constructors in func3" 116 117gdb_test "print *obj3" "\\$\[0-9\]* = {<n2::C2> = .*}" 118 119gdb_exit 120return 0 121