mi_catch_ex_hand.exp 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. # Copyright 2011-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. # A global variable used to simplify the maintenance of some of
  22. # the regular expressions below.
  23. set eol "\[\r\n\]+"
  24. # Before going any further, verify that we can insert exception
  25. # handlers catchpoints... That way, we won't have to do this while
  26. # doing the actual GDB/MI testing.
  27. clean_restart ${testfile}
  28. if ![runto_main] then {
  29. return 0
  30. }
  31. set msg "insert catchpoint on all Ada exceptions handlers"
  32. gdb_test_multiple "catch handlers" $msg {
  33. -re "Catchpoint $decimal: all Ada exceptions handlers$eol$gdb_prompt $" {
  34. pass $msg
  35. }
  36. -re "Your Ada runtime appears to be missing some debugging information.*\[\r\n\]+$gdb_prompt $" {
  37. # If the runtime was not built with enough debug information,
  38. # or if it was stripped, we can not test exception
  39. # catchpoints.
  40. unsupported $msg
  41. return -1
  42. }
  43. }
  44. # Now, we can start the GDB/MI testing itself...
  45. load_lib mi-support.exp
  46. set MIFLAGS "-i=mi"
  47. mi_clean_restart $binfile
  48. #############################################
  49. # 1. Try catching all exceptions handlers. #
  50. #############################################
  51. with_test_prefix "scenario 1" {
  52. if {[mi_runto_main] < 0} {
  53. return 0
  54. }
  55. }
  56. mi_gdb_test "-catch-handlers" \
  57. "\\^done,bkptno=\"$decimal\",bkpt={.*disp=\"keep\",enabled=\"y\",what=\"all Ada exceptions handlers\",.*}" \
  58. "catch all exceptions handlers"
  59. # Continue to exception handler.
  60. proc continue_to_exception_handler { test line } {
  61. global decimal
  62. mi_send_resuming_command "exec-continue" "$test"
  63. # Now MI stream output.
  64. mi_expect_stop \
  65. "breakpoint-hit\",disp=\"keep\",bkptno=\"$decimal\",exception-name=\"exception\"?" \
  66. "foo" "" ".*" "$line" \
  67. ".*" \
  68. $test
  69. }
  70. # We don't have the exception name info when stopping at the exception handlers
  71. # catchpoints so we use source line to check if the inferior stops at the
  72. # right location.
  73. set bp_ce_location [gdb_get_line_number "BREAK1" ${testdir}/foo.adb]
  74. continue_to_exception_handler \
  75. "continue until CE handling caught by all-exceptions handlers catchpoint" \
  76. "$bp_ce_location"
  77. set bp_pe_location [gdb_get_line_number "BREAK2" ${testdir}/foo.adb]
  78. continue_to_exception_handler \
  79. "continue until PE handling caught by all-exceptions handlers catchpoint" \
  80. "$bp_pe_location"
  81. ##########################################################
  82. # 2. Try catching only some of the exceptions handlers. #
  83. ##########################################################
  84. # Here is the scenario:
  85. # - Restart the debugger from scratch, runto_main
  86. # - We'll catch only "Constraint_Error handlers"
  87. # - continue, we should stop at the Constraint_Error exception handler
  88. # - continue, we should not stop at the Program_Error exception handler
  89. # but exit instead.
  90. with_test_prefix "scenario 2" {
  91. mi_delete_breakpoints
  92. if {[mi_runto_main] < 0} {
  93. return 0
  94. }
  95. }
  96. mi_gdb_test "-catch-handlers -e Constraint_Error" \
  97. "\\^done,bkptno=\"$decimal\",bkpt={.*disp=\"keep\",enabled=\"y\",what=\"`Constraint_Error' Ada exception handlers\",.*}" \
  98. "catch Constraint_Error"
  99. mi_execute_to "exec-continue" \
  100. "breakpoint-hit\",disp=\"keep\",bkptno=\"$decimal\",exception-name=\"exception\"?" \
  101. "foo" "" ".*" "$bp_ce_location" \
  102. ".*" \
  103. "continue to exception catchpoint hit"
  104. # Exit the inferior.
  105. mi_send_resuming_command "exec-continue" "continuing to inferior exit"
  106. mi_expect_stop "exited-normally" "" "" "" "" "" "exit normally"
  107. mi_gdb_exit
  108. return 0