formatted_ref.exp 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. # Copyright 2007-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. # Author: P. N. Hilfinger, AdaCore Inc.
  16. # Note: This test is essentially a transcription of gdb.cp/formatted-ref.exp,
  17. # and is thus much more wordy than it needs to be. There are fewer
  18. # tests because only a few parameter types in Ada are required to be
  19. # passed by reference, and there is no equivalent of &(&x) for reference
  20. # values.
  21. # This also tests that some other arithmetic operations on references
  22. # work properly: condition expression using a reference object as one of its
  23. # operand.
  24. load_lib "ada.exp"
  25. if { [skip_ada_tests] } { return -1 }
  26. standard_ada_testfile formatted_ref
  27. if {[gdb_compile_ada "${srcfile}" "${binfile}" executable [list debug ]] != "" } {
  28. untested formatted-ref.exp
  29. return -1
  30. }
  31. proc get_address { var } {
  32. global expect_out
  33. global gdb_prompt
  34. gdb_test_multiple "print $var'access" "address of $var" {
  35. -re "\\$\[0-9\]+ = \\(.*\\) (0x\[0-9a-f\]+).*$gdb_prompt $" {
  36. return $expect_out(1,string)
  37. }
  38. }
  39. perror "couldn't find address of $var"
  40. return ""
  41. }
  42. proc test_p_x { var val addr } {
  43. global gdb_prompt
  44. set test "print/x $var"
  45. gdb_test_multiple "$test" $test {
  46. -re "\\$\[0-9\]+ = [string_to_regexp $val].*$gdb_prompt $" {
  47. pass $test
  48. }
  49. -re "\\$\[0-9\]+ = $addr.*$gdb_prompt $" {
  50. fail "$test (prints just address)"
  51. }
  52. -re "\\$\[0-9\]+ = 0x\[a-f0-9\]+.*$gdb_prompt $" {
  53. fail "$test (prints unexpected address)"
  54. }
  55. }
  56. return 0
  57. }
  58. proc test_p_x_addr { var addr } {
  59. global gdb_prompt
  60. foreach attr {access unchecked_access unrestricted_access} {
  61. foreach space {"" " "} {
  62. set test "print/x $var'$space$attr"
  63. gdb_test_multiple $test $test {
  64. -re "\\$\[0-9\]+ = $addr.*$gdb_prompt $" {
  65. pass $test
  66. }
  67. -re "\\$\[0-9\]+ = 0x\[a-f0-9+\]+.*$gdb_prompt $" {
  68. fail "$test (prints unexpected address)"
  69. }
  70. }
  71. }
  72. }
  73. gdb_test "complete print/x $var'unres" "print/x $var'unrestricted_access"
  74. gdb_test_no_output "complete print/x $var'abcd"
  75. gdb_test "complete print $var'f" "print $var'first"
  76. return 0
  77. }
  78. proc test_p_op1_equals_op2 {op1 op2} {
  79. set test "print $op1 = $op2"
  80. gdb_test $test "\\$\[0-9\]+ = true"
  81. }
  82. clean_restart ${testfile}
  83. set bp_location \
  84. defs.adb:[gdb_get_line_number "marker here" ${testdir}/defs.adb]
  85. # Workaround gcc PR101575.
  86. #runto $bp_location
  87. gdb_breakpoint "$bp_location"
  88. gdb_run_cmd
  89. set re "Breakpoint $decimal, defs.f1 \\(.*\\) at .*:$decimal.*"
  90. set re_xfail "Breakpoint $decimal, defs__struct1IP \\(\\) at .*:$decimal.*"
  91. set ok 1
  92. gdb_test_multiple "" "Runto to $bp_location" {
  93. -re -wrap $re {
  94. if { $ok } {
  95. pass $gdb_test_name
  96. } else {
  97. xfail $gdb_test_name
  98. }
  99. }
  100. -re -wrap $re_xfail {
  101. set ok 0
  102. send_gdb "continue\n"
  103. exp_continue
  104. }
  105. }
  106. set s1_address [get_address "s1"]
  107. test_p_x "s" "(x => 0xd, y => 0x13)" $s1_address
  108. test_p_x_addr "s" $s1_address
  109. test_p_op1_equals_op2 "s.x" "13"