1 # Copyright 1997-2019 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 # This file is part of the gdb testsuite.
17 # tests for exception-handling support
18 # Written by Satish Pai <pai@apollo.hp.com> 1997-07-23
19 # Rewritten by Michael Chastain <mec.gnu@mindspring.com> 2004-01-08
21 # This file used to have two copies of the tests with different
22 # compiler flags for hp-ux. Instead, the user should set CXXOPTS
23 # or run runtest with --target_board unix/gdb:debug_flags="..."
24 # to choose the compiler flags.
26 # The interesting compiler flags are: "aCC +A -Wl,-a,-archive" .
27 # Static-linked executables use a different mechanism to get the
28 # address of the notification hook in the C++ support library.
30 # TODO: this file has many absolute line numbers.
31 # Replace them with gdb_get_line_number.
36 if { [skip_stl_tests] } { continue }
38 # On SPU this test fails because the executable exceeds local storage size.
39 if { [istarget "spu*-*-*"] } {
45 if {[prepare_for_testing "failed to prepare" $testfile $srcfile {debug c++}]} {
49 # Set a catch catchpoint
51 gdb_test "catch catch" "Catchpoint \[0-9\]+ \\(catch\\)" \
52 "catch catch (before inferior run)"
54 # Set a throw catchpoint
56 gdb_test "catch throw" "Catchpoint \[0-9\]+ \\(throw\\)" \
57 "catch throw (before inferior run)"
59 # Set a rethrow catchpoint
61 gdb_test "catch rethrow" "Catchpoint \[0-9\]+ \\(rethrow\\)" \
62 "catch rethrow (before inferior run)"
65 set re_head "Num${ws}Type${ws}Disp${ws}Enb${ws}Address${ws}What"
66 set re_2_bp "1${ws}catchpoint${ws}keep${ws}y${ws}exception catch"
67 set re_3_bp "2${ws}catchpoint${ws}keep${ws}y${ws}exception throw"
68 set re_4_bp "3${ws}catchpoint${ws}keep${ws}y${ws}exception rethrow"
70 set name "info breakpoints (before inferior run)"
71 gdb_test_multiple "info breakpoints" $name {
72 -re "$re_head${ws}$re_2_bp${ws}$re_3_bp${ws}$re_4_bp\r\n$gdb_prompt $" {
81 gdb_test "tbreak main" "Temporary breakpoint 4.*" \
82 "Set temporary breakpoint at main"
86 gdb_test_multiple "" "run to main" {
87 -re "Temporary breakpoint 4,.*$gdb_prompt $" {
97 set name "info breakpoints (after inferior run)"
98 gdb_test_multiple "info breakpoints" $name {
99 -re "$re_head${ws}$re_2_bp${ws}$re_3_bp${ws}$re_4_bp\r\n$gdb_prompt $" {
102 -re ".*$gdb_prompt $"
104 send_user "\n---\n$expect_out(buffer)\n---\n"
109 gdb_test "break catcher" "Breakpoint \[0-9\]+ at.*"
111 # Get the first exception thrown
113 set name "continue to first throw"
114 gdb_test_multiple "continue" $name {
115 -re "Continuing.${ws}Catchpoint \[0-9\]+ \\(exception thrown\\), throw location.*${srcfile}:30, catch location .*${srcfile}:50\r\n$gdb_prompt $" {
118 -re "Continuing.${ws}Catchpoint \[0-9\]+ \\(exception thrown\\).*\r\n$gdb_prompt $" {
123 # Backtrace from the throw point.
124 # This should get to user code.
126 set name "backtrace after first throw"
127 gdb_test_multiple "backtrace" $name {
128 -re ".*#\[0-9\]+.*\[\[:<:\]\]__cxa_throw\[\[:>:\]\].*#\[0-9\]+${ws}$hex in foo \\(i=20\\) at .*${srcfile}:\[0-9\]+\r\n#\[0-9\]+${ws}$hex in main \\(.*\\) at .*${srcfile}:\[0-9\]+\r\n$gdb_prompt $" {
129 # Either __cxxabiv1::__cxa_throw or __cxa_throw can be printed
130 # depending on debug info presence.
135 # Continue to the catch.
137 set name "continue to first catch"
138 gdb_test_multiple "continue" $name {
139 -re "Continuing.${ws}Catchpoint \[0-9\]+ \\(exception caught\\), throw location.*${srcfile}:30, catch location .*${srcfile}:50\r\n$gdb_prompt $" {
142 -re "Continuing.${ws}Catchpoint \[0-9\]+ \\(exception caught\\).*\r\n$gdb_prompt $" {
147 # Backtrace from the catch point.
148 # This should get to user code.
150 set name "backtrace after first catch"
151 gdb_test_multiple "backtrace" $name {
152 -re ".*#\[0-9\]+.*\[\[:<:\]\]__cxa_begin_catch\[\[:>:\]\].*#\[0-9\]+${ws}$hex in main \\(.*\\) at .*$srcfile:\[0-9\]+\r\n$gdb_prompt $" {
157 # Continue to breakpoint on catcher.
158 gdb_test "continue" ".*catcher \\(x=13\\).*" "continue to catcher for the first time"
160 # Continue to second throw.
162 set name "continue to second throw"
163 gdb_test_multiple "continue" $name {
164 -re "Continuing.${ws}Catchpoint \[0-9\]+ \\(exception thrown\\), throw location.*${srcfile}:30, catch location .*${srcfile}:58\r\n$gdb_prompt $" {
167 -re "Continuing.${ws}Catchpoint \[0-9\]+ \\(exception thrown\\).*\r\n$gdb_prompt $" {
172 # Backtrace from the throw point.
173 # This should get to user code.
175 set name "backtrace after second throw"
176 gdb_test_multiple "backtrace" $name {
177 -re ".*#\[0-9\]+.*\[\[:<:\]\]__cxa_throw\[\[:>:\]\].*#\[0-9\]+${ws}$hex in foo \\(i=20\\) at .*${srcfile}:\[0-9\]+\r\n#\[0-9\]+${ws}$hex in main \\(.*\\) at .*${srcfile}:\[0-9\]+\r\n$gdb_prompt $" {
182 # Continue to second catch.
184 set name "continue to second catch"
185 gdb_test_multiple "continue" $name {
186 -re "Continuing.${ws}Catchpoint \[0-9\]+ \\(exception caught\\), throw location.*${srcfile}:30, catch location .*${srcfile}:58\r\n$gdb_prompt $" {
189 -re "Continuing.${ws}Catchpoint \[0-9\]+ \\(exception caught\\).*\r\n$gdb_prompt $" {
194 # Backtrace from the catch point.
195 # This should get to user code.
197 set name "backtrace after second catch"
198 gdb_test_multiple "backtrace" $name {
199 -re ".*#\[0-9\]+.*\[\[:<:\]\]__cxa_begin_catch\[\[:>:\]\].*#\[0-9\]+${ws}$hex in main \\(.*\\) at .*$srcfile:\[0-9\]+\r\n$gdb_prompt $" {
204 # Continue to breakpoint on catcher.
205 gdb_test "continue" ".*catcher \\(x=13\\).*" "continue to catcher for the second time"
208 # Continue to the re-throw.
210 gdb_test "continue" "Catchpoint \[0-9\]+.*exception rethrown.*" \
211 "continue to rethrow"