1# Copyright 1997, 1998, 2004 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 2 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, write to the Free Software 15# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 16 17# This file is part of the gdb testsuite. 18# tests for exception-handling support 19# Written by Satish Pai <pai@apollo.hp.com> 1997-07-23 20# Rewritten by Michael Chastain <mec.gnu@mindspring.com> 2004-01-08 21 22# This file used to have two copies of the tests with different 23# compiler flags for hp-ux. Instead, the user should set CXXOPTS 24# or run runtest with --target_board unix/gdb:debug_flags="..." 25# to choose the compiler flags. 26# 27# The interesting compiler flags are: "aCC +A -Wl,-a,-archive" . 28# Static-linked executables use a different mechanism to get the 29# address of the notification hook in the C++ support library. 30 31# TODO: this file is not ready for production yet. If you are working 32# on C++ exception support for gdb, you can take out the "continue" 33# statement and try your luck. -- chastain 2004-01-09 34 35# TODO: this file has many absolute line numbers. 36# Replace them with gdb_get_line_number. 37 38set ws "\[\r\n\t \]+" 39set nl "\[\r\n\]+" 40 41if $tracelevel then { 42 strace $tracelevel 43} 44 45set testfile "exception" 46set srcfile ${testfile}.cc 47set binfile ${objdir}/${subdir}/${testfile} 48 49if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug c++}] != "" } { 50 gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail." 51} 52 53# Start with a fresh gdb 54 55set prms_id 0 56set bug_id 0 57 58gdb_exit 59gdb_start 60gdb_reinitialize_dir $srcdir/$subdir 61gdb_load ${binfile} 62 63if ![runto_main] then { 64 perror "couldn't run to breakpoint" 65 continue 66} 67 68# As I said before, this test script is not ready yet! 69 70continue 71 72# Set a catch catchpoint 73 74gdb_test "catch catch" "Catchpoint \[0-9\]+ \\(catch\\)" 75 76# Set a throw catchpoint 77 78gdb_test "catch throw" "Catchpoint \[0-9\]+ \\(throw\\)" \ 79 "catch throw (static executable)" 80 81# The catchpoints should be listed in the list of breakpoints. 82 83set re_head "Num${ws}Type${ws}Disp${ws}Enb${ws}Address${ws}What" 84set re_1_main "1${ws}breakpoint${ws}keep${ws}y${ws}$hex${ws}in main.*breakpoint already hit.*" 85set re_2_catch "2${ws}catch catch${ws}keep${ws}y${ws}$hex${ws}exception catch" 86set re_3_catch "3${ws}catch throw${ws}keep${ws}y${ws}$hex${ws}exception throw" 87set re_2_bp "2${ws}breakpoint${ws}keep${ws}y${ws}$hex${ws}exception catch" 88set re_3_bp "3${ws}breakpoint${ws}keep${ws}y${ws}$hex${ws}exception throw" 89 90set name "info breakpoints" 91gdb_test_multiple "info breakpoints" $name { 92 -re "$re_head${ws}$re_1_main${ws}$re_2_catch${ws}$re_3_catch\r\n$gdb_prompt $" { 93 pass $name 94 } 95 -re "$re_head${ws}$re_1_main${ws}$re_2_bp${ws}$re_3_bp\r\n$gdb_prompt $" { 96 # TODO: gdb HEAD 2004-01-08 does this. Is this okay? 97 unresolved $name 98 } 99} 100 101# Some targets support "info catch". 102# Some do not. 103 104set name "info catch" 105gdb_test_multiple "info catch" $name { 106 -re "Info catch not supported with this target/compiler combination.\r\n$gdb_prompt $" { 107 unsupported $name 108 } 109 -re "No catches.\r\n$gdb_prompt $" { 110 # TODO: gdb HEAD 2004-01-08 does this. Is this okay? 111 unresolved $name 112 } 113} 114 115# Get the first exception thrown 116 117set name "continue to first throw" 118gdb_test_multiple "continue" $name { 119 -re "Continuing.${ws}Catchpoint \[0-9\]+ \\(exception thrown\\), throw location.*${srcfile}:30, catch location .*${srcfile}:50\r\n$gdb_prompt $" { 120 pass $name 121 } 122 -re "Continuing.${ws}Catchpoint \[0-9\]+ \\(exception thrown\\)\r\n.*\r\n$gdb_prompt $" { 123 # TODO: gdb HEAD 2004-01-08 does this. Is this okay? 124 unresolved $name 125 } 126} 127 128# Backtrace from the throw point. 129# This should get to user code. 130 131set name "backtrace after first throw" 132gdb_test_multiple "backtrace" $name { 133 -re ".*#\[0-9\]+${ws}$hex in foo \\(i=20\\) at .*${srcfile}:30\r\n#\[0-9\]+${ws}$hex in main \\((void|)\\) at .*${srcfile}:48\r\n$gdb_prompt $" { 134 pass $name 135 } 136} 137 138# Continue to the catch. 139 140set name "continue to first catch" 141gdb_test_multiple "continue" $name { 142 -re "Continuing.${ws}Catchpoint \[0-9\]+ \\(exception caught\\), throw location.*${srcfile}:30, catch location .*${srcfile}:50\r\n$gdb_prompt $" { 143 pass $name 144 } 145 -re "Continuing.${ws}Catchpoint \[0-9\]+ \\(exception caught\\)\r\n.*\r\n$gdb_prompt $" { 146 # TODO: gdb HEAD 2004-01-08 does this. Is this okay? 147 unresolved $name 148 } 149} 150 151# Backtrace from the catch point. 152# This should get to user code. 153 154set name "backtrace after first catch" 155gdb_test_multiple "backtrace" $name { 156 -re ".*#\[0-9\]+${ws}$hex in main \\((void|)\\) at .*$srcfile:50\r\n$gdb_prompt $" { 157 pass $name 158 } 159} 160 161# Continue to second throw. 162 163set name "continue to second throw" 164gdb_test_multiple "continue" $name { 165 -re "Continuing.${ws}Got an except 13${ws}Catchpoint \[0-9\]+ \\(exception thrown\\), throw location.*${srcfile}:30, catch location .*${srcfile}:58\r\n$gdb_prompt $" { 166 pass $name 167 } 168 -re "Continuing.${ws}Got an except 13${ws}Catchpoint \[0-9\]+ \\(exception thrown\\)\r\n.*\r\n$gdb_prompt $" { 169 # TODO: gdb HEAD 2004-01-08 does this. Is this okay? 170 unresolved $name 171 } 172} 173 174# Backtrace from the throw point. 175# This should get to user code. 176 177set name "backtrace after second throw" 178gdb_test_multiple "backtrace" $name { 179 -re ".*#\[0-9\]+${ws}$hex in foo \\(i=20\\) at .*${srcfile}:30\r\n#\[0-9\]+${ws}$hex in main \\((void|)\\) at .*${srcfile}:56\r\n$gdb_prompt $" { 180 pass $name 181 } 182} 183 184# Continue to second catch. 185 186set name "continue to second catch" 187gdb_test_multiple "continue" $name { 188 -re "Continuing.${ws}Catchpoint \[0-9\]+ \\(exception caught\\), throw location.*${srcfile}:30, catch location .*${srcfile}:58\r\n$gdb_prompt $" { 189 pass $name 190 } 191 -re "Continuing.${ws}Catchpoint \[0-9\]+ \\(exception caught\\)\r\n.*\r\n$gdb_prompt $" { 192 # TODO: gdb HEAD 2004-01-08 does this. Is this okay? 193 unresolved $name 194 } 195} 196 197# Backtrace from the catch point. 198# This should get to user code. 199 200set name "backtrace after second catch" 201gdb_test_multiple "backtrace" $name { 202 -re ".*#\[0-9\]+${ws}$hex in main \\((void|)\\) at .*$srcfile:58\r\n$gdb_prompt $" { 203 pass $name 204 } 205} 206 207# That is all for now. 208# 209# The original code had: 210# 211# continue to re-throw ; backtrace 212# continue to catch ; backtrace 213# continue to throw out of main 214# 215# The problem is that "re-throw" does not show a throw; only a catch. 216# I do not know if this is because of a bug, or because the generated 217# code is optimized for a throw into the same function. 218# 219# -- chastain 2004-01-09 220