1 # Copyright 2013-2014 Free Software Foundation, Inc.
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.
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.
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/>.
16 # Test namespace aliases.
17 # PRs c++/7935, c++/10541
21 if {![dwarf2_support]} {
25 if {[skip_cplus_tests]} {
29 standard_testfile .cc nsalias-dw.S
31 # Make the DWARF used for the test. This is necessary to work
32 # around compiler issues. Not all versions of gcc output the
33 # correct debuginfo we need.
35 # This should create the equivalent DWARF to:
44 # int foo (void) { return x; }
47 # namespace Innermost = innermost;
50 # int foo (void) { return x + Innermost::foo (); }
53 # namespace Inner = inner;
56 # int foo (void) { return x + Inner::foo (); }
59 # namespace Outer = outer;
60 # namespace oi = Outer::Inner;
62 set asm_file [standard_output_file $srcfile2]
63 Dwarf::assemble $asm_file {
65 compile_unit {{language @DW_LANG_C_plus_plus}} {
66 declare_labels int_label outer_label inner_label innermost_label
67 declare_labels im_foo_label i_foo_label o_foo_label
68 declare_labels OuterInner_label oi1_label oi2_label
70 int_label: base_type {
72 {encoding @DW_ATE_signed}
73 {byte_size 4 DW_FORM_sdata}
76 outer_label: DW_TAG_namespace {
79 inner_label: DW_TAG_namespace {
82 innermost_label: DW_TAG_namespace {
88 {const_value 2 DW_FORM_data1}
91 im_foo_label: DW_TAG_subprogram {
98 imported_declaration {
100 {import :$innermost_label}
106 {const_value 1 DW_FORM_data1}
109 i_foo_label: subprogram {
116 OuterInner_label: imported_declaration {
118 {import :$inner_label}
124 {const_value 0 DW_FORM_data1}
127 o_foo_label: subprogram {
134 imported_declaration {
136 {import :$outer_label}
139 oi1_label: imported_declaration {
141 {import :$OuterInner_label}
144 oi2_label: imported_declaration {
149 imported_declaration {
155 {specification :$im_foo_label}
156 {low_pc 0x1 DW_FORM_addr}
157 {high_pc 0x2 DW_FORM_addr}
161 {specification :$i_foo_label}
162 {low_pc 0x3 DW_FORM_addr}
163 {high_pc 0x4 DW_FORM_addr}
167 {specification :$o_foo_label}
168 {low_pc 0x5 DW_FORM_addr}
169 {high_pc 0x6 DW_FORM_addr}
175 if {[gdb_compile $srcdir/$subdir/$srcfile ${binfile}1.o \
176 object {c++ debug}] != ""} {
180 if {[gdb_compile $asm_file ${binfile}2.o object {nodebug}] != ""} {
184 if {[gdb_compile [list ${binfile}1.o ${binfile}2.o] \
185 $binfile executable {c++}] != ""} {
189 clean_restart $testfile
191 # A procedure to run various tests on aliased namespaces.
192 proc do_alias_tests {ns {real ""} {x ""}} {
194 # The "real" namespace is simply NS in all lowercase.
196 set real [string tolower $ns]
199 # The value of `x' is the number of '::' in NS.
201 set x [expr {[llength [split $ns ":"]] / 2}]
205 gdb_test "whatis $ns" "type = $real"
208 gdb_test "ptype $ns" "type = namespace $real"
211 send_log "expecting x = $x\n"
212 gdb_test "print ${ns}::x" " = $x"
214 # Attempt to list the function.
215 gdb_test_no_output "list ${ns}::foo"
217 # Attempt to break on the start of the function.
218 gdb_breakpoint "*${ns}::foo"
221 with_test_prefix "($ns)" {
222 gdb_test_no_output "delete \$bpnum"
226 # This is a list of all the permutations to be tested. For troubleshooting
227 # purposes, this list is explicitly enumerated.
230 lappend permutations "outer"
231 lappend permutations "Outer"
232 lappend permutations "outer::inner"
233 lappend permutations "Outer::inner"
234 lappend permutations "outer::Inner"
235 lappend permutations "Outer::Inner"
236 lappend permutations "outer::inner::innermost"
237 lappend permutations "outer::inner::Innermost"
238 lappend permutations "outer::Inner::innermost"
239 lappend permutations "outer::Inner::Innermost"
240 lappend permutations "Outer::inner::innermost"
241 lappend permutations "Outer::inner::Innermost"
242 lappend permutations "Outer::Inner::innermost"
243 lappend permutations "Outer::Inner::Innermost"
245 foreach p $permutations {
249 # Test recursively imported aliases.
250 foreach ns {"oi1" "oi2" "oi3"} {
251 do_alias_tests $ns "outer::inner" 1
252 do_alias_tests "${ns}::innermost" "outer::inner::innermost" 2
253 do_alias_tests "${ns}::Innermost" "outer::inner::innermost" 2
256 # Generate another objfile with nested imported declarations.
259 declare_labels n0_label
261 n0_label: DW_TAG_namespace {
267 {const_value 3 DW_FORM_data1}
271 declare_labels n0_import
272 n0_import: imported_declaration {
278 for {set i 1} {$i <= 100} {incr i} {
279 append imports [format "
280 declare_labels n%d_import
281 n%d_import: imported_declaration {
283 {import :\$n%d_import}
284 }" $i $i $i [expr {$i - 1}]]
287 standard_testfile .cc nsalias-r-dw.S
289 set asm_file [standard_output_file $srcfile2]
290 set the_dwarf [format {
292 compile_unit {{language @DW_LANG_C_plus_plus}} {
293 declare_labels int_label n0_label
295 int_label: base_type {
297 {encoding @DW_ATE_signed}
298 {byte_size 4 DW_FORM_sdata}
306 Dwarf::assemble $asm_file $the_dwarf
308 if {[gdb_compile $asm_file ${binfile}3.o object {nodebug}] != ""} {
312 if {[gdb_compile [list ${binfile}1.o ${binfile}3.o] \
313 ${binfile}-r executable {c++}] != ""} {
317 clean_restart ${testfile}-r
319 gdb_test_no_output "set complaints 1"
320 gdb_test "print N100::x" \
321 ".* has too many recursively imported declarations.*" \
322 "compaint for too many recursively imported declarations"