Avoid "text file busy" in dw2-using-debug-str.exp
[binutils-gdb.git] / gdb / testsuite / gdb.cp / exception.exp
blob5489d0cace4ae92cb17d650c59dfb5a536b100b2
1 # Copyright 1997-2024 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 set ws  "\[\r\n\t \]+"
31 set nl  "\[\r\n\]+"
33 require allow_stl_tests
35 standard_testfile .cc
37 if {[prepare_for_testing "failed to prepare" $testfile $srcfile {debug c++}]} {
38     return -1
41 # Set a catch catchpoint
43 gdb_test "catch catch" "Catchpoint \[0-9\]+ \\(catch\\)" \
44     "catch catch (before inferior run)"
46 # Set a throw catchpoint
48 gdb_test "catch throw" "Catchpoint \[0-9\]+ \\(throw\\)" \
49     "catch throw (before inferior run)"
51 # Set a rethrow catchpoint
53 gdb_test "catch rethrow" "Catchpoint \[0-9\]+ \\(rethrow\\)" \
54     "catch rethrow (before inferior run)"
57 set re_head     "Num${ws}Type${ws}Disp${ws}Enb${ws}Address${ws}What"
58 set re_2_bp     "1${ws}catchpoint${ws}keep${ws}y${ws}exception catch"
59 set re_3_bp     "2${ws}catchpoint${ws}keep${ws}y${ws}exception throw"
60 set re_4_bp     "3${ws}catchpoint${ws}keep${ws}y${ws}exception rethrow"
62 set name "info breakpoints (before inferior run)"
63 gdb_test_multiple "info breakpoints" $name {
64     -re "$re_head${ws}$re_2_bp${ws}$re_3_bp${ws}$re_4_bp\r\n$gdb_prompt $" {
65         pass $name
66     }
67     -re ".*$gdb_prompt $"
68       {
69         fail $name
70       }
73 gdb_test "tbreak -q main" "Temporary breakpoint 4.*" \
74     "Set temporary breakpoint at main"
76 set ok 0
77 gdb_run_cmd
78 gdb_test_multiple "" "run to main" {
79     -re "Temporary breakpoint 4,.*$gdb_prompt $" {
80         pass "run to main"
81         set ok 1
82     }
85 if { !$ok } {
86     return
89 set name "info breakpoints, after inferior run"
90 gdb_test_multiple "info breakpoints" $name {
91     -re "$re_head${ws}$re_2_bp${ws}$re_3_bp${ws}$re_4_bp\r\n$gdb_prompt $" {
92         pass $name
93     }
94     -re ".*$gdb_prompt $"
95       {
96         send_user "\n---\n$expect_out(buffer)\n---\n"
97         fail $name
98       }
101 gdb_test "break catcher" "Breakpoint \[0-9\]+ at.*"
103 # Get the first exception thrown
104        
105 gdb_test "continue"  \
106     "Continuing.${ws}Catchpoint \[0-9\]+ \\(exception thrown\\).*" \
107     "continue to first throw"
109 # Backtrace from the throw point.
110 # This should get to user code.
112 set name "backtrace after first throw"
113 gdb_test_multiple "backtrace" $name {
114     -re ".*#\[0-9\]+.*\[\[:<:\]\]__cxa_throw\[\[:>:\]\].*#\[0-9\]+${ws}$hex (\\\[PAC\\\] )?in foo \\(i=20\\) at .*${srcfile}:\[0-9\]+\r\n#\[0-9\]+${ws}$hex in main \\(.*\\) at .*${srcfile}:\[0-9\]+\r\n$gdb_prompt $" {
115         # Either __cxxabiv1::__cxa_throw or __cxa_throw can be printed
116         # depending on debug info presence.
117         pass $name
118     }
121 # Continue to the catch.
123 gdb_test "continue" \
124     "Continuing.${ws}Catchpoint \[0-9\]+ \\(exception caught\\).*" \
125     "continue to first catch"
127 # Backtrace from the catch point.
128 # This should get to user code.
130 set name "backtrace after first catch"
131 gdb_test_multiple "backtrace" $name {
132     -re ".*#\[0-9\]+.*\[\[:<:\]\]__cxa_begin_catch\[\[:>:\]\].*#\[0-9\]+${ws}$hex (\\\[PAC\\\] )?in main \\(.*\\) at .*$srcfile:\[0-9\]+\r\n$gdb_prompt $" {
133         pass $name
134     }
137 # Continue to breakpoint on catcher.
138 gdb_test "continue" ".*catcher \\(x=13\\).*" "continue to catcher for the first time"
140 # Continue to second throw.
142 gdb_test "continue" \
143     "Continuing.${ws}Catchpoint \[0-9\]+ \\(exception thrown\\).*" \
144     "continue to second throw"
146 # Backtrace from the throw point.
147 # This should get to user code.
149 set name "backtrace after second throw"
150 gdb_test_multiple "backtrace" $name {
151     -re ".*#\[0-9\]+.*\[\[:<:\]\]__cxa_throw\[\[:>:\]\].*#\[0-9\]+${ws}$hex (\\\[PAC\\\] )?in foo \\(i=20\\) at .*${srcfile}:\[0-9\]+\r\n#\[0-9\]+${ws}$hex in main \\(.*\\) at .*${srcfile}:\[0-9\]+\r\n$gdb_prompt $" {
152         pass $name
153     }
156 # Continue to second catch.
158 gdb_test "continue" \
159     "Continuing.${ws}Catchpoint \[0-9\]+ \\(exception caught\\).*" \
160     "continue to second catch"
162 # Backtrace from the catch point.
163 # This should get to user code.
165 set name "backtrace after second catch"
166 gdb_test_multiple "backtrace" $name {
167     -re ".*#\[0-9\]+.*\[\[:<:\]\]__cxa_begin_catch\[\[:>:\]\].*#\[0-9\]+${ws}$hex (\\\[PAC\\\] )?in main \\(.*\\) at .*$srcfile:\[0-9\]+\r\n$gdb_prompt $" {
168         pass $name
169     }
172 # Continue to breakpoint on catcher.
173 gdb_test "continue" ".*catcher \\(x=13\\).*" "continue to catcher for the second time"
176 # Continue to the re-throw.
178 gdb_test "continue" "Catchpoint \[0-9\]+.*exception rethrown.*" \
179     "continue to rethrow"