summaryrefslogtreecommitdiff
path: root/gdb/testsuite/gdb.ada
diff options
context:
space:
mode:
authorXavier Roirand <roirand@adacore.com>2017-11-22 10:40:39 +0100
committerXavier Roirand <roirand@adacore.com>2018-01-03 11:02:53 +0100
commit9f757bf7fcb8834ead780e0c4a76d6029b1402c2 (patch)
tree73e1c8207e49be351b83236f7a9a7a7c0fcb9011 /gdb/testsuite/gdb.ada
parent219d1afa89d0d53ca93a684cac341f16470f3ca0 (diff)
(Ada) New command to stop at start of exception handler.
When using gdb for debugging Ada source code, there are several catchpoint types you can define in order to stop upon certain conditions. Let's use this small example: procedure Foo is begin begin raise Constraint_Error; exception when Program_Error => null; when Constraint_Error => null; when others => null; end; end Foo; One can stop when the exception is being raised by using the exception catchpoint like below: (gdb) catch exception Catchpoint 1: all Ada exceptions (gdb) In that case, when running Foo, gdb will stop at the line where the exception was raised: begin >>> raise Constraint_Error; exception This patch introduces new type of catchpoint, when the user wants to stop at the location of the exception handling. Imagine we want to stop on any exception handled by the program, we can do: (gdb) catch handlers Catchpoint 1: all Ada exceptions handlers (gdb) r Starting program: /tmp/foo By doing so, when running Foo, gdb will stop here: Catchpoint 1, exception at 0x000000000040255a in foo () at foo.adb:25 25 when Constraint_Error => (gdb) It is also possible to stop when the Constraint_Error exception is being handled in this program. With this patch, we can use: (gdb) catch handlers Constraint_Error Catchpoint 1: `Constraint_Error' Ada exception handlers (gdb) Like for other catchpoint, you can set a condition when adding a catchpoint on exception handlers. Here the handlers catchpoint checks Global_Var: (gdb) catch handlers Constraint_Error if Global_Var /= 0 gdb/ChangeLog: * ada-lang.h (ada_exception_catchpoint_kind) <ada_catch_handlers>: Add field. * ada-lang.c (struct exception_support_info) <catch_handlers_sym>: Add field. (default_exception_support_info) <catch_handlers_sym>: Add field. (exception_support_info_fallback) <catch_handlers_sym>: Add field. (ada_exception_name_addr_1): Add "catch handlers" handling. (ada_exception_catchpoint_cond_string) <ex>: New parameter. Update all callers. (create_excep_cond_exprs) <ex>: Add parameter. (re_set_exception): Update create_excep_cond_exprs call. (print_it_exception, print_one_exception, print_mention_exception) (print_recreate_exception): Add "catch handler" handling. (allocate_location_catch_handlers, re_set_catch_handlers) (check_status_catch_handlers, print_it_catch_handlers) (print_one_catch_handlers, print_mention_catch_handlers) (print_recreate_catch_handlers): New function. (catch_handlers_breakpoint_ops): New variable. (catch_ada_exception_command_split) <is_catch_handlers_cmd>: Add parameter. Add "catch handler" handling. (ada_exception_sym_name, ada_exception_breakpoint_ops): Add "catch handler" handling. (ada_exception_catchpoint_cond_string): Add "catch handler" handling. (create_ada_exception_catchpoint): Update create_excep_cond_exprs call. (catch_ada_handlers_command): New function. (initialize_ada_catchpoint_ops): Initialize "catch handlers" operations structure. (_initialize_ada_language): Add "catch handlers" command entry. * NEWS: Document "catch handlers" feature. gdb/doc/ChangeLog: * gdb.texinfo (Set Catchpoints): Add documentation for new "catch handlers" action. gdb/testsuite/ChangeLog: * gdb.ada/excep_handle.exp: New testcase. * gdb.ada/excep_handle/foo.adb: New file. * gdb.ada/excep_handle/pck.ads: New file. Tested on x86_64-linux.
Diffstat (limited to 'gdb/testsuite/gdb.ada')
-rw-r--r--gdb/testsuite/gdb.ada/excep_handle.exp171
-rw-r--r--gdb/testsuite/gdb.ada/excep_handle/foo.adb103
-rw-r--r--gdb/testsuite/gdb.ada/excep_handle/pck.ads19
3 files changed, 293 insertions, 0 deletions
diff --git a/gdb/testsuite/gdb.ada/excep_handle.exp b/gdb/testsuite/gdb.ada/excep_handle.exp
new file mode 100644
index 0000000000..c693fd30ea
--- /dev/null
+++ b/gdb/testsuite/gdb.ada/excep_handle.exp
@@ -0,0 +1,171 @@
+# Copyright 2018 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/>.
+
+load_lib "ada.exp"
+
+standard_ada_testfile foo
+
+if {[gdb_compile_ada "${srcfile}" "${binfile}" executable [list debug additional_flags=-gnata ]] != "" } {
+ return -1
+}
+
+clean_restart ${testfile}
+
+# Some global variables used to simplify the maintenance of some of
+# the regular expressions below.
+set eol "\[\r\n\]+"
+set sp "\[ \t\]*"
+
+set when "when"
+set catchpoint_constraint_error_msg \
+ "Catchpoint $decimal, exception at $hex in foo \\\(\\\).*at .*foo.adb:$decimal$eol$decimal$sp$when Constraint_Error =>"
+
+set catchpoint_program_error_msg \
+ "Catchpoint $decimal, exception at $hex in foo \\\(\\\).*at .*foo.adb:$decimal$eol$decimal$sp$when Program_Error =>"
+
+set catchpoint_storage_error_msg \
+ "Catchpoint $decimal, exception at $hex in foo \\\(\\\).*at .*foo.adb:$decimal$eol$decimal$sp$when Storage_Error =>"
+
+############################################
+# Check that runtime supports catchpoint. #
+############################################
+
+if ![runto_main] then {
+ fail "Cannot run to main, testcase aborted"
+ return 0
+}
+
+set msg "insert catchpoint on all Ada exceptions handlers"
+gdb_test_multiple "catch handlers" $msg {
+ -re "Catchpoint $decimal: all Ada exceptions handlers$eol$gdb_prompt $" {
+ pass $msg
+ }
+ -re "Your Ada runtime appears to be missing some debugging information.*$eol$gdb_prompt $" {
+ # If the runtime was not built with enough debug information,
+ # or if it was stripped, we can not test exception handlers
+ # catchpoints.
+ unsupported $msg
+ return -1
+ }
+}
+
+############################################
+# 1. Try catching all exceptions handlers. #
+############################################
+
+# Continue. The program should stop at first exception handling.
+
+gdb_test "continue" \
+ "Continuing\.$eol$catchpoint_constraint_error_msg$eol.*" \
+ "continuing to first Constraint_Error exception handlers"
+
+# Resume the program's exception.
+#
+# The program will first go through a block of code which has an
+# exception handler, but since no exception is raised, we should
+# not stop there. Instead, we expect to stop in the handler of
+# the next exception being raised.
+
+gdb_test "continue" \
+ "Continuing\.$eol$catchpoint_storage_error_msg$eol.*" \
+ "continuing and stopping in Storage_Error exception handlers"
+
+gdb_test_no_output "delete 2" \
+ "delete catchpoint on all Ada exceptions handlers"
+
+##################################################
+# 2. Try catching some named exception handlers. #
+##################################################
+
+# Insert a catchpoint on Program_Error Ada exception handlers.
+
+gdb_test "catch handlers Program_Error" \
+ "Catchpoint $decimal: `Program_Error' Ada exception handlers" \
+ "insert catchpoint on Program_Error Ada exception handlers"
+
+# Continue, we should not stop at ABORT_SIGNAL but at Program_Error one.
+
+gdb_test "continue" \
+ "Continuing\.$eol$catchpoint_program_error_msg$eol.*" \
+ "continuing without stopping to Program_Error exception handlers"
+
+gdb_test_no_output \
+ "delete 3" \
+ "delete catchpoint on all Program_Error Ada exception handlers"
+
+# Insert a catchpoint on Storage_Error Ada exception handlers.
+
+gdb_test "catch handlers Storage_Error" \
+ "Catchpoint $decimal: `Storage_Error' Ada exception handlers" \
+ "insert catchpoint on Storage_Error Ada exception handlers"
+
+# Continue, we should stop at Storage_Error handlers.
+
+gdb_test "continue" \
+ "Continuing\.$eol$catchpoint_storage_error_msg$eol.*" \
+ "continuing without stopping to Storage_Error exception handlers"
+
+gdb_test_no_output \
+ "delete 4" \
+ "delete catchpoint on all Storage_Error Ada exception handlers"
+
+########################################################################
+# 3. Try catching with condition and without named exception handlers. #
+########################################################################
+
+# Insert a catchpoint on all Ada exceptions handlers with condition.
+
+gdb_test "catch handlers if Global_Var = 2" \
+ "Catchpoint $decimal: all Ada exceptions handlers" \
+ "insert catchpoint on all Ada exception handlers with condition"
+
+# Check that condition is stored and properly displayed.
+
+gdb_test "info breakpoint" "stop only if Global_Var = 2" \
+ "Check catch handlers with condition"
+
+# Continue, we should not stop at ABORT_SIGNAL but at Program_Error one.
+
+gdb_test "continue" \
+ "Continuing\.$eol$catchpoint_constraint_error_msg$eol.*" \
+ "continuing to second Constraint_Error exception handlers"
+
+gdb_test_no_output \
+ "delete 5" \
+ "delete catchpoint on all all Ada exceptions handlers with condition"
+
+################################################################
+# 4. Try catching with condition and named exception handlers. #
+################################################################
+
+# Insert a catchpoint on Program_Error Ada exception handlers with
+# condition.
+
+gdb_test "catch handlers Program_Error if Global_Var = 4" \
+ "Catchpoint $decimal: `Program_Error' Ada exception handlers" \
+ "insert catchpoint on Program_Error Ada exception handlers with condition"
+
+# Continue, we should not stop at first Program_Error handlers but at
+# the second one.
+
+gdb_test "continue" \
+ "Continuing\.$eol$catchpoint_program_error_msg$eol.*" \
+ "continuing to Program_Error exception handlers"
+
+# Continue, the program should exit properly.
+
+gdb_test "continue" \
+ "Continuing\..*$inferior_exited_re.*" \
+ "continuing to program completion"
diff --git a/gdb/testsuite/gdb.ada/excep_handle/foo.adb b/gdb/testsuite/gdb.ada/excep_handle/foo.adb
new file mode 100644
index 0000000000..93c684347a
--- /dev/null
+++ b/gdb/testsuite/gdb.ada/excep_handle/foo.adb
@@ -0,0 +1,103 @@
+-- Copyright 2018 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/>.
+
+with Pck; use Pck;
+
+procedure Foo is
+begin
+
+ -- Part 1 of the testcase
+
+ begin
+ raise Constraint_Error;
+ exception
+ when Constraint_Error =>
+ null;
+ end;
+
+ begin
+ null;
+ exception
+ when others =>
+ null;
+ end;
+
+ begin
+ raise Storage_Error;
+ exception
+ when Storage_Error =>
+ null;
+ end;
+
+ -- Part 2 of the testcase
+
+ begin
+ raise ABORT_SIGNAL;
+ exception
+ when others =>
+ null;
+ end;
+
+ begin
+ raise Program_Error;
+ exception
+ when Program_Error =>
+ null;
+ end;
+
+ begin
+ raise Storage_Error;
+ exception
+ when Storage_Error =>
+ null;
+ end;
+
+ -- Part 3 of the testcase
+
+ begin
+ Global_Var := Global_Var + 1;
+ raise ABORT_SIGNAL;
+ exception
+ when others =>
+ null;
+ end;
+
+ begin
+ Global_Var := Global_Var + 1;
+ raise Constraint_Error;
+ exception
+ when Constraint_Error =>
+ null;
+ end;
+
+ -- Part 4 of the testcase
+
+ begin
+ Global_Var := Global_Var + 1;
+ raise Program_Error;
+ exception
+ when others =>
+ null;
+ end;
+
+ begin
+ Global_Var := Global_Var + 1;
+ raise Program_Error;
+ exception
+ when Program_Error =>
+ null;
+ end;
+
+end Foo;
diff --git a/gdb/testsuite/gdb.ada/excep_handle/pck.ads b/gdb/testsuite/gdb.ada/excep_handle/pck.ads
new file mode 100644
index 0000000000..6a7cf084d8
--- /dev/null
+++ b/gdb/testsuite/gdb.ada/excep_handle/pck.ads
@@ -0,0 +1,19 @@
+-- Copyright 2018 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/>.
+
+package Pck is
+ Global_Var : Integer := 0;
+ ABORT_SIGNAL : exception;
+end Pck;