1# Copyright 2019-2023 Free Software Foundation, Inc. 2# This program is free software; you can redistribute it and/or modify 3# it under the terms of the GNU General Public License as published by 4# the Free Software Foundation; either version 3 of the License, or 5# (at your option) any later version. 6# 7# This program is distributed in the hope that it will be useful, 8# but WITHOUT ANY WARRANTY; without even the implied warranty of 9# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10# GNU General Public License for more details. 11# 12# You should have received a copy of the GNU General Public License 13# along with this program. If not, see <http://www.gnu.org/licenses/>. 14 15# Regression test for a GDB internal error that would trigger if a 16# "catch catch" catchpoint ended up with multiple locations. This 17# testcase exercises that scenario by building the binary with 18# -static-libgcc/-static-libstdc++ and a shared library that depends 19# on the libstc++.so DSO (which is how GDB was built and revealed the 20# bug), and vice versa. 21 22if {[skip_shlib_tests]} { 23 return 0 24} 25 26# STATIC_BIN indicates whether to build the main binary with 27# -static-libgcc/-static-libstdc++. STATIC_LIB is the same, but for 28# the shared library. 29proc test_multi_libstdcpp {static_bin static_lib} { 30 global srcdir subdir 31 global decimal hex 32 33 # Library file. 34 set libname "except-multi-location-lib" 35 set srcfile_lib ${srcdir}/${subdir}/${libname}.cc 36 set binfile_lib [standard_output_file ${libname}-$static_bin-$static_lib.so] 37 set lib_flags {debug c++} 38 if {$static_lib} { 39 lappend lib_flags additional_flags=-static-libgcc additional_flags=-static-libstdc++ 40 } 41 42 # Binary file. 43 set testfile "except-multi-location-main" 44 set srcfile ${srcdir}/${subdir}/${testfile}.cc 45 set binfile [standard_output_file ${testfile}-$static_bin-$static_lib] 46 set bin_flags [list debug c++ shlib=${binfile_lib}] 47 if {$static_bin} { 48 lappend bin_flags additional_flags=-static-libgcc additional_flags=-static-libstdc++ 49 } 50 51 if { [gdb_compile_shlib ${srcfile_lib} ${binfile_lib} $lib_flags] != "" 52 || [gdb_compile ${srcfile} ${binfile} executable $bin_flags] != "" } { 53 untested "failed to compile" 54 return -1 55 } 56 57 clean_restart 58 59 gdb_load ${binfile} 60 gdb_load_shlib $binfile_lib 61 62 if ![runto_main] { 63 return 0 64 } 65 66 gdb_test "catch catch" "Catchpoint \[0-9\]+ \\(catch\\)" 67 gdb_test "catch throw" "Catchpoint \[0-9\]+ \\(throw\\)" 68 gdb_test "catch rethrow" "Catchpoint \[0-9\]+ \\(rethrow\\)" 69 70 set ws "\[ \t\]*" 71 gdb_test "info breakpoints" \ 72 [multi_line \ 73 "${decimal}${ws}catchpoint${ws}keep${ws}y${ws}exception catch" \ 74 "${decimal}${ws}catchpoint${ws}keep${ws}y${ws}exception throw" \ 75 "${decimal}${ws}catchpoint${ws}keep${ws}y${ws}exception rethrow"] 76} 77 78# Try different static/not-static combinations. 79foreach_with_prefix static_lib {"0" "1"} { 80 foreach_with_prefix static_bin {"0" "1"} { 81 test_multi_libstdcpp $static_lib $static_bin 82 } 83} 84