aboutsummaryrefslogtreecommitdiff
path: root/gdb/testsuite
diff options
context:
space:
mode:
Diffstat (limited to 'gdb/testsuite')
-rw-r--r--gdb/testsuite/ChangeLog7
-rw-r--r--gdb/testsuite/gdb.mi/mi-catch-cpp-exceptions.cc73
-rw-r--r--gdb/testsuite/gdb.mi/mi-catch-cpp-exceptions.exp197
-rw-r--r--gdb/testsuite/lib/mi-support.exp11
4 files changed, 285 insertions, 3 deletions
diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog
index 4c7f59b..94c73486 100644
--- a/gdb/testsuite/ChangeLog
+++ b/gdb/testsuite/ChangeLog
@@ -1,5 +1,12 @@
2019-06-15 Andrew Burgess <andrew.burgess@embecosm.com>
+ * gdb.mi/mi-catch-cpp-exceptions.cc: New file.
+ * gdb.mi/mi-catch-cpp-exceptions.exp: New file.
+ * lib/mi-support.exp (mi_expect_stop): Handle 'exception-caught'
+ as a stop reason.
+
+2019-06-15 Andrew Burgess <andrew.burgess@embecosm.com>
+
* gdb.base/annota1.exp: Update expected results.
* gdb.cp/annota2.exp: Likewise.
* gdb.cp/annota3.exp: Likewise.
diff --git a/gdb/testsuite/gdb.mi/mi-catch-cpp-exceptions.cc b/gdb/testsuite/gdb.mi/mi-catch-cpp-exceptions.cc
new file mode 100644
index 0000000..cacda46
--- /dev/null
+++ b/gdb/testsuite/gdb.mi/mi-catch-cpp-exceptions.cc
@@ -0,0 +1,73 @@
+/* Copyright 2019 Free Software Foundation, Inc.
+
+ This file is part of GDB.
+
+ 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 3 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, see <http://www.gnu.org/licenses/>. */
+
+class my_exception
+{
+private:
+ int m_value;
+
+public:
+ my_exception (int v)
+ : m_value (v)
+ {
+ /* Nothing. */
+ }
+};
+
+void
+bar ()
+{
+ my_exception ex (4);
+ throw ex; /* Throw 1. */
+}
+
+void
+foo ()
+{
+ for (int i = 0; i < 2; ++i)
+ {
+ try
+ {
+ bar ();
+ }
+ catch (const my_exception &ex) /* Catch 1. */
+ {
+ if (i == 1)
+ throw; /* Throw 2. */
+ }
+ }
+}
+
+int
+main ()
+{
+ for (int i = 0; i < 2; ++i)
+ {
+ try
+ {
+ foo ();
+ }
+ catch (const my_exception &ex) /* Catch 2. */
+ {
+ if (i == 1)
+ return 1; /* Stop here. */
+ }
+ }
+
+ return 0;
+}
+
diff --git a/gdb/testsuite/gdb.mi/mi-catch-cpp-exceptions.exp b/gdb/testsuite/gdb.mi/mi-catch-cpp-exceptions.exp
new file mode 100644
index 0000000..b5dfbe6
--- /dev/null
+++ b/gdb/testsuite/gdb.mi/mi-catch-cpp-exceptions.exp
@@ -0,0 +1,197 @@
+# Copyright 2019 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 3 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, see <http://www.gnu.org/licenses/>.
+
+# Test the -catch-throw, -catch-rethrow, and -catch-catch MI commands.
+
+if { [skip_cplus_tests] } { continue }
+
+load_lib mi-support.exp
+set MIFLAGS "-i=mi"
+
+standard_testfile .cc
+
+if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug c++}] != "" } {
+ untested "failed to compile"
+ return -1
+}
+
+# Grab some line numbers we'll need.
+set catch_1_lineno [gdb_get_line_number "Catch 1"]
+set catch_2_lineno [gdb_get_line_number "Catch 2"]
+set throw_1_lineno [gdb_get_line_number "Throw 1"]
+set throw_2_lineno [gdb_get_line_number "Throw 2"]
+set main_lineno [gdb_get_line_number "Stop here"]
+
+# Restart this test, load the test binary and set a breakpoint in
+# main.
+proc restart_for_test {} {
+ global srcdir subdir binfile srcfile
+ global main_lineno
+
+ if {[mi_gdb_start]} {
+ continue
+ }
+
+ mi_delete_breakpoints
+ mi_gdb_reinitialize_dir $srcdir/$subdir
+ mi_gdb_load ${binfile}
+
+ mi_runto main
+
+ mi_create_breakpoint \
+ "$srcfile:${main_lineno}" "break before exiting program" \
+ -disp keep -func "main.*" \
+ -file ".*mi-catch-cpp-exceptions.cc" -line ${main_lineno}
+}
+
+# Issue an -exec-continue then wait for GDB to catch a C++ exception
+# event in FUNC on LINE. Use TESTNAME to make tests unique.
+proc continue_to_next_exception { func line testname } {
+ global hex
+
+ mi_send_resuming_command "exec-continue" \
+ "exec-continue"
+ mi_expect_stop "exception-caught" ".*" ".*" ".*" ".*" \
+ {} "run until an exception is caught: $testname"
+ mi_gdb_test "-stack-list-frames 1 1" \
+ "\\^done,stack=\\\[frame=\{level=\"1\",addr=\"$hex\",func=\"${func}\",.*,line=\"${line}\".*\}\\\]" \
+ "check previous frame: $testname"
+}
+
+# Issue an -exec-continue and stop at the breakpoint in main.
+proc continue_to_breakpoint_in_main {} {
+ global main_lineno
+
+ mi_send_resuming_command "exec-continue" "exec-continue to main"
+ mi_expect_stop "breakpoint-hit" "main" ".*" ".*" "${main_lineno}" \
+ {.* disp="keep"} "run until breakpoint in main"
+}
+
+# TYPE is one of throw, rethrow, or catch. This proc creates a catch
+# point using -catch-TYPE. The optional string EXTRA is any extra
+# arguments to pass when setting up the catchpoint.
+proc setup_catchpoint {type {extra ""}} {
+ global decimal
+ mi_gdb_test "-catch-${type} ${extra}" \
+ "\\^done,bkpt=\{number=\"$decimal\".*what=\"exception ${type}\",catch-type=\"${type}\".*\}" \
+ "Setup -catch-${type}"
+}
+
+# Ensure that -catch-throw will catch only throws and nothing else.
+with_test_prefix "-catch-throw" {
+ restart_for_test
+ setup_catchpoint "throw"
+ continue_to_next_exception "bar" "${throw_1_lineno}" "throw 1"
+ continue_to_next_exception "bar" "${throw_1_lineno}" "throw 2"
+ continue_to_next_exception "bar" "${throw_1_lineno}" "throw 3"
+ continue_to_next_exception "bar" "${throw_1_lineno}" "throw 4"
+ continue_to_breakpoint_in_main
+}
+
+# Ensure that -catch-rethrow catches only rethrows and nothing else.
+with_test_prefix "-catch-rethrow" {
+ restart_for_test
+ setup_catchpoint "rethrow"
+ continue_to_next_exception "foo" "${throw_2_lineno}" "rethrow 1"
+ continue_to_next_exception "foo" "${throw_2_lineno}" "rethrow 2"
+ continue_to_breakpoint_in_main
+}
+
+# Ensure that -catch-catch catches only catch points, and nothing
+# else.
+with_test_prefix "-catch-catch" {
+ restart_for_test
+ setup_catchpoint "catch"
+ continue_to_next_exception "foo" "${catch_1_lineno}" "catch 1"
+ continue_to_next_exception "foo" "${catch_1_lineno}" "catch 2"
+ continue_to_next_exception "main" "${catch_2_lineno}" "catch 3"
+ continue_to_next_exception "foo" "${catch_1_lineno}" "catch 4"
+ continue_to_next_exception "foo" "${catch_1_lineno}" "catch 5"
+ continue_to_next_exception "main" "${catch_2_lineno}" "catch 6"
+ continue_to_breakpoint_in_main
+}
+
+# Now check that all of the command with a regexp that doesn't match,
+# don't trigger.
+with_test_prefix "all with invalid regexp" {
+ restart_for_test
+ setup_catchpoint "throw" "-r blahblah"
+ setup_catchpoint "rethrow" "-r woofwoof"
+ setup_catchpoint "catch" "-r miowmiow"
+
+ # Would like to use 'continue_to_breakpoint_in_main' here, if
+ # there wasn't a bug that requires a use of kfail.
+
+ mi_send_resuming_command "exec-continue" \
+ "exec-continue"
+ set testname "run until breakpoint in main"
+ gdb_expect {
+ -re "could not find minimal symbol for typeinfo address.*$mi_gdb_prompt$" {
+ kfail "gdb/24541" "${testname}"
+ }
+ -re "\\*stopped,reason=\"breakpoint-hit\".*func=\"main\".*line=\"${main_lineno}\".*$mi_gdb_prompt$" {
+ pass "${testname}"
+ }
+ timeout {
+ fail "${testname} (timeout)"
+ }
+ }
+}
+
+# Now check that all of the commands with a regexp that does match,
+# still trigger.
+with_test_prefix "all with valid regexp" {
+ restart_for_test
+ setup_catchpoint "throw" "-r my_ex"
+ setup_catchpoint "rethrow" "-r _except"
+ setup_catchpoint "catch" "-r my_exception"
+ continue_to_next_exception "bar" "${throw_1_lineno}" "throw 1"
+ continue_to_next_exception "foo" "${catch_1_lineno}" "catch 1"
+ continue_to_next_exception "bar" "${throw_1_lineno}" "throw 2"
+ continue_to_next_exception "foo" "${catch_1_lineno}" "catch 2"
+ continue_to_next_exception "foo" "${throw_2_lineno}" "rethrow 1"
+ continue_to_next_exception "main" "${catch_2_lineno}" "catch 3"
+ continue_to_next_exception "bar" "${throw_1_lineno}" "throw 3"
+ continue_to_next_exception "foo" "${catch_1_lineno}" "catch 4"
+ continue_to_next_exception "bar" "${throw_1_lineno}" "throw 4"
+ continue_to_next_exception "foo" "${catch_1_lineno}" "catch 5"
+ continue_to_next_exception "foo" "${throw_2_lineno}" "rethrow 2"
+ continue_to_next_exception "main" "${catch_2_lineno}" "catch 6"
+ continue_to_breakpoint_in_main
+}
+
+# Check that the temporary switch works on its own.
+with_test_prefix "all with -t" {
+ restart_for_test
+ setup_catchpoint "throw" "-t"
+ setup_catchpoint "rethrow" "-t"
+ setup_catchpoint "catch" "-t"
+ continue_to_next_exception "bar" "${throw_1_lineno}" "throw 1"
+ continue_to_next_exception "foo" "${catch_1_lineno}" "catch 1"
+ continue_to_next_exception "foo" "${throw_2_lineno}" "rethrow 1"
+ continue_to_breakpoint_in_main
+}
+
+# Check that the temporary switch works when used with a regexp.
+restart_for_test
+with_test_prefix "all with -t and regexp" {
+ setup_catchpoint "throw" "-t -r my_ex"
+ setup_catchpoint "rethrow" "-t -r _except"
+ setup_catchpoint "catch" "-t -r my_exception"
+ continue_to_next_exception "bar" "${throw_1_lineno}" "throw 1"
+ continue_to_next_exception "foo" "${catch_1_lineno}" "catch 1"
+ continue_to_next_exception "foo" "${throw_2_lineno}" "rethrow 1"
+ continue_to_breakpoint_in_main
+}
diff --git a/gdb/testsuite/lib/mi-support.exp b/gdb/testsuite/lib/mi-support.exp
index a58c4f6..8c2c7c8 100644
--- a/gdb/testsuite/lib/mi-support.exp
+++ b/gdb/testsuite/lib/mi-support.exp
@@ -1221,10 +1221,15 @@ proc mi_expect_stop { reason func args file line extra test } {
set args "\\\[$args\\\]"
set bn ""
+ set ebn ""
if { $reason == "breakpoint-hit" } {
set bn {bkptno="[0-9]+",}
} elseif { $reason == "solib-event" } {
set bn ".*"
+ } elseif { $reason == "exception-caught" } {
+ set ebn {bkptno="[0-9]+",}
+ set bn ".*"
+ set reason "breakpoint-hit"
}
set r ""
@@ -1235,9 +1240,9 @@ proc mi_expect_stop { reason func args file line extra test } {
set a $after_reason
- verbose -log "mi_expect_stop: expecting: \\*stopped,${r}${a}${bn}frame=\{addr=\"$hex\",func=\"$func\",args=$args,(?:file=\"$any$file\",fullname=\"${fullname_syntax}$file\",line=\"$line\",arch=\"$any\"|from=\"$file\")\}$after_stopped,thread-id=\"$decimal\",stopped-threads=$any\r\n($thread_selected_re|$breakpoint_re)*$prompt_re"
+ verbose -log "mi_expect_stop: expecting: \\*stopped,${ebn}${r}${a}${bn}frame=\{addr=\"$hex\",func=\"$func\",args=$args,(?:file=\"$any$file\",fullname=\"${fullname_syntax}$file\",line=\"$line\",arch=\"$any\"|from=\"$file\")\}$after_stopped,thread-id=\"$decimal\",stopped-threads=$any\r\n($thread_selected_re|$breakpoint_re)*$prompt_re"
gdb_expect {
- -re "\\*stopped,${r}${a}${bn}frame=\{addr=\"$hex\",func=\"$func\",args=$args,(?:file=\"$any$file\",fullname=\"${fullname_syntax}$file\",line=\"($line)\",arch=\"$any\"|from=\"$file\")\}$after_stopped,thread-id=\"$decimal\",stopped-threads=$any\r\n($thread_selected_re|$breakpoint_re)*$prompt_re" {
+ -re "\\*stopped,${ebn}${r}${a}${bn}frame=\{addr=\"$hex\",func=\"$func\",args=$args,(?:file=\"$any$file\",fullname=\"${fullname_syntax}$file\",line=\"($line)\",arch=\"$any\"|from=\"$file\")\}$after_stopped,thread-id=\"$decimal\",stopped-threads=$any\r\n($thread_selected_re|$breakpoint_re)*$prompt_re" {
pass "$test"
if {[array names expect_out "2,string"] != ""} {
return $expect_out(2,string)
@@ -1245,7 +1250,7 @@ proc mi_expect_stop { reason func args file line extra test } {
# No debug info available but $file does match.
return 0
}
- -re "\\*stopped,${r}${a}${bn}frame=\{addr=\"$hex\",func=\"$any\",args=\[\\\[\{\]$any\[\\\]\}\],file=\"$any\",fullname=\"${fullname_syntax}$any\",line=\"\[0-9\]*\",arch=\"$any\"\}$after_stopped,thread-id=\"$decimal\",stopped-threads=$any\r\n($thread_selected_re|$breakpoint_re)*$prompt_re" {
+ -re "\\*stopped,${ebn}${r}${a}${bn}frame=\{addr=\"$hex\",func=\"$any\",args=\[\\\[\{\]$any\[\\\]\}\],file=\"$any\",fullname=\"${fullname_syntax}$any\",line=\"\[0-9\]*\",arch=\"$any\"\}$after_stopped,thread-id=\"$decimal\",stopped-threads=$any\r\n($thread_selected_re|$breakpoint_re)*$prompt_re" {
verbose -log "got $expect_out(buffer)"
fail "$test (stopped at wrong place)"
return -1