]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/testsuite/gdb.dwarf2/symbol_needs_eval_fail.exp
Update copyright year range in header of all files managed by GDB
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.dwarf2 / symbol_needs_eval_fail.exp
1 # Copyright 2017-2024 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
16 # Test the symbol needs check mechanism if it assumes that faking
17 # reads from a target is a safe thing to do.
18 #
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.
22
23 load_lib dwarf.exp
24
25 # This test can only be run on targets which support DWARF-2 and use gas.
26 require dwarf2_support
27
28 # Choose suitable integer registers for the test.
29
30 set dwarf_regnum 0
31
32 if { [is_aarch64_target] } {
33 set regname x0
34 } elseif { [is_aarch32_target]
35 || [istarget "s390*-*-*" ]
36 || [istarget "powerpc*-*-*"]
37 || [istarget "rs6000*-*-aix*"] } {
38 set regname r0
39 } elseif { [is_x86_like_target] } {
40 set regname eax
41 } elseif { [is_amd64_regs_target] } {
42 set regname rax
43 } else {
44 verbose "Skipping ${gdb_test_file_name}."
45 return
46 }
47
48 standard_testfile symbol_needs_eval.c ${gdb_test_file_name}-dw.S
49
50 if [prepare_for_testing "failed to prepare" $testfile $srcfile {debug}] {
51 return
52 }
53
54 set int_size [get_sizeof "int" -1]
55
56 # Make some DWARF for the test.
57
58 set asm_file [standard_output_file $srcfile2]
59 Dwarf::assemble $asm_file {
60 global dwarf_regnum regname int_size
61
62 set exec_mask_var [gdb_target_symbol exec_mask]
63
64 cu {} {
65 DW_TAG_compile_unit {
66 {DW_AT_name symbol_needs_eval.c}
67 {DW_AT_comp_dir /tmp}
68 } {
69 declare_labels int_type_label
70
71 # define int type
72 int_type_label: DW_TAG_base_type {
73 {DW_AT_name "int"}
74 {DW_AT_encoding @DW_ATE_signed}
75 {DW_AT_byte_size $int_size DW_FORM_sdata}
76 }
77
78 # define artificial variable a
79 DW_TAG_variable {
80 {DW_AT_name a}
81 {DW_AT_type :$int_type_label}
82 {DW_AT_location {
83 DW_OP_addr $exec_mask_var
84 DW_OP_deref_size $int_size
85
86 # conditional jump to DW_OP_bregx
87 DW_OP_bra 4
88 DW_OP_lit0
89
90 # jump to DW_OP_stack_value
91 DW_OP_skip 3
92 DW_OP_bregx $dwarf_regnum 0
93 DW_OP_stack_value
94 } SPECIAL_expr}
95 {external 1 flag}
96 }
97 }
98 }
99 }
100
101 if { [prepare_for_testing ${testfile}.exp ${testfile} \
102 [list $srcfile $asm_file] {nodebug}] } {
103 return -1
104 }
105
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"
109
110 if ![runto_main] {
111 return -1
112 }
113
114 gdb_test_no_output "set var \$$regname = 2" "init reg to 2"
115
116 gdb_test "print/d a" " = 2" "a == 2"