pieces.exp 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. # Copyright 2010-2022 Free Software Foundation, Inc.
  2. # This program is free software; you can redistribute it and/or modify
  3. # it under the terms of the GNU General Public License as published by
  4. # the Free Software Foundation; either version 3 of the License, or
  5. # (at your option) any later version.
  6. #
  7. # This program is distributed in the hope that it will be useful,
  8. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. # GNU General Public License for more details.
  11. #
  12. # You should have received a copy of the GNU General Public License
  13. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  14. load_lib dwarf.exp
  15. # Test some DWARF piece operators.
  16. # This test can only be run on targets which support DWARF-2 and use gas.
  17. if {![dwarf2_support]} {
  18. return 0
  19. }
  20. # This test can only be run on x86 targets.
  21. if {![is_x86_like_target]} {
  22. return 0
  23. }
  24. standard_testfile .S
  25. set csrcfile ${testfile}.c
  26. if {[prepare_for_testing "failed to prepare" ${testfile} $srcfile]} {
  27. return -1
  28. }
  29. if ![runto_main] {
  30. return -1
  31. }
  32. # Function f1 tests a particular gdb bug involving DW_OP_piece.
  33. proc pieces_test_f1 {} {
  34. global csrcfile
  35. set line [gdb_get_line_number "f1 breakpoint" $csrcfile]
  36. gdb_test "break pieces.c:$line" "Breakpoint 2.*" \
  37. "set f1 breakpoint for pieces"
  38. gdb_continue_to_breakpoint "continue to f1 breakpoint for pieces"
  39. gdb_test "print a" " = {i = 4, j = 14}" "print a in pieces:f1"
  40. gdb_test "print a.j" " = 14" "print a.j in pieces:f1"
  41. }
  42. # Function f2 tests for a bug when indexing into an array created
  43. # using DW_OP_piece.
  44. proc pieces_test_f2 {} {
  45. global csrcfile
  46. set line [gdb_get_line_number "f2 breakpoint" $csrcfile]
  47. gdb_test "break pieces.c:$line" "Breakpoint 3.*" \
  48. "set f2 breakpoint for pieces"
  49. gdb_continue_to_breakpoint "continue to f2 breakpoint for pieces"
  50. gdb_test "print a" " = .4, 14." "print a in pieces:f2"
  51. gdb_test "print a\[0\]" " = 4" "print a\[0\] in pieces:f2"
  52. gdb_test "print a\[1\]" " = 14" "print a\[1\] in pieces:f2"
  53. }
  54. # Function f3 tests DW_OP_bit_piece.
  55. proc pieces_test_f3 {} {
  56. global csrcfile
  57. set line [gdb_get_line_number "f3 breakpoint" $csrcfile]
  58. gdb_test "break pieces.c:$line" "Breakpoint 4.*" \
  59. "set f3 breakpoint for pieces"
  60. gdb_continue_to_breakpoint "continue to f3 breakpoint for pieces"
  61. gdb_test "print a.i" " = 4" "print a.i in pieces:f3"
  62. gdb_test "print a.j" " = 14" "print a.j in pieces:f3"
  63. gdb_test "print a.i = 7" " = 7" "set a.i in pieces:f3"
  64. gdb_test "print a.i" " = 7" "print new a.i in pieces:f3"
  65. }
  66. # Function f6 tests for an empty DW_OP_piece.
  67. proc pieces_test_f6 {} {
  68. global csrcfile
  69. set line [gdb_get_line_number "f6 breakpoint" $csrcfile]
  70. gdb_test "break pieces.c:$line" "Breakpoint 5.*" \
  71. "set f6 breakpoint for pieces"
  72. gdb_continue_to_breakpoint "continue to f6 breakpoint for pieces"
  73. gdb_test "print a" \
  74. " = {i = 7, j = 8, q = .optimized out.}" \
  75. "print a with optimized out piece"
  76. # Note: no warning for this case.
  77. gdb_test_multiple "print a.i" \
  78. "print a.i with optimized out piece" {
  79. -re "warning: some bits in computed object" {
  80. fail "print a.i with optimized out piece"
  81. }
  82. -re " = 7" {
  83. pass "print a.i with optimized out piece"
  84. }
  85. }
  86. }
  87. pieces_test_f1
  88. pieces_test_f2
  89. pieces_test_f3
  90. pieces_test_f6