catch_assert_if.exp 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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 bla
  18. if {[gdb_compile_ada "${srcfile}" "${binfile}" executable [list debug additional_flags=-gnata ]] != "" } {
  19. return -1
  20. }
  21. clean_restart ${testfile}
  22. ######################################################################
  23. # 1. Try catching all exceptions to check that runtime supports it. #
  24. ######################################################################
  25. set eol "\[\r\n\]+"
  26. set sp "\[ \t\]*"
  27. if ![runto_main] then {
  28. return 0
  29. }
  30. set msg "insert catchpoint on all Ada exceptions"
  31. gdb_test_multiple "catch exception" $msg {
  32. -re "Catchpoint $decimal: all Ada exceptions$eol$gdb_prompt $" {
  33. pass $msg
  34. }
  35. -re "Your Ada runtime appears to be missing some debugging information.*$eol$gdb_prompt $" {
  36. # If the runtime was not built with enough debug information,
  37. # or if it was stripped, we can not test exception
  38. # catchpoints.
  39. unsupported $msg
  40. return -1
  41. }
  42. }
  43. ##################################################
  44. # 2. Try catching conditional failed assertion. #
  45. ##################################################
  46. # Here is the scenario:
  47. # - Restart the debugger from scratch, runto_main
  48. # We'll catch assertions if Global_Var = 2
  49. # - continue, we should see the second failed assertion
  50. # - continue, the program exits.
  51. if ![runto_main] then {
  52. return 0
  53. }
  54. gdb_test "catch assert if Global_Var = 2" \
  55. "Catchpoint $decimal: failed Ada assertions" \
  56. "insert catchpoint on failed assertions with condition"
  57. # Check that condition is stored and properly displayed.
  58. set exp_bp ".*$decimal${sp}catchpoint${sp}keep${sp}y${sp}failed Ada assertions$eol${sp}stop only if Global_Var = 2.*"
  59. gdb_test "info breakpoint" $exp_bp "Check catch assertions with condition"
  60. set bp_location [gdb_get_line_number "STOP" ${testdir}/bla.adb]
  61. set catchpoint_msg \
  62. "Catchpoint $decimal, failed assertion at $hex in bla \\\(\\\).*at .*bla.adb:$bp_location"
  63. gdb_test "continue" \
  64. "Continuing\.$eol$catchpoint_msg$eol.*STOP" \
  65. "continuing to expected failed assertion"
  66. gdb_test "continue" \
  67. "Continuing\..*$inferior_exited_re.*" \
  68. "continuing to program completion"