excep_handle.exp 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. # Copyright 2018-2022 Free Software Foundation, Inc.
  2. #
  3. # This program is free software; you can redistribute it and/or modify
  4. # it under the terms of the GNU General Public License as published by
  5. # the Free Software Foundation; either version 3 of the License, or
  6. # (at your option) any later version.
  7. #
  8. # This program is distributed in the hope that it will be useful,
  9. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. # GNU General Public License for more details.
  12. #
  13. # You should have received a copy of the GNU General Public License
  14. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. load_lib "ada.exp"
  16. if { [skip_ada_tests] } { return -1 }
  17. standard_ada_testfile foo
  18. if {[gdb_compile_ada "${srcfile}" "${binfile}" executable [list debug additional_flags=-gnata ]] != "" } {
  19. return -1
  20. }
  21. clean_restart ${testfile}
  22. # Some global variables used to simplify the maintenance of some of
  23. # the regular expressions below.
  24. set eol "\[\r\n\]+"
  25. set sp "\[ \t\]*"
  26. set when "when"
  27. set catchpoint_constraint_error_msg \
  28. "Catchpoint $decimal, exception at $hex in foo \\\(\\\).*at .*foo.adb:$decimal$eol$decimal$sp$when Constraint_Error =>"
  29. set catchpoint_program_error_msg \
  30. "Catchpoint $decimal, exception at $hex in foo \\\(\\\).*at .*foo.adb:$decimal$eol$decimal$sp$when Program_Error =>"
  31. set catchpoint_storage_error_msg \
  32. "Catchpoint $decimal, exception at $hex in foo \\\(\\\).*at .*foo.adb:$decimal$eol$decimal$sp$when Storage_Error =>"
  33. ############################################
  34. # Check that runtime supports catchpoint. #
  35. ############################################
  36. if ![runto_main] then {
  37. return 0
  38. }
  39. set msg "insert catchpoint on all Ada exceptions handlers"
  40. gdb_test_multiple "catch handlers" $msg {
  41. -re "Catchpoint $decimal: all Ada exceptions handlers$eol$gdb_prompt $" {
  42. pass $msg
  43. }
  44. -re "Your Ada runtime appears to be missing some debugging information.*$eol$gdb_prompt $" {
  45. # If the runtime was not built with enough debug information,
  46. # or if it was stripped, we can not test exception handlers
  47. # catchpoints.
  48. unsupported $msg
  49. return -1
  50. }
  51. }
  52. ############################################
  53. # 1. Try catching all exceptions handlers. #
  54. ############################################
  55. # Continue. The program should stop at first exception handling.
  56. gdb_test "continue" \
  57. "Continuing\.$eol$catchpoint_constraint_error_msg$eol.*" \
  58. "continuing to first Constraint_Error exception handlers"
  59. # Resume the program's exception.
  60. #
  61. # The program will first go through a block of code which has an
  62. # exception handler, but since no exception is raised, we should
  63. # not stop there. Instead, we expect to stop in the handler of
  64. # the next exception being raised.
  65. gdb_test "continue" \
  66. "Continuing\.$eol$catchpoint_storage_error_msg$eol.*" \
  67. "continuing and stopping in Storage_Error exception handlers"
  68. gdb_test_no_output "delete 2" \
  69. "delete catchpoint on all Ada exceptions handlers"
  70. ##################################################
  71. # 2. Try catching some named exception handlers. #
  72. ##################################################
  73. # Insert a catchpoint on Program_Error Ada exception handlers.
  74. gdb_test "catch handlers Program_Error" \
  75. "Catchpoint $decimal: `Program_Error' Ada exception handlers" \
  76. "insert catchpoint on Program_Error Ada exception handlers"
  77. # Continue, we should not stop at ABORT_SIGNAL but at Program_Error one.
  78. gdb_test "continue" \
  79. "Continuing\.$eol$catchpoint_program_error_msg$eol.*" \
  80. "continuing without stopping to Program_Error exception handlers"
  81. gdb_test_no_output \
  82. "delete 3" \
  83. "delete catchpoint on all Program_Error Ada exception handlers"
  84. # Insert a catchpoint on Storage_Error Ada exception handlers.
  85. gdb_test "catch handlers Storage_Error" \
  86. "Catchpoint $decimal: `Storage_Error' Ada exception handlers" \
  87. "insert catchpoint on Storage_Error Ada exception handlers"
  88. # Continue, we should stop at Storage_Error handlers.
  89. gdb_test "continue" \
  90. "Continuing\.$eol$catchpoint_storage_error_msg$eol.*" \
  91. "continuing without stopping to Storage_Error exception handlers"
  92. gdb_test_no_output \
  93. "delete 4" \
  94. "delete catchpoint on all Storage_Error Ada exception handlers"
  95. ########################################################################
  96. # 3. Try catching with condition and without named exception handlers. #
  97. ########################################################################
  98. # Insert a catchpoint on all Ada exceptions handlers with condition.
  99. gdb_test "catch handlers if Global_Var = 2" \
  100. "Catchpoint $decimal: all Ada exceptions handlers" \
  101. "insert catchpoint on all Ada exception handlers with condition"
  102. # Check that condition is stored and properly displayed.
  103. gdb_test "info breakpoint" "stop only if Global_Var = 2" \
  104. "Check catch handlers with condition"
  105. # Continue, we should not stop at ABORT_SIGNAL but at Program_Error one.
  106. gdb_test "continue" \
  107. "Continuing\.$eol$catchpoint_constraint_error_msg$eol.*" \
  108. "continuing to second Constraint_Error exception handlers"
  109. gdb_test_no_output \
  110. "delete 5" \
  111. "delete catchpoint on all all Ada exceptions handlers with condition"
  112. ################################################################
  113. # 4. Try catching with condition and named exception handlers. #
  114. ################################################################
  115. # Insert a catchpoint on Program_Error Ada exception handlers with
  116. # condition.
  117. gdb_test "catch handlers Program_Error if Global_Var = 4" \
  118. "Catchpoint $decimal: `Program_Error' Ada exception handlers" \
  119. "insert catchpoint on Program_Error Ada exception handlers with condition"
  120. # Continue, we should not stop at first Program_Error handlers but at
  121. # the second one.
  122. gdb_test "continue" \
  123. "Continuing\.$eol$catchpoint_program_error_msg$eol.*" \
  124. "continuing to Program_Error exception handlers"
  125. # Continue, the program should exit properly.
  126. gdb_test "continue" \
  127. "Continuing\..*$inferior_exited_re.*" \
  128. "continuing to program completion"