]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/testsuite/gdb.dwarf2/implptrpiece.exp
Update copyright year range in header of all files managed by GDB
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.dwarf2 / implptrpiece.exp
1 # Copyright 2013-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 load_lib dwarf.exp
17
18 # This test can only be run on targets which support DWARF-2 and use gas.
19 require dwarf2_support
20
21 require allow_cplus_tests
22
23 standard_testfile main.c -dw.S
24
25 # Make some DWARF for the test.
26 set asm_file [standard_output_file $srcfile2]
27
28 Dwarf::assemble $asm_file {
29 # Using a funny address size here and in the pointer type lets us
30 # also check for a sign-extension bug in the
31 # DW_OP_GNU_implicit_pointer code.
32 cu { addr_size 2 } {
33 compile_unit {} {
34 declare_labels struct_label short_type_label
35 declare_labels char_type_label ptr_label
36 declare_labels var_label
37
38 struct_label: structure_type {
39 {name S}
40 {byte_size 4 DW_FORM_sdata}
41 } {
42 member {
43 {name a}
44 {type :$short_type_label}
45 {data_member_location 0 DW_FORM_sdata}
46 }
47 member {
48 {name b}
49 {type :$char_type_label}
50 {data_member_location 2 DW_FORM_sdata}
51 }
52 member {
53 {name c}
54 {type :$char_type_label}
55 {data_member_location 3 DW_FORM_sdata}
56 }
57 }
58
59 short_type_label: base_type {
60 {name "short int"}
61 {encoding @DW_ATE_signed}
62 {byte_size 2 DW_FORM_sdata}
63 }
64
65 char_type_label: base_type {
66 {name "signed char"}
67 {encoding @DW_ATE_signed}
68 {byte_size 1 DW_FORM_sdata}
69 }
70
71 # See comment above to understand the pointer size.
72 ptr_label: pointer_type {
73 {byte_size 2 DW_FORM_sdata}
74 {type :$char_type_label}
75 }
76
77 var_label: DW_TAG_variable {
78 {name s}
79 {type :$struct_label}
80 {location {
81 const2u 0x5678
82 stack_value
83 piece 2
84 const1u 2
85 stack_value
86 piece 1
87 const1u 3
88 stack_value
89 piece 1
90 } SPECIAL_expr}
91 }
92
93 DW_TAG_variable {
94 {name p}
95 {type :$ptr_label}
96 {location {
97 GNU_implicit_pointer $var_label 2
98 } SPECIAL_expr}
99 }
100 }
101 }
102 }
103
104 if { [build_executable ${testfile}.exp ${testfile} \
105 [list $srcfile $asm_file] {nodebug}] } {
106 return -1
107 }
108
109 # We need --readnow because otherwise we never read in the CU we
110 # created above.
111 set saved_gdbflags $GDBFLAGS
112 set GDBFLAGS "$GDBFLAGS -readnow"
113 clean_restart ${testfile}
114 set GDBFLAGS $saved_gdbflags
115
116 if ![runto_main] {
117 return -1
118 }
119
120 # Determine byte order.
121 set endian [get_endianness]
122
123 # Access the second byte of s through an implicit pointer to the third
124 # byte of s, using a negative offset. Compare that to the second byte of
125 # the short integer 0x5678 in target byte order.
126 switch $endian { little {set val 0x56} big {set val 0x78} }
127 gdb_test "p/x p\[-1\]" " = $val"