1 1.3 christos # Copyright 2013-2015 Free Software Foundation, Inc. 2 1.1 christos 3 1.1 christos # This program is free software; you can redistribute it and/or modify 4 1.1 christos # it under the terms of the GNU General Public License as published by 5 1.1 christos # the Free Software Foundation; either version 3 of the License, or 6 1.1 christos # (at your option) any later version. 7 1.1 christos # 8 1.1 christos # This program is distributed in the hope that it will be useful, 9 1.1 christos # but WITHOUT ANY WARRANTY; without even the implied warranty of 10 1.1 christos # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 1.1 christos # GNU General Public License for more details. 12 1.1 christos # 13 1.1 christos # You should have received a copy of the GNU General Public License 14 1.1 christos # along with this program. If not, see <http://www.gnu.org/licenses/>. 15 1.1 christos 16 1.1 christos # Test namespace aliases. 17 1.1 christos # PRs c++/7935, c++/10541 18 1.1 christos 19 1.1 christos load_lib dwarf.exp 20 1.1 christos 21 1.1 christos if {![dwarf2_support]} { 22 1.1 christos return 0 23 1.1 christos } 24 1.1 christos 25 1.1 christos if {[skip_cplus_tests]} { 26 1.1 christos continue 27 1.1 christos } 28 1.1 christos 29 1.1 christos standard_testfile .cc nsalias-dw.S 30 1.1 christos 31 1.1 christos # Make the DWARF used for the test. This is necessary to work 32 1.1 christos # around compiler issues. Not all versions of gcc output the 33 1.1 christos # correct debuginfo we need. 34 1.1 christos # 35 1.1 christos # This should create the equivalent DWARF to: 36 1.1 christos # 37 1.1 christos # namespace outer 38 1.1 christos # { 39 1.1 christos # namespace inner 40 1.1 christos # { 41 1.1 christos # namespace innermost 42 1.1 christos # { 43 1.1 christos # const int x = 2; 44 1.1 christos # int foo (void) { return x; } 45 1.1 christos # } 46 1.1 christos # 47 1.1 christos # namespace Innermost = innermost; 48 1.1 christos # 49 1.1 christos # const int x = 1; 50 1.1 christos # int foo (void) { return x + Innermost::foo (); } 51 1.1 christos # } 52 1.1 christos # 53 1.1 christos # namespace Inner = inner; 54 1.1 christos # 55 1.1 christos # const int x = 0; 56 1.1 christos # int foo (void) { return x + Inner::foo (); } 57 1.1 christos # } 58 1.1 christos # 59 1.1 christos # namespace Outer = outer; 60 1.1 christos # namespace oi = Outer::Inner; 61 1.1 christos 62 1.1 christos set asm_file [standard_output_file $srcfile2] 63 1.1 christos Dwarf::assemble $asm_file { 64 1.1 christos cu {} { 65 1.1 christos compile_unit {{language @DW_LANG_C_plus_plus}} { 66 1.1 christos declare_labels int_label outer_label inner_label innermost_label 67 1.1 christos declare_labels im_foo_label i_foo_label o_foo_label 68 1.1 christos declare_labels OuterInner_label oi1_label oi2_label 69 1.1 christos 70 1.1 christos int_label: base_type { 71 1.1 christos {name int} 72 1.1 christos {encoding @DW_ATE_signed} 73 1.1 christos {byte_size 4 DW_FORM_sdata} 74 1.1 christos } 75 1.1 christos 76 1.1 christos outer_label: DW_TAG_namespace { 77 1.1 christos {name outer} 78 1.1 christos } { 79 1.1 christos inner_label: DW_TAG_namespace { 80 1.1 christos {name inner} 81 1.1 christos } { 82 1.1 christos innermost_label: DW_TAG_namespace { 83 1.1 christos {name innermost} 84 1.1 christos } { 85 1.1 christos DW_TAG_variable { 86 1.1 christos {name x} 87 1.1 christos {type :$int_label} 88 1.1 christos {const_value 2 DW_FORM_data1} 89 1.1 christos } 90 1.1 christos 91 1.1 christos im_foo_label: DW_TAG_subprogram { 92 1.1 christos {name foo} 93 1.3 christos {external 1 flag_present} 94 1.3 christos {declaration 1 flag_present} 95 1.1 christos } 96 1.1 christos } 97 1.1 christos 98 1.1 christos imported_declaration { 99 1.1 christos {name Innermost} 100 1.1 christos {import :$innermost_label} 101 1.1 christos } 102 1.1 christos 103 1.1 christos DW_TAG_variable { 104 1.1 christos {name x} 105 1.1 christos {type :$int_label} 106 1.1 christos {const_value 1 DW_FORM_data1} 107 1.1 christos } 108 1.1 christos 109 1.1 christos i_foo_label: subprogram { 110 1.1 christos {name foo} 111 1.3 christos {external 1 flag_present} 112 1.3 christos {declaration 1 flag_present} 113 1.1 christos } 114 1.1 christos } 115 1.1 christos 116 1.1 christos OuterInner_label: imported_declaration { 117 1.1 christos {name Inner} 118 1.1 christos {import :$inner_label} 119 1.1 christos } 120 1.1 christos 121 1.1 christos DW_TAG_variable { 122 1.1 christos {name x} 123 1.1 christos {type :$int_label} 124 1.1 christos {const_value 0 DW_FORM_data1} 125 1.1 christos } 126 1.1 christos 127 1.1 christos o_foo_label: subprogram { 128 1.1 christos {name foo} 129 1.3 christos {external 1 flag_present} 130 1.3 christos {declaration 1 flag_present} 131 1.1 christos } 132 1.1 christos } 133 1.1 christos 134 1.1 christos imported_declaration { 135 1.1 christos {name Outer} 136 1.1 christos {import :$outer_label} 137 1.1 christos } 138 1.1 christos 139 1.1 christos oi1_label: imported_declaration { 140 1.1 christos {name oi1} 141 1.1 christos {import :$OuterInner_label} 142 1.1 christos } 143 1.1 christos 144 1.1 christos oi2_label: imported_declaration { 145 1.1 christos {name oi2} 146 1.1 christos {import :$oi1_label} 147 1.1 christos } 148 1.1 christos 149 1.1 christos imported_declaration { 150 1.1 christos {name oi3} 151 1.1 christos {import :$oi2_label} 152 1.1 christos } 153 1.1 christos 154 1.1 christos subprogram { 155 1.1 christos {specification :$im_foo_label} 156 1.3 christos {low_pc 0x4 DW_FORM_addr} 157 1.3 christos {high_pc 0x7 DW_FORM_addr} 158 1.1 christos } 159 1.1 christos 160 1.1 christos subprogram { 161 1.1 christos {specification :$i_foo_label} 162 1.3 christos {low_pc 0x8 DW_FORM_addr} 163 1.3 christos {high_pc 0xb DW_FORM_addr} 164 1.1 christos } 165 1.1 christos 166 1.1 christos subprogram { 167 1.1 christos {specification :$o_foo_label} 168 1.3 christos {low_pc 0xc DW_FORM_addr} 169 1.3 christos {high_pc 0xf DW_FORM_addr} 170 1.1 christos } 171 1.1 christos } 172 1.1 christos } 173 1.1 christos } 174 1.1 christos 175 1.1 christos if {[gdb_compile $srcdir/$subdir/$srcfile ${binfile}1.o \ 176 1.1 christos object {c++ debug}] != ""} { 177 1.1 christos return -1 178 1.1 christos } 179 1.1 christos 180 1.1 christos if {[gdb_compile $asm_file ${binfile}2.o object {nodebug}] != ""} { 181 1.1 christos return -1 182 1.1 christos } 183 1.1 christos 184 1.1 christos if {[gdb_compile [list ${binfile}1.o ${binfile}2.o] \ 185 1.1 christos $binfile executable {c++}] != ""} { 186 1.1 christos return -1 187 1.1 christos } 188 1.1 christos 189 1.1 christos clean_restart $testfile 190 1.1 christos 191 1.1 christos # A procedure to run various tests on aliased namespaces. 192 1.1 christos proc do_alias_tests {ns {real ""} {x ""}} { 193 1.1 christos 194 1.1 christos # The "real" namespace is simply NS in all lowercase. 195 1.1 christos if {$real == ""} { 196 1.1 christos set real [string tolower $ns] 197 1.1 christos } 198 1.1 christos 199 1.1 christos # The value of `x' is the number of '::' in NS. 200 1.1 christos if {$x == ""} { 201 1.1 christos set x [expr {[llength [split $ns ":"]] / 2}] 202 1.1 christos } 203 1.1 christos 204 1.1 christos # Test "whatis" 205 1.1 christos gdb_test "whatis $ns" "type = $real" 206 1.1 christos 207 1.1 christos # Test "ptype" 208 1.1 christos gdb_test "ptype $ns" "type = namespace $real" 209 1.1 christos 210 1.1 christos # Print 'x' 211 1.1 christos send_log "expecting x = $x\n" 212 1.1 christos gdb_test "print ${ns}::x" " = $x" 213 1.1 christos 214 1.1 christos # Attempt to list the function. 215 1.1 christos gdb_test_no_output "list ${ns}::foo" 216 1.1 christos 217 1.1 christos # Attempt to break on the start of the function. 218 1.1 christos gdb_breakpoint "*${ns}::foo" 219 1.1 christos 220 1.1 christos # And then erase it 221 1.1 christos with_test_prefix "($ns)" { 222 1.1 christos gdb_test_no_output "delete \$bpnum" 223 1.1 christos } 224 1.1 christos } 225 1.1 christos 226 1.1 christos # This is a list of all the permutations to be tested. For troubleshooting 227 1.1 christos # purposes, this list is explicitly enumerated. 228 1.1 christos 229 1.1 christos set permutations {} 230 1.1 christos lappend permutations "outer" 231 1.1 christos lappend permutations "Outer" 232 1.1 christos lappend permutations "outer::inner" 233 1.1 christos lappend permutations "Outer::inner" 234 1.1 christos lappend permutations "outer::Inner" 235 1.1 christos lappend permutations "Outer::Inner" 236 1.1 christos lappend permutations "outer::inner::innermost" 237 1.1 christos lappend permutations "outer::inner::Innermost" 238 1.1 christos lappend permutations "outer::Inner::innermost" 239 1.1 christos lappend permutations "outer::Inner::Innermost" 240 1.1 christos lappend permutations "Outer::inner::innermost" 241 1.1 christos lappend permutations "Outer::inner::Innermost" 242 1.1 christos lappend permutations "Outer::Inner::innermost" 243 1.1 christos lappend permutations "Outer::Inner::Innermost" 244 1.1 christos 245 1.1 christos foreach p $permutations { 246 1.1 christos do_alias_tests $p 247 1.1 christos } 248 1.1 christos 249 1.1 christos # Test recursively imported aliases. 250 1.1 christos foreach ns {"oi1" "oi2" "oi3"} { 251 1.1 christos do_alias_tests $ns "outer::inner" 1 252 1.1 christos do_alias_tests "${ns}::innermost" "outer::inner::innermost" 2 253 1.1 christos do_alias_tests "${ns}::Innermost" "outer::inner::innermost" 2 254 1.1 christos } 255 1.1 christos 256 1.1 christos # Generate another objfile with nested imported declarations. 257 1.1 christos 258 1.1 christos set imports { 259 1.1 christos declare_labels n0_label 260 1.1 christos 261 1.1 christos n0_label: DW_TAG_namespace { 262 1.1 christos {name n0} 263 1.1 christos } { 264 1.1 christos DW_TAG_variable { 265 1.1 christos {name x} 266 1.1 christos {type :$int_label} 267 1.1 christos {const_value 3 DW_FORM_data1} 268 1.1 christos } 269 1.1 christos } 270 1.1 christos 271 1.1 christos declare_labels n0_import 272 1.1 christos n0_import: imported_declaration { 273 1.1 christos {name N0} 274 1.1 christos {import :$n0_label} 275 1.1 christos } 276 1.1 christos } 277 1.1 christos 278 1.1 christos for {set i 1} {$i <= 100} {incr i} { 279 1.1 christos append imports [format " 280 1.1 christos declare_labels n%d_import 281 1.1 christos n%d_import: imported_declaration { 282 1.1 christos {name N%d} 283 1.1 christos {import :\$n%d_import} 284 1.1 christos }" $i $i $i [expr {$i - 1}]] 285 1.1 christos } 286 1.1 christos 287 1.1 christos standard_testfile .cc nsalias-r-dw.S 288 1.1 christos 289 1.1 christos set asm_file [standard_output_file $srcfile2] 290 1.1 christos set the_dwarf [format { 291 1.1 christos cu {} { 292 1.1 christos compile_unit {{language @DW_LANG_C_plus_plus}} { 293 1.1 christos declare_labels int_label n0_label 294 1.1 christos 295 1.1 christos int_label: base_type { 296 1.1 christos {name int} 297 1.1 christos {encoding @DW_ATE_signed} 298 1.1 christos {byte_size 4 DW_FORM_sdata} 299 1.1 christos } 300 1.1 christos 301 1.1 christos %s 302 1.1 christos } 303 1.1 christos } 304 1.1 christos } $imports] 305 1.1 christos 306 1.1 christos Dwarf::assemble $asm_file $the_dwarf 307 1.1 christos 308 1.1 christos if {[gdb_compile $asm_file ${binfile}3.o object {nodebug}] != ""} { 309 1.1 christos return -1 310 1.1 christos } 311 1.1 christos 312 1.1 christos if {[gdb_compile [list ${binfile}1.o ${binfile}3.o] \ 313 1.1 christos ${binfile}-r executable {c++}] != ""} { 314 1.1 christos return -1 315 1.1 christos } 316 1.1 christos 317 1.1 christos clean_restart ${testfile}-r 318 1.1 christos 319 1.1 christos gdb_test_no_output "set complaints 1" 320 1.1 christos gdb_test "print N100::x" \ 321 1.1 christos ".* has too many recursively imported declarations.*" \ 322 1.1 christos "compaint for too many recursively imported declarations" 323