📄 exception.exp
字号:
# Copyright (C) 1997, 1998 Free Software Foundation, Inc.# This program is free software; you can redistribute it and/or modify# it under the terms of the GNU General Public License as published by# the Free Software Foundation; either version 2 of the License, or# (at your option) any later version.# # This program is distributed in the hope that it will be useful,# but WITHOUT ANY WARRANTY; without even the implied warranty of# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the# GNU General Public License for more details.# # You should have received a copy of the GNU General Public License# along with this program; if not, write to the Free Software# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. # Please email any bugs, comments, and/or additions to this file to:# bug-gdb@prep.ai.mit.edu## tests for exception-handling support# Written by Satish Pai <pai@apollo.hp.com> 1997-07-23# This file is part of the gdb testsuite# Note: These tests are geared to the HP aCC compiler,# which has an idiosyncratic way of emitting debug info# for exceptions -- it uses a callback mechanism, which# is different from the way g++ records exception info# for debugging# The tests are in two parts; the first part deals with# statically linked (archive-bound) executables, and the# second part repeats those tests with dynamically linked# (shared bound) executables. (In the latter case we use# a different mechanism to get the address of the notification# hook in the C++ support library.) The tests themselves are# the same in both parts.# # IMPORTANT:# ---------# IF YOU CHANGE A TEST IN ONE PART MAKE SURE YOU CHANGE IT# --------------------------------------------------------# IN THE OTHER PART TOO!# ----------------------if $tracelevel then { strace $tracelevel }if { [skip_hp_tests] } then { continue }## test running programs## Part I : Archive-bound executables# ----------------------------------set testfile "exception"set srcfile ${testfile}.ccset binfile ${objdir}/${subdir}/${testfile} if [get_compiler_info ${binfile} "c++"] { return -1;} if { $gcc_compiled } then { continue }set cmdline "$CXX_FOR_TARGET ${srcdir}/${subdir}/${srcfile} +A -Wl,-a,archive -g -o ${binfile}"remote_exec build $cmdline# Start with a fresh gdbset prms_id 0set bug_id 0gdb_exitgdb_startgdb_reinitialize_dir $srcdir/$subdirgdb_load ${binfile}if ![runto_main] then { perror "couldn't run to breakpoint" continue}# Set a catch catchpointsend_gdb "catch catch\n"gdb_expect { -re "Catchpoint \[0-9\]* \\(catch\\)\r\n$gdb_prompt $" { pass "catch catch (static executable)" } -re ".*$gdb_prompt $" { fail "catch catch (static executable)" } timeout { fail "(timeout) catch catch (static executable)" }}# Set a throw catchpointsend_gdb "catch throw\n"gdb_expect { -re "Catchpoint \[0-9\]* \\(throw\\)\r\n$gdb_prompt $" { pass "catch throw (static executable)" } -re ".*$gdb_prompt $" { fail "catch throw (static executable)" } timeout { fail "(timeout) catch throw (static executable)" }}# The catchpoints should be listed in the list of breakpoints.send_gdb "info break\n"gdb_expect { -re ".*\[0-9\]*\[ \]*catch catch\[ \]*keep y\[ \]*exception catch\[ \]*\r\n\[0-9\]*\[ \]*catch throw\[ \]*keep y\[ \]*exception throw\[ \]*\r\n$gdb_prompt $" { pass "info break with catchpoints (static executable)" } -re ".*$gdb_prompt $" { fail "info break (static executable)" } timeout { fail "(timeout) info break (static executable)" }}# Info catch currently does not work with HP aCC. No easy way to# list the active handlers on the stack.send_gdb "info catch\n"gdb_expect { -re "Info catch not supported with this target/compiler combination.\r\n$gdb_prompt $" { pass "info catch (static executable)" } -re ".*$gdb_prompt $" { fail "info catch (static executable)" } timeout { fail "(timeout) info catch (static executable)" }}# Get the first exception thrown send_gdb "continue\n"gdb_expect { -re "Continuing.*Catchpoint \[0-9\]* \\(exception thrown\\), throw location.*exception\\.cc:8, catch location .*exception\\.cc:28\r\n.*$gdb_prompt $" { pass "caught a throw (static executable)" } -re ".*$gdb_prompt $" { fail "didn't catch a throw (static executable)" } timeout { fail "(timeout) after continue -- didn't catch a throw? (static executable)" }}send_gdb "backtrace\n"gdb_expect { -re "#0\[ \]*__d_eh_break.*\r\n#1\[ \]*$hex in __d_eh_notify_callback \\(eh_type=__EH_NOTIFY_THROW.*\r\n#2\[ \]*$hex in __eh_notify_throw.*\r\n#3\[ \]*$hex in foo \\(i=20\\) at .*exception\\.cc:8\r\n#4\[ \]*$hex in main.* at .*exception\\.cc:26\r\n$gdb_prompt $" { pass "backtrace after throw (static executable)" } -re "#0\[ \]*__d_eh_break.*\r\n#1\[ \]*$hex in __d_eh_notify_callback \\(eh_type=\[0-9\].*\r\n#2\[ \]*$hex in __eh_notify_throw.*\r\n#3\[ \]*$hex in foo \\(i=20\\) at .*exception\\.cc:8\r\n#4\[ \]*$hex in main.* at .*exception\\.cc:26\r\n$gdb_prompt $" { pass "backtrace after throw (static executable)" } -re ".*$gdb_prompt $" { fail "backtrace after throw (static executable)" } timeout { fail "(timeout) backtrace after throw (static executable)" }}# Now intercept it when it is caught.send_gdb "continue\n"gdb_expect { -re "Continuing.*Catchpoint \[0-9\]* \\(exception caught\\), throw location.*exception\\.cc:8, catch location .*exception\\.cc:28\r\n.*$gdb_prompt $" { pass "caught a catch (static executable)" } -re ".*$gdb_prompt $" { fail "didn't catch a catch (static executable)" } timeout { fail "(timeout) after continue -- didn't catch a catch? (static executable)" }}send_gdb "backtrace\n"gdb_expect { -re "#0\[ \]*__d_eh_break.*\r\n#1\[ \]*$hex in __d_eh_notify_callback \\(eh_type=__EH_NOTIFY_CATCH.*\r\n.*\r\n#3\[ \]*$hex in __throw__.*\r\n#4\[ \]*$hex in foo \\(i=20\\) at .*exception.cc:8\r\n#5\[ \]*$hex in main.* at .*exception.cc:26\r\n$gdb_prompt $" { pass "backtrace after catch (static executable)" } -re "#0\[ \]*__d_eh_break.*\r\n#1\[ \]*$hex in __d_eh_notify_callback \\(eh_type=\[0-9\].*\r\n.*\r\n#3\[ \]*$hex in __throw__.*\r\n#4\[ \]*$hex in foo \\(i=20\\) at .*exception.cc:8\r\n#5\[ \]*$hex in main.* at .*exception.cc:26\r\n$gdb_prompt $" { pass "backtrace after catch (static executable)" } -re ".*$gdb_prompt $" { fail "backtrace after catch (static executable)" } timeout { fail "(timeout) backtrace after catch (static executable)" }} send_gdb "continue\n"gdb_expect { -re "Continuing\\.\r\nGot.*\r\nCatchpoint \[0-9\]* \\(exception thrown\\), throw location.*exception\\.cc:8, catch location .*exception\\.cc:36\r\n.*$gdb_prompt $" { pass "caught a throw (2) (static executable)" } -re ".*$gdb_prompt $" { fail "didn't catch a throw (2) (static executable)" } timeout { fail "(timeout) after continue -- didn't catch a throw (2)? (static executable)" }}send_gdb "continue\n"gdb_expect { -re "Continuing.*Catchpoint \[0-9\]* \\(exception caught\\), throw location.*exception\\.cc:8, catch location .*exception\\.cc:36\r\n.*$gdb_prompt $" { pass "caught a catch (2) (static executable)" } -re ".*$gdb_prompt $" { fail "didn't catch a catch (2) (static executable)" } timeout { fail "(timeout) after continue -- didn't catch a catch (2)? (static executable)" }}# Now the exception will be rethrown.send_gdb "continue\n"gdb_expect { -re "Continuing\\.\r\nGot.*\r\nCatchpoint \[0-9\]* \\(exception thrown\\), throw location.*exception\\.cc:38, catch location .*exception\\.cc:41\r\n.*$gdb_prompt $" { pass "caught a rethrow (static executable)" } -re ".*$gdb_prompt $" { fail "didn't catch a rethrow (static executable)" } timeout { fail "(timeout) after continue -- didn't catch a rethrow? (static executable)" }}send_gdb "continue\n"gdb_expect { -re "Continuing.*Catchpoint \[0-9\]* \\(exception caught\\), throw location.*exception\\.cc:3\[68\], catch location .*exception\\.cc:41\r\n.*$gdb_prompt $" { # FIXME: guo: why XFAIL? need comment xfail "caught a catch (3) (static executable)" } -re ".*$gdb_prompt $" { fail "didn't catch a catch (3) (static executable)" } timeout { fail "(timeout) after continue -- didn't catch a catch (3)? (static executable)" }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -