2010-01-01 07:32:07 +00:00
# Copyright 1997, 1998, 2004, 2005, 2007, 2008, 2009, 2010
2009-01-03 05:58:08 +00:00
# Free Software Foundation, Inc.
1999-08-16 19:57:19 +00:00
# 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
2007-08-23 18:14:19 +00:00
# the Free Software Foundation; either version 3 of the License, or
1999-08-16 19:57:19 +00:00
# (at your option) any later version.
2007-08-23 18:14:19 +00:00
#
1999-08-16 19:57:19 +00:00
# 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.
2007-08-23 18:14:19 +00:00
#
1999-08-16 19:57:19 +00:00
# You should have received a copy of the GNU General Public License
2007-08-23 18:14:19 +00:00
# along with this program. If not, see <http://www.gnu.org/licenses/>.
1999-08-16 19:57:19 +00:00
2004-01-09 09:48:52 +00:00
# This file is part of the gdb testsuite.
1999-08-16 19:57:19 +00:00
# tests for exception-handling support
# Written by Satish Pai <pai@apollo.hp.com> 1997-07-23
2004-01-09 09:48:52 +00:00
# Rewritten by Michael Chastain <mec.gnu@mindspring.com> 2004-01-08
1999-08-16 19:57:19 +00:00
2004-01-09 09:48:52 +00:00
# This file used to have two copies of the tests with different
# compiler flags for hp-ux. Instead, the user should set CXXOPTS
# or run runtest with --target_board unix/gdb:debug_flags="..."
# to choose the compiler flags.
#
2004-01-10 00:03:17 +00:00
# The interesting compiler flags are: "aCC +A -Wl,-a,-archive" .
2004-01-09 09:48:52 +00:00
# Static-linked executables use a different mechanism to get the
# address of the notification hook in the C++ support library.
1999-08-16 19:57:19 +00:00
2004-01-09 09:48:52 +00:00
# TODO: this file has many absolute line numbers.
# Replace them with gdb_get_line_number.
1999-08-16 19:57:19 +00:00
2004-01-09 09:48:52 +00:00
set ws "\[\r\n\t \]+"
set nl "\[\r\n\]+"
1999-08-16 19:57:19 +00:00
2004-01-09 09:48:52 +00:00
if $tracelevel then {
strace $tracelevel
}
1999-08-16 19:57:19 +00:00
2010-03-12 19:17:01 +00:00
if { [skip_stl_tests] } { continue }
2005-03-08 10:12:21 +00:00
2006-11-22 17:19:52 +00:00
# On SPU this test fails because the executable exceeds local storage size.
if { [istarget "spu*-*-*"] } {
return 0
}
1999-08-16 19:57:19 +00:00
set testfile "exception"
set srcfile ${testfile}.cc
set binfile ${objdir}/${subdir}/${testfile}
2004-01-09 09:48:52 +00:00
if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug c++}] != "" } {
2006-08-10 05:27:22 +00:00
untested exception.exp
return -1
1999-08-16 19:57:19 +00:00
}
# Start with a fresh gdb
gdb_exit
gdb_start
gdb_reinitialize_dir $srcdir/$subdir
gdb_load ${binfile}
# Set a catch catchpoint
2008-06-05 18:45:37 +00:00
gdb_test "catch catch" "Catchpoint \[0-9\]+ \\(catch\\)" \
"catch catch (before inferior run)"
1999-08-16 19:57:19 +00:00
# Set a throw catchpoint
2004-01-09 09:48:52 +00:00
gdb_test "catch throw" "Catchpoint \[0-9\]+ \\(throw\\)" \
2008-06-05 18:45:37 +00:00
"catch throw (before inferior run)"
1999-08-16 19:57:19 +00:00
2008-06-05 18:45:37 +00:00
# The catchpoints should be listed in the list of breakpoints.
# In case of a statically linked test, we won't have a pending breakpoint.
# Hence we allow for both an address or "<PENDING>". If we ever become able
# to tell whether the target is linked statically or not, we can be more
# precise and require exact output.
set addr "\(<PENDING>|$hex\)"
2004-01-09 09:48:52 +00:00
set re_head "Num${ws}Type${ws}Disp${ws}Enb${ws}Address${ws}What"
2008-06-05 18:45:37 +00:00
set re_2_bp "1${ws}breakpoint${ws}keep${ws}y${ws}$addr${ws}exception catch"
set re_3_bp "2${ws}breakpoint${ws}keep${ws}y${ws}$addr${ws}exception throw"
2004-01-09 09:48:52 +00:00
2008-06-05 18:45:37 +00:00
set name "info breakpoints (before inferior run)"
2004-01-09 09:48:52 +00:00
gdb_test_multiple "info breakpoints" $name {
2008-06-05 18:45:37 +00:00
-re "$re_head${ws}$re_2_bp${ws}$re_3_bp\r\n$gdb_prompt $" {
2004-01-09 09:48:52 +00:00
pass $name
}
2008-06-05 18:45:37 +00:00
-re ".*$gdb_prompt $"
{
fail $name
}
2004-01-09 09:48:52 +00:00
}
2008-06-05 18:45:37 +00:00
gdb_test "tbreak main" "Temporary breakpoint 3.*" \
"Set temporary breakpoint at main"
2004-01-09 09:48:52 +00:00
2008-06-05 18:45:37 +00:00
set ok 0
gdb_run_cmd
gdb_test_multiple "" "Run to main" {
-re "Temporary breakpoint 3,.*$gdb_prompt $" {
pass "Run to main"
set ok 1
2004-01-09 09:48:52 +00:00
}
2008-06-05 18:45:37 +00:00
}
if { !$ok } {
continue
}
set addr "$hex"
set re_head "Num${ws}Type${ws}Disp${ws}Enb${ws}Address${ws}What"
set re_2_bp "1${ws}breakpoint${ws}keep${ws}y${ws}$addr${ws}exception catch"
set re_3_bp "2${ws}breakpoint${ws}keep${ws}y${ws}$addr${ws}exception throw"
set name "info breakpoints (after inferior run)"
gdb_test_multiple "info breakpoints" $name {
-re "$re_head${ws}$re_2_bp${ws}$re_3_bp\r\n$gdb_prompt $" {
pass $name
2004-01-09 09:48:52 +00:00
}
2008-06-05 18:45:37 +00:00
-re ".*$gdb_prompt $"
{
send_user "\n---\n$expect_out(buffer)\n---\n"
fail $name
}
1999-08-16 19:57:19 +00:00
}
# Get the first exception thrown
2004-01-09 09:48:52 +00:00
set name "continue to first throw"
gdb_test_multiple "continue" $name {
-re "Continuing.${ws}Catchpoint \[0-9\]+ \\(exception thrown\\), throw location.*${srcfile}:30, catch location .*${srcfile}:50\r\n$gdb_prompt $" {
pass $name
}
2008-06-05 18:45:37 +00:00
-re "Continuing.${ws}Catchpoint \[0-9\]+ \\(exception thrown\\).*\r\n$gdb_prompt $" {
pass $name
2004-01-09 09:48:52 +00:00
}
1999-08-16 19:57:19 +00:00
}
2004-01-09 09:48:52 +00:00
# Backtrace from the throw point.
# This should get to user code.
1999-08-16 19:57:19 +00:00
2004-01-09 09:48:52 +00:00
set name "backtrace after first throw"
gdb_test_multiple "backtrace" $name {
* gdb.cp/cp-relocate.exp: Remove single-quoting of C++ methods.
* gdb.cp/cplusfuncs.cc (dm_type_short): New function.
(dm_type_long): New function.
(dm_type_unsigned_short): New function.
(dm_type_unsigned_long): New function.
(myint): New typedef.
* gdb.cp/cplusfuncs.exp (probe_demangler): Add tests for short,
long, unsigned shor and long, operator char*, and typedef.
(test_lookup_operator_functions): Add operator char* test.
(test_paddr_operator_functions): Likewise.
(test_paddr_overloaded_functions): Use probe values for
short, long, and unsigned short and long.
(test_paddr_hairy_functions): If the demangler probe detected
gdb type printers, "expect" them. Otherwise "expect" the v2 or v3
demangler.
* gdb.cp/expand-sals.exp: Backtrace may contain class names.
* gdb.cp/member-ptr.exp: Refine expected result for "print pmf"
and "print null_pmf".
Add test "ptype a.*pmf".
* gdb.cp/overload.exp: Allow optional "int" to appear with
"short" and "long".
* gdb.cp/ovldbreak.exp: Use append to construct super-duper
long expect value for men_overload1arg.
Allow "int" to appear with "short" and "long".
When testing "info break", add argument for main (void).
Also allow "int" to appear with "short" and "long".
Ditto with "unsigned" and "long long".
* gdb.java/jmain.exp: Do not enclose methods names in single
quotes.
* gdb.java/jmisc.exp: Likewise.
* gdb.java/jprint.exp: Likewise.
* gdb.python/py-symbol.exp: Update expected "linkage_name" value.
From Jan Kratochvil <jan.kratochvil@redhat.com>:
* gdb.cp/exception.exp (backtrace after first throw)
(backtrace after second throw): Allow a namespace before __cxa_throw.
(backtrace after first catch, backtrace after second catch): Allow
a namespace before __cxa_begin_catch.
* gdb.cp/cpexprs.exp: New file.
* gdb.cp/cpexprs.cc: New file.
From Daniel Jacobowitz <dan@codesourcery.com>
* gdb.cp/cpexprs.exp (escape): Delete. Change all callers
to use string_to_regexp.
(ctor, dtor): New functions. Use them to match constructor
and destructor function types.
(Top level): Use runto_main.
2010-03-09 18:08:05 +00:00
-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 $" {
# Either __cxxabiv1::__cxa_throw or __cxa_throw can be printed
# depending on debug info presence.
2004-01-09 09:48:52 +00:00
pass $name
}
1999-08-16 19:57:19 +00:00
}
2004-01-09 09:48:52 +00:00
# Continue to the catch.
1999-08-16 19:57:19 +00:00
2004-01-09 09:48:52 +00:00
set name "continue to first catch"
gdb_test_multiple "continue" $name {
-re "Continuing.${ws}Catchpoint \[0-9\]+ \\(exception caught\\), throw location.*${srcfile}:30, catch location .*${srcfile}:50\r\n$gdb_prompt $" {
pass $name
}
2008-06-05 18:45:37 +00:00
-re "Continuing.${ws}Catchpoint \[0-9\]+ \\(exception caught\\).*\r\n$gdb_prompt $" {
pass $name
2004-01-09 09:48:52 +00:00
}
1999-08-16 19:57:19 +00:00
}
2004-01-09 09:48:52 +00:00
# Backtrace from the catch point.
# This should get to user code.
1999-08-16 19:57:19 +00:00
2004-01-09 09:48:52 +00:00
set name "backtrace after first catch"
gdb_test_multiple "backtrace" $name {
* gdb.cp/cp-relocate.exp: Remove single-quoting of C++ methods.
* gdb.cp/cplusfuncs.cc (dm_type_short): New function.
(dm_type_long): New function.
(dm_type_unsigned_short): New function.
(dm_type_unsigned_long): New function.
(myint): New typedef.
* gdb.cp/cplusfuncs.exp (probe_demangler): Add tests for short,
long, unsigned shor and long, operator char*, and typedef.
(test_lookup_operator_functions): Add operator char* test.
(test_paddr_operator_functions): Likewise.
(test_paddr_overloaded_functions): Use probe values for
short, long, and unsigned short and long.
(test_paddr_hairy_functions): If the demangler probe detected
gdb type printers, "expect" them. Otherwise "expect" the v2 or v3
demangler.
* gdb.cp/expand-sals.exp: Backtrace may contain class names.
* gdb.cp/member-ptr.exp: Refine expected result for "print pmf"
and "print null_pmf".
Add test "ptype a.*pmf".
* gdb.cp/overload.exp: Allow optional "int" to appear with
"short" and "long".
* gdb.cp/ovldbreak.exp: Use append to construct super-duper
long expect value for men_overload1arg.
Allow "int" to appear with "short" and "long".
When testing "info break", add argument for main (void).
Also allow "int" to appear with "short" and "long".
Ditto with "unsigned" and "long long".
* gdb.java/jmain.exp: Do not enclose methods names in single
quotes.
* gdb.java/jmisc.exp: Likewise.
* gdb.java/jprint.exp: Likewise.
* gdb.python/py-symbol.exp: Update expected "linkage_name" value.
From Jan Kratochvil <jan.kratochvil@redhat.com>:
* gdb.cp/exception.exp (backtrace after first throw)
(backtrace after second throw): Allow a namespace before __cxa_throw.
(backtrace after first catch, backtrace after second catch): Allow
a namespace before __cxa_begin_catch.
* gdb.cp/cpexprs.exp: New file.
* gdb.cp/cpexprs.cc: New file.
From Daniel Jacobowitz <dan@codesourcery.com>
* gdb.cp/cpexprs.exp (escape): Delete. Change all callers
to use string_to_regexp.
(ctor, dtor): New functions. Use them to match constructor
and destructor function types.
(Top level): Use runto_main.
2010-03-09 18:08:05 +00:00
-re ".*#\[0-9\]+.*\[\[:<:\]\]__cxa_begin_catch\[\[:>:\]\].*#\[0-9\]+${ws}$hex in main \\(.*\\) at .*$srcfile:\[0-9\]+\r\n$gdb_prompt $" {
2004-01-09 09:48:52 +00:00
pass $name
}
1999-08-16 19:57:19 +00:00
}
2004-01-09 09:48:52 +00:00
# Continue to second throw.
1999-08-16 19:57:19 +00:00
2004-01-09 09:48:52 +00:00
set name "continue to second throw"
gdb_test_multiple "continue" $name {
-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 $" {
pass $name
}
2008-06-05 18:45:37 +00:00
-re "Continuing.${ws}Got an except 13${ws}Catchpoint \[0-9\]+ \\(exception thrown\\).*\r\n$gdb_prompt $" {
pass $name
2004-01-09 09:48:52 +00:00
}
1999-08-16 19:57:19 +00:00
}
2004-01-09 09:48:52 +00:00
# Backtrace from the throw point.
# This should get to user code.
1999-08-16 19:57:19 +00:00
2004-01-09 09:48:52 +00:00
set name "backtrace after second throw"
gdb_test_multiple "backtrace" $name {
* gdb.cp/cp-relocate.exp: Remove single-quoting of C++ methods.
* gdb.cp/cplusfuncs.cc (dm_type_short): New function.
(dm_type_long): New function.
(dm_type_unsigned_short): New function.
(dm_type_unsigned_long): New function.
(myint): New typedef.
* gdb.cp/cplusfuncs.exp (probe_demangler): Add tests for short,
long, unsigned shor and long, operator char*, and typedef.
(test_lookup_operator_functions): Add operator char* test.
(test_paddr_operator_functions): Likewise.
(test_paddr_overloaded_functions): Use probe values for
short, long, and unsigned short and long.
(test_paddr_hairy_functions): If the demangler probe detected
gdb type printers, "expect" them. Otherwise "expect" the v2 or v3
demangler.
* gdb.cp/expand-sals.exp: Backtrace may contain class names.
* gdb.cp/member-ptr.exp: Refine expected result for "print pmf"
and "print null_pmf".
Add test "ptype a.*pmf".
* gdb.cp/overload.exp: Allow optional "int" to appear with
"short" and "long".
* gdb.cp/ovldbreak.exp: Use append to construct super-duper
long expect value for men_overload1arg.
Allow "int" to appear with "short" and "long".
When testing "info break", add argument for main (void).
Also allow "int" to appear with "short" and "long".
Ditto with "unsigned" and "long long".
* gdb.java/jmain.exp: Do not enclose methods names in single
quotes.
* gdb.java/jmisc.exp: Likewise.
* gdb.java/jprint.exp: Likewise.
* gdb.python/py-symbol.exp: Update expected "linkage_name" value.
From Jan Kratochvil <jan.kratochvil@redhat.com>:
* gdb.cp/exception.exp (backtrace after first throw)
(backtrace after second throw): Allow a namespace before __cxa_throw.
(backtrace after first catch, backtrace after second catch): Allow
a namespace before __cxa_begin_catch.
* gdb.cp/cpexprs.exp: New file.
* gdb.cp/cpexprs.cc: New file.
From Daniel Jacobowitz <dan@codesourcery.com>
* gdb.cp/cpexprs.exp (escape): Delete. Change all callers
to use string_to_regexp.
(ctor, dtor): New functions. Use them to match constructor
and destructor function types.
(Top level): Use runto_main.
2010-03-09 18:08:05 +00:00
-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 $" {
2004-01-09 09:48:52 +00:00
pass $name
}
1999-08-16 19:57:19 +00:00
}
2004-01-09 09:48:52 +00:00
# Continue to second catch.
1999-08-16 19:57:19 +00:00
2004-01-09 09:48:52 +00:00
set name "continue to second catch"
gdb_test_multiple "continue" $name {
-re "Continuing.${ws}Catchpoint \[0-9\]+ \\(exception caught\\), throw location.*${srcfile}:30, catch location .*${srcfile}:58\r\n$gdb_prompt $" {
pass $name
}
2008-06-05 18:45:37 +00:00
-re "Continuing.${ws}Catchpoint \[0-9\]+ \\(exception caught\\).*\r\n$gdb_prompt $" {
pass $name
2004-01-09 09:48:52 +00:00
}
1999-08-16 19:57:19 +00:00
}
2004-01-09 09:48:52 +00:00
# Backtrace from the catch point.
# This should get to user code.
1999-08-16 19:57:19 +00:00
2004-01-09 09:48:52 +00:00
set name "backtrace after second catch"
gdb_test_multiple "backtrace" $name {
* gdb.cp/cp-relocate.exp: Remove single-quoting of C++ methods.
* gdb.cp/cplusfuncs.cc (dm_type_short): New function.
(dm_type_long): New function.
(dm_type_unsigned_short): New function.
(dm_type_unsigned_long): New function.
(myint): New typedef.
* gdb.cp/cplusfuncs.exp (probe_demangler): Add tests for short,
long, unsigned shor and long, operator char*, and typedef.
(test_lookup_operator_functions): Add operator char* test.
(test_paddr_operator_functions): Likewise.
(test_paddr_overloaded_functions): Use probe values for
short, long, and unsigned short and long.
(test_paddr_hairy_functions): If the demangler probe detected
gdb type printers, "expect" them. Otherwise "expect" the v2 or v3
demangler.
* gdb.cp/expand-sals.exp: Backtrace may contain class names.
* gdb.cp/member-ptr.exp: Refine expected result for "print pmf"
and "print null_pmf".
Add test "ptype a.*pmf".
* gdb.cp/overload.exp: Allow optional "int" to appear with
"short" and "long".
* gdb.cp/ovldbreak.exp: Use append to construct super-duper
long expect value for men_overload1arg.
Allow "int" to appear with "short" and "long".
When testing "info break", add argument for main (void).
Also allow "int" to appear with "short" and "long".
Ditto with "unsigned" and "long long".
* gdb.java/jmain.exp: Do not enclose methods names in single
quotes.
* gdb.java/jmisc.exp: Likewise.
* gdb.java/jprint.exp: Likewise.
* gdb.python/py-symbol.exp: Update expected "linkage_name" value.
From Jan Kratochvil <jan.kratochvil@redhat.com>:
* gdb.cp/exception.exp (backtrace after first throw)
(backtrace after second throw): Allow a namespace before __cxa_throw.
(backtrace after first catch, backtrace after second catch): Allow
a namespace before __cxa_begin_catch.
* gdb.cp/cpexprs.exp: New file.
* gdb.cp/cpexprs.cc: New file.
From Daniel Jacobowitz <dan@codesourcery.com>
* gdb.cp/cpexprs.exp (escape): Delete. Change all callers
to use string_to_regexp.
(ctor, dtor): New functions. Use them to match constructor
and destructor function types.
(Top level): Use runto_main.
2010-03-09 18:08:05 +00:00
-re ".*#\[0-9\]+.*\[\[:<:\]\]__cxa_begin_catch\[\[:>:\]\].*#\[0-9\]+${ws}$hex in main \\(.*\\) at .*$srcfile:\[0-9\]+\r\n$gdb_prompt $" {
2004-01-09 09:48:52 +00:00
pass $name
}
1999-08-16 19:57:19 +00:00
}
2004-01-09 09:48:52 +00:00
# That is all for now.
#
# The original code had:
#
# continue to re-throw ; backtrace
# continue to catch ; backtrace
# continue to throw out of main
#
# The problem is that "re-throw" does not show a throw; only a catch.
# I do not know if this is because of a bug, or because the generated
# code is optimized for a throw into the same function.
#
# -- chastain 2004-01-09