xref: /netbsd-src/external/gpl3/gdb.old/dist/gdb/testsuite/gdb.cp/demangle.exp (revision 122b5006ee1bd67145794b4cde92f4fe4781a5ec)
1# Copyright (C) 1992-2019 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 was written by Fred Fish. (fnf@cygnus.com)
17
18if { [skip_cplus_tests] } { continue }
19
20### The demangling style we last sent to GDB.
21set current_demangling_style none
22
23### Set GDB's current demangling style to STYLE.  Subsequent calls to
24### test_demangle will include STYLE in the test name when reporting
25### passes and failures.
26proc set_demangling_style {style} {
27    global gdb_prompt
28    global current_demangling_style
29
30    gdb_test_multiple "set demangle-style $style" \
31	"$style: set demangle-style" {
32	    -re "set demangle-style $style\[\r\n\]+$gdb_prompt $" {
33		pass "$style: set demangle-style"
34	    }
35	    -re ".*$gdb_prompt $" {
36		fail "$style: set demangle-style"
37		error "set_demangling_style: set style"
38	    }
39	    timeout {
40		fail "$style: set demangle-style (timeout)"
41		error "set_demangling_style: set style"
42	    }
43	}
44
45    gdb_test_multiple "show demangle-style" \
46	"$style: check demangling style" {
47	    -re "The current C\[+\]+ demangling style is \"$style\".\r\n$gdb_prompt $" {
48		pass "$style: check demangling style"
49	    }
50	    -re ".*$gdb_prompt $" {
51		fail "$style: check demangling style"
52		error "set_demangling_style: check style"
53	    }
54	    timeout {
55		fail "$style: check demangling style (timeout)"
56		error "set_demangling_style: check style"
57	    }
58	}
59
60    set current_demangling_style $style
61}
62
63
64### Utility function for test_demangling and test_demangling_exact.
65proc test_demangling_core {tester test result} {
66    global current_demangling_style
67
68    if {! [regexp {^([^ ]+): (.+)$} $test dummy style name]} {
69      error "bad test name passed to test_demangling"
70    }
71
72    if {[string compare $style $current_demangling_style]} {
73	with_test_prefix $test {
74	    set_demangling_style $style
75	}
76    }
77
78    $tester "demangle $name" $result $test
79}
80
81### Demangle an identifier, and check that the result matches a pattern.
82###
83### TEST should be of the form "STYLE: NAME", where STYLE is the name
84### of a demangling style (like "gnu" or "arm"), and NAME is a mangled
85### identifier to demangle.  Pass when the result matches the regular
86### expression RESULT.  Report passes and fails using TEST as the name
87### of the test.
88###
89### Why don't we just pass the STYLE and NAME as two separate
90### arguments, or let the style be a global variable?  That would be
91### cleaner.  However, doing it this way means that:
92###
93### 1) the name of the test, as recorded in the summary and log,
94### appears verbatim in the script, and
95###
96### 2) that test names are unique, even though we try to demangle the same
97### identifiers using several different mangling styles.
98###
99### This makes it a lot easier for people tracking down failures to
100### find the one they care about.
101
102proc test_demangling {test result} {
103    test_demangling_core gdb_test $test $result
104}
105
106### Like test_demangling, above, except that RESULT is not a regexp,
107### but a string that must match exactly.
108
109proc test_demangling_exact {test result} {
110    test_demangling_core gdb_test_exact $test $result
111}
112
113#
114#  Test gnu-v3 style name demangling
115#
116
117proc test_gnuv3_style_demangling {} {
118    global gdb_prompt
119
120    # Rvalue reference tests
121    test_demangling_exact "gnu-v3: _ZN9ArrowLine19ArrowheadIntersectsEP9ArrowheadO6BoxObjP7Graphic" "ArrowLine::ArrowheadIntersects(Arrowhead*, BoxObj&&, Graphic*)"
122    test_demangling "gnu-v3: _Z13BitPatterntoaOK10BitPatternccc" \
123	"BitPatterntoa\[(\]+(const BitPattern|BitPattern const)&&, char, char, char\[)\]+"
124    test_demangling_exact "gnu-v3: _ZN8TextCode14CoreConstDeclsEO7ostream" "TextCode::CoreConstDecls(ostream&&)"
125    test_demangling "gnu-v3: _Z31DrawDestinationTransformedImageP7_XImageiiS0_iimjiijmmP4_XGCOK13ivTransformeriiii" \
126	"DrawDestinationTransformedImage\[(\]+_XImage\[*\]+, int, int, _XImage\[*\]+, int, int, unsigned long, unsigned int, int, int, unsigned int, unsigned long, unsigned long, _XGC\[*\]+, (const ivTransformer|ivTransformer const)&&, int, int, int, int\[)\]+"
127    test_demangling_exact "gnu-v3: _ZN11RelateManip6EffectEO7ivEvent" "RelateManip::Effect(ivEvent&&)"
128    test_demangling_exact "gnu-v3: _ZN20DisplayList_IteratorC4EO11DisplayList" "DisplayList_Iterator::DisplayList_Iterator(DisplayList&&)"
129    test_demangling_exact "gnu-v3: _ZN3fooC4EOS_" "foo::foo(foo&&)"
130    test_demangling_exact "gnu-v3: _ZN3fooC4EiOS_iS0_iS0_" "foo::foo(int, foo&&, int, foo&&, int, foo&&)"
131    test_demangling "gnu-v3: _ZN7ivWorldC2EPKcOiPPcPK12ivOptionDescPK14ivPropertyData" \
132	"ivWorld::ivWorld\[(\]+(const char|char const)\[*\]+, int&&, char\[*\]+\[*\]+, (const ivOptionDesc|ivOptionDesc const)\[*\]+, (const ivPropertyData|ivPropertyData const)\[*\]+\[)\]+"
133    test_demangling "gnu-v3: _Z3argOK7Complex" \
134	"arg\[(\]+(const Complex|Complex const)&&\[)\]+"
135    test_demangling "gnu-v3: _ZNK9BitString8containsEOK10BitPattern" \
136	"BitString::contains\[(\]+(const BitPattern|BitPattern const)&&\[)\]+ const"
137    test_demangling "gnu-v3: _ZNK9BitString8containsEOK12BitSubStringi" \
138	"BitString::contains\[(\]+(const BitSubString|BitSubString const)&&, int\[)\]+ const"
139    test_demangling "gnu-v3: _ZNK9BitString8containsEOKS_" \
140	"BitString::contains\[(\]+(const BitString|BitString const)&&\[)\]+ const"
141    test_demangling_exact "gnu-v3: _ZN4ListI10VHDLEntityE3PixC4EOKS2_" \
142	"List<VHDLEntity>::Pix::Pix(List<VHDLEntity>::Pix const&&)"
143    test_demangling_exact "gnu-v3: _ZN4ListI10VHDLEntityE7elementC2EOKS0_PS2_" \
144	"List<VHDLEntity>::element::element(VHDLEntity const&&, List<VHDLEntity>::element*)"
145    test_demangling_exact "gnu-v3: _ZN4ListI10VHDLEntityE7elementC4EOKS2_" \
146	"List<VHDLEntity>::element::element(List<VHDLEntity>::element const&&)"
147    test_demangling_exact "gnu-v3: _ZNK4ListI10VHDLEntityEclEOKNS1_3PixE" \
148	"List<VHDLEntity>::operator()(List<VHDLEntity>::Pix const&&) const"
149    test_demangling_exact "gnu-v3: _ZN4ListI10VHDLEntityEC4EOKS1_" \
150	"List<VHDLEntity>::List(List<VHDLEntity> const&&)"
151    test_demangling_exact "gnu-v3: _ZN4PixXI11VHDLLibrary14VHDLLibraryRep4ListI10VHDLEntityEEC2EOKS5_" \
152	"PixX<VHDLLibrary, VHDLLibraryRep, List<VHDLEntity> >::PixX(PixX<VHDLLibrary, VHDLLibraryRep, List<VHDLEntity> > const&&)"
153    test_demangling_exact "gnu-v3: _ZNK11VHDLLibrary5nextEEO4PixXIS_14VHDLLibraryRep4ListI10VHDLEntityEE" \
154	"VHDLLibrary::nextE(PixX<VHDLLibrary, VHDLLibraryRep, List<VHDLEntity> >&&) const"
155    test_demangling_exact "gnu-v3: _ZNK4ListI10VHDLEntityE4nextEONS1_3PixE" \
156	"List<VHDLEntity>::next(List<VHDLEntity>::Pix&&) const"
157}
158
159proc catch_demangling_errors {command} {
160    if {[catch $command result]} {
161	puts "ERROR: demangle.exp: while running $command: $result"
162    }
163}
164
165# Test support for different demangling styles.  Note that this does
166# not depend upon running the test program and does not depend upon
167# gdb being able to lookup any C++ symbols.  It simply calls the
168# internal demangler with synthesized strings and tests the results.
169
170proc do_tests {} {
171    global subdir
172    global gdb_prompt
173
174
175    # Start with a fresh gdb.
176
177    gdb_exit
178    gdb_start
179
180    gdb_test_no_output "set language c++"
181    gdb_test_no_output "set width 0"
182
183    # Using catch_demangling_errors this way ensures that, if one of
184    # the functions raises a Tcl error, then it'll get reported, and
185    # the rest of the functions will still run.
186    catch_demangling_errors test_gnuv3_style_demangling
187
188    # Verify specifying demangle language.
189    gdb_test_no_output "set language unknown"
190    set_demangling_style "auto"
191    gdb_test_exact "demangle -l c++ -- _ZSt4cout" "std::cout"
192    gdb_test_exact "demangle -l c++ _ZSt4cout" "std::cout"
193    gdb_test_exact "demangle -l c -- _ZSt4cout" "Can't demangle \"_ZSt4cout\""
194    gdb_test_exact "demangle -l garbage xyzdje" "Unknown language \"garbage\""
195}
196
197do_tests
198