binutils-gdb/gdb/testsuite/gdb.ada/excep_handle.exp
Xavier Roirand 9f757bf7fc (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.
2018-01-03 11:02:53 +01:00

172 lines
6.1 KiB
Plaintext

# 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"