1# Copyright 2011-2023 Free Software Foundation, Inc. 2# 3# Contributed by Red Hat, originally written by Keith Seitz. 4# 5# This program is free software; you can redistribute it and/or modify 6# it under the terms of the GNU General Public License as published by 7# the Free Software Foundation; either version 3 of the License, or 8# (at your option) any later version. 9# 10# This program is distributed in the hope that it will be useful, 11# but WITHOUT ANY WARRANTY; without even the implied warranty of 12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13# GNU General Public License for more details. 14# 15# You should have received a copy of the GNU General Public License 16# along with this program. If not, see <http://www.gnu.org/licenses/>. 17 18# This file is part of the gdb testsuite. 19 20# A helper proc which sets a breakpoint at FUNC and attempts to 21# run to the breakpoint. 22proc test_breakpoint {func result} { 23 set DEC {[0-9]} 24 25 # Return to the top of the test function every time. 26 delete_breakpoints 27 if {![gdb_breakpoint test_function]} { 28 fail "set test_function breakpoint for $func" 29 } elseif {[gdb_test "continue" \ 30 "Continuing.\r\n\r\nBreakpoint $DEC+,.*test_function.*" \ 31 "continue to test_function for $func"] != 0} { 32 } else { 33 gdb_breakpoint "$func" 34 gdb_test "continue" \ 35 "Continuing.\r\n\r\nBreakpoint $DEC+,.*$result.*" \ 36 "continue to $func" 37 } 38} 39 40if {[skip_cplus_tests]} { return } 41 42# Tests for c++/12750 43standard_testfile .cc 44 45if {[prepare_for_testing "failed to prepare" $testfile $srcfile {c++ debug}]} { 46 return -1 47} 48 49# The GDB workaround for GCC PR debug/45682 does not apply as it requires 50# DW_AT_linkage_name of methods. The whole class A is in anonymous namespace, 51# therefore not accessible outside of the CU (compilation unit) and therefore 52# GCC does not produce DW_AT_linkage_name for such methods. 53 54set have_gcc_45682_fixed 1 55set test "info addr A::func()" 56gdb_test_multiple $test $test { 57 -re "No symbol \"A::func\\(\\)\" in current context\\.\r\n$gdb_prompt $" { 58 pass $test 59 } 60 -re "Symbol \"A::func\\(\\)\" is a function at address .*\r\n$gdb_prompt $" { 61 setup_xfail gcc/45682 "*-*-*" 62 fail $test 63 set have_gcc_45682_fixed 0 64 } 65} 66 67if {![runto_main]} { 68 return 69} 70 71set ans {(anonymous namespace)} 72set methods {} 73lappend methods "xxx::${ans}::func" 74lappend methods "xxx::${ans}::A::func" 75 76gdb_test_no_output "set listsize 1" "" 77 78foreach test $methods { 79 # The result we expect is the source code name of the symbol, 80 # i.e., without "(anonymous namespace)". 81 regsub -all [string_to_regexp "${ans}::"] $test "" expected 82 set result ".*// [string_to_regexp $expected]" 83 84 # Test whether the function/method can be "list"ed 85 # with the filename pre-pended. 86 if {[string compare $test "xxx::${ans}::A::func"] == 0 87 && !$have_gcc_45682_fixed} { 88 setup_xfail gcc/45682 "*-*-*" 89 } 90 gdb_test "list ${srcfile}:$test" $result 91 if {[string compare $test "xxx::${ans}::A::func"] == 0 92 && !$have_gcc_45682_fixed} { 93 setup_xfail gcc/45682 "*-*-*" 94 } 95 gdb_test "list '${srcfile}:$test'" $result 96 if {[string compare $test "xxx::${ans}::A::func"] == 0 97 && !$have_gcc_45682_fixed} { 98 setup_xfail gcc/45682 "*-*-*" 99 } 100 gdb_test "list '${srcfile}':'$test'" $result 101 if {[string compare $test "xxx::${ans}::A::func"] == 0 102 && !$have_gcc_45682_fixed} { 103 setup_xfail gcc/45682 "*-*-*" 104 } 105 gdb_test "list ${srcfile}:'$test'" $result 106 107 # Test setting and hitting a breakoint at the function/method. 108 test_breakpoint $test $expected 109 test_breakpoint "'$test'" $expected 110} 111 112gdb_exit 113return 0 114