symbol_needs_eval_fail.exp 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. # Copyright 2017-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. # Test the symbol needs check mechanism if it assumes that faking
  15. # reads from a target is a safe thing to do.
  16. #
  17. # In particular, the test uses a relative branch DWARF operation to
  18. # hide a register read. If the target reads are indeed faked, the
  19. # result returned will be wrong.
  20. load_lib dwarf.exp
  21. # This test can only be run on targets which support DWARF-2 and use gas.
  22. if {![dwarf2_support]} {
  23. return 0
  24. }
  25. # Choose suitable integer registers for the test.
  26. set dwarf_regnum 0
  27. if { [is_aarch64_target] } {
  28. set regname x0
  29. } elseif { [is_aarch32_target]
  30. || [istarget "s390*-*-*" ]
  31. || [istarget "powerpc*-*-*"]
  32. || [istarget "rs6000*-*-aix*"] } {
  33. set regname r0
  34. } elseif { [is_x86_like_target] } {
  35. set regname eax
  36. } elseif { [is_amd64_regs_target] } {
  37. set regname rax
  38. } else {
  39. verbose "Skipping ${gdb_test_file_name}."
  40. return
  41. }
  42. standard_testfile symbol_needs_eval.c ${gdb_test_file_name}-dw.S
  43. # Make some DWARF for the test.
  44. set asm_file [standard_output_file $srcfile2]
  45. Dwarf::assemble $asm_file {
  46. global dwarf_regnum regname
  47. set exec_mask_var [gdb_target_symbol exec_mask]
  48. cu {} {
  49. DW_TAG_compile_unit {
  50. {DW_AT_name symbol_needs_eval.c}
  51. {DW_AT_comp_dir /tmp}
  52. } {
  53. declare_labels int_type_label
  54. # define int type
  55. int_type_label: DW_TAG_base_type {
  56. {DW_AT_name "int"}
  57. {DW_AT_encoding @DW_ATE_signed}
  58. {DW_AT_byte_size 4 DW_FORM_sdata}
  59. }
  60. # define artificial variable a
  61. DW_TAG_variable {
  62. {DW_AT_name a}
  63. {DW_AT_type :$int_type_label}
  64. {DW_AT_location {
  65. DW_OP_addr $exec_mask_var
  66. DW_OP_deref
  67. # conditional jump to DW_OP_bregx
  68. DW_OP_bra 4
  69. DW_OP_lit0
  70. # jump to DW_OP_stack_value
  71. DW_OP_skip 3
  72. DW_OP_bregx $dwarf_regnum 0
  73. DW_OP_stack_value
  74. } SPECIAL_expr}
  75. {external 1 flag}
  76. }
  77. }
  78. }
  79. }
  80. if { [prepare_for_testing ${testfile}.exp ${testfile} \
  81. [list $srcfile $asm_file] {nodebug}] } {
  82. return -1
  83. }
  84. # The variable's location expression requires a frame,
  85. # so an error should be reported.
  86. gdb_test "print/d a" "No frame selected." "variable a can't be printed"
  87. if ![runto_main] {
  88. return -1
  89. }
  90. gdb_test_no_output "set var \$$regname = 2" "init reg to 2"
  91. gdb_test "print/d a" " = 2" "a == 2"