1 # Copyright 2017-2024 Free Software Foundation, Inc.
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.
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.
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/>.
16 # Test the symbol needs check mechanism if it assumes that faking
17 # reads from a target is a safe thing to do.
19 # In particular, the test uses a relative branch DWARF operation to
20 # hide a register read. If the target reads are indeed faked, the
21 # result returned will be wrong.
25 # This test can only be run on targets which support DWARF-2 and use gas.
26 require dwarf2_support
28 # Choose suitable integer registers for the test.
32 if { [is_aarch64_target] } {
34 } elseif { [is_aarch32_target]
35 || [istarget "s390*-*-*" ]
36 || [istarget "powerpc*-*-*"]
37 || [istarget "rs6000*-*-aix*"] } {
39 } elseif { [is_x86_like_target] } {
41 } elseif { [is_amd64_regs_target] } {
44 verbose "Skipping ${gdb_test_file_name}."
48 standard_testfile symbol_needs_eval.c ${gdb_test_file_name}-dw.S
50 if [prepare_for_testing "failed to prepare" $testfile $srcfile {debug}] {
54 set int_size [get_sizeof "int" -1]
56 # Make some DWARF for the test.
58 set asm_file [standard_output_file $srcfile2]
59 Dwarf::assemble $asm_file {
60 global dwarf_regnum regname int_size
62 set exec_mask_var [gdb_target_symbol exec_mask]
66 {DW_AT_name symbol_needs_eval.c}
69 declare_labels int_type_label
72 int_type_label: DW_TAG_base_type {
74 {DW_AT_encoding @DW_ATE_signed}
75 {DW_AT_byte_size $int_size DW_FORM_sdata}
78 # define artificial variable a
81 {DW_AT_type :$int_type_label}
83 DW_OP_addr $exec_mask_var
84 DW_OP_deref_size $int_size
86 # conditional jump to DW_OP_bregx
90 # jump to DW_OP_stack_value
92 DW_OP_bregx $dwarf_regnum 0
101 if { [prepare_for_testing ${testfile}.exp ${testfile} \
102 [list $srcfile $asm_file] {nodebug}] } {
106 # The variable's location expression requires a frame,
107 # so an error should be reported.
108 gdb_test "print/d a" "No frame selected." "variable a can't be printed"
114 gdb_test_no_output "set var \$$regname = 2" "init reg to 2"
116 gdb_test "print/d a" " = 2" "a == 2"