Add PR check to suggest alternatives to using undef (#118506)
[llvm-project.git] / llvm / test / tools / yaml2obj / ELF / DWARF / debug-loclists.yaml
blobc6c93c68915cd7f2eea9b724fdc6ab13d7084876
1 ## Test that yaml2obj emits a .debug_loclists section when requested.
3 ## a) Generate and verify a little endian DWARF32 .debug_loclists section in a 64-bit object file.
5 # RUN: yaml2obj --docnum=1 -DENDIAN=ELFDATA2LSB %s -o %t1.dwarf32.le.o
6 # RUN: llvm-readobj --sections --section-data %t1.dwarf32.le.o | \
7 # RUN:   FileCheck -DSIZE=133 -DADDRALIGN=1 %s --check-prefixes=SHDR,DWARF32-LE
9 #            SHDR: Index: 1
10 #       SHDR-NEXT: Name: .debug_loclists (1)
11 #       SHDR-NEXT: Type: SHT_PROGBITS (0x1)
12 #       SHDR-NEXT: Flags [ (0x0)
13 #       SHDR-NEXT: ]
14 #       SHDR-NEXT: Address: 0x0
15 #       SHDR-NEXT: Offset: 0x40
16 #       SHDR-NEXT: Size: [[SIZE]]
17 #       SHDR-NEXT: Link: 0
18 #       SHDR-NEXT: Info: 0
19 #       SHDR-NEXT: AddressAlignment: [[ADDRALIGN]]
20 #       SHDR-NEXT: EntrySize: 0
21 # DWARF32-LE-NEXT: SectionData (
22 # DWARF32-LE-NEXT:   0000: 3D000000 05000800 03000000 0C000000  |=...............|
23 ##                         ^-------                             unit_length (4-byte)
24 ##                                  ^---                        version (2-byte)
25 ##                                      ^-                      address_size (1-byte)
26 ##                                        ^-                    segment_selector_size (1-byte)
27 ##                                           ^-------           offset_entry_count (4-byte)
28 ##                                                    ^-------  offsets[0] (4-byte)
29 # DWARF32-LE-NEXT:   0010: 1B000000 2F000000 01B42402 B424A186  |..../.....$..$..|
30 ##                         ^-------                             offsets[1] (4-byte)
31 ##                                  ^-------                    offsets[2] (4-byte)
32 ##                                           ^-                 DW_LLE_base_addressx
33 ##                                             ^---             operands[0] (ULEB128) 0x1234
34 ##                                                 ^-           DW_LLE_startx_endx
35 ##                                                    ^---      operands[0] (ULEB128) 0x1234
36 ##                                                        ^---  operands[1] (ULEB128) 0x4321
37 # DWARF32-LE-NEXT:   0020: 010411B4 249F0003 B424A186 0102117D  |....$....$.....}|
38 ##                         --
39 ##                           ^-                                 location descriptions length (ULEB128) 0x04
40 ##                             ^-                               DW_OP_consts
41 ##                               ^----                          operands[0] (SLEB128) +0x1234
42 ##                                    ^-                        DW_OP_stack_value
43 ##                                      ^-                      DW_LLE_end_of_list
44 ##                                        ^-                    DW_LLE_startx_length
45 ##                                           ^---               operands[0] (ULEB128) 0x1234
46 ##                                               ^------        operands[1] (ULEB128) 0x4321
47 ##                                                      ^-      location descriptions length (ULEB128) 0x02
48 ##                                                        ^-    DW_OP_consts
49 ##                                                          ^-  operands[0] (SLEB128) -0x03
50 # DWARF32-LE-NEXT:   0030: 04B424A1 86010311 B4240005 0311B424  |..$......$.....$|
51 ##                         ^-                                   DW_LLE_offset_pair
52 ##                           ^---                               operands[0] (ULEB128) 0x1234
53 ##                               ^------                        operands[1] (ULEB128) 0x4321
54 ##                                      ^-                      location descriptions length (ULEB128) 0x03
55 ##                                        ^-                    DW_OP_consts
56 ##                                           ^---               operands[0] (SLEB128) +0x1234
57 ##                                               ^-             DW_LLE_end_of_list
58 ##                                                 ^-           DW_LLE_default_location
59 ##                                                    ^-        location descriptions length (ULEB128) 0x03
60 ##                                                      ^-      DW_OP_consts
61 ##                                                        ^---  operands[0] (SLEB128) +0x1234
62 # DWARF32-LE-NEXT:   0040: 00400000 00050008 00020000 00080000  |.@..............|
63 ##                         ^-                                   DW_LLE_end_of_list
64 ##                           ^--------                          unit_length (4-byte)
65 ##                                    ^---                      version (2-byte)
66 ##                                        ^-                    address_size (1-byte)
67 ##                                           ^-                 segment_selector_size (1-byte)
68 ##                                             ^--------        offset_entry_count (4-byte)
69 ##                                                      ^-----  offsets[0] (4-byte)
70 # DWARF32-LE-NEXT:   0050: 00270000 00063412 00000000 00000734  |.'....4........4|
71 ##                         --
72 ##                           ^--------                          offsets[1] (4-byte)
73 ##                                    ^-                        DW_LLE_base_address
74 ##                                      ^-----------------      operands[0] (8-byte)
75 ##                                                        ^-    DW_LLE_start_end
76 ##                                                          ^-  operands[0] (8-byte)
77 # DWARF32-LE-NEXT:   0060: 12000000 00000021 43000000 00000003  |.......!C.......|
78 ##                         ---------------
79 ##                                        ^-----------------    operands[1] (8-byte)
80 ##                                                          ^-  location descriptions length (ULEB128) 0x03
81 # DWARF32-LE-NEXT:   0070: 11B42400 08341200 00000000 00A18601  |..$..4..........|
82 ##                         ^-                                   DW_OP_consts
83 ##                           ^---                               operands[0] (SLEB128) +0x1234
84 ##                               ^-                             DW_LLE_end_of_list
85 ##                                  ^-                          DW_LLE_start_length
86 ##                                    ^-----------------        operands[0] (8-byte)
87 ##                                                      ^-----  operands[1] (LEB128) 0x4321
88 # DWARF32-LE-NEXT:   0080: 0311B424 00                          |...$.|
89 ##                         ^-                                   location descriptions length (ULEB128) 0x03
90 ##                           ^-                                 DW_OP_consts
91 ##                             ^---                             operands[0] (SLEB128) +0x1234
92 ##                                  ^-                          DW_LLE_end_of_list
93 # DWARF32-LE-NEXT: )
95 --- !ELF
96 FileHeader:
97   Class: ELFCLASS64
98   Data:  [[ENDIAN]]
99   Type:  ET_EXEC
100 DWARF:
101   debug_loclists:
102     - Lists:
103         - Entries:
104             - Operator: DW_LLE_base_addressx
105               Values:   [ 0x1234 ]
106             - Operator: DW_LLE_startx_endx
107               Values:   [ 0x1234, 0x4321 ]
108               Descriptions:
109                 - Operator: DW_OP_consts
110                   Values:   [ 0x1234 ]
111                 - Operator: DW_OP_stack_value
112             - Operator: DW_LLE_end_of_list
113         - Entries:
114             - Operator: DW_LLE_startx_length
115               Values:   [ 0x1234, 0x4321 ]
116               Descriptions:
117                 - Operator: DW_OP_consts
118                   ## Test a negative number (-3).
119                   Values:   [ 0xfffffffffffffffd ]
120             - Operator: DW_LLE_offset_pair
121               Values:   [ 0x1234, 0x4321 ]
122               Descriptions:
123                 - Operator: DW_OP_consts
124                   Values:   [ 0x1234 ]
125             - Operator: DW_LLE_end_of_list
126         - Entries:
127             - Operator: DW_LLE_default_location
128               Descriptions:
129                 - Operator: DW_OP_consts
130                   Values:   [ 0x1234 ]
131             - Operator: DW_LLE_end_of_list
132     - Lists:
133         - Entries:
134             - Operator: DW_LLE_base_address
135               Values:   [ 0x1234 ]
136             - Operator: DW_LLE_start_end
137               Values:   [ 0x1234, 0x4321 ]
138               Descriptions:
139                 - Operator: DW_OP_consts
140                   Values:   [ 0x1234 ]
141             - Operator: DW_LLE_end_of_list
142         - Entries:
143             - Operator: DW_LLE_start_length
144               Values:   [ 0x1234, 0x4321 ]
145               Descriptions:
146                 - Operator: DW_OP_consts
147                   Values:   [ 0x1234 ]
148             - Operator: DW_LLE_end_of_list
150 ## b) Generate and verify a big endian DWARF32 .debug_loclists section in a 64-bit object file.
152 # RUN: yaml2obj --docnum=1 -DENDIAN=ELFDATA2MSB %s -o %t.dwarf32.be.o
153 # RUN: llvm-readobj --sections --section-data %t.dwarf32.be.o | \
154 # RUN:   FileCheck -DSIZE=133 -DADDRALIGN=1 %s --check-prefixes=SHDR,DWARF32-BE
156 # DWARF32-BE-NEXT: SectionData (
157 # DWARF32-BE-NEXT:   0000: 0000003D 00050800 00000003 0000000C  |...=............|
158 ##                         ^-------                             unit_length (4-byte)
159 ##                                  ^---                        version (2-byte)
160 ##                                      ^-                      address_size (1-byte)
161 ##                                        ^-                    segment_selector_size (1-byte)
162 ##                                           ^-------           offset_entry_count (4-byte)
163 ##                                                    ^-------  offsets[0] (4-byte)
164 # DWARF32-BE-NEXT:   0010: 0000001B 0000002F 01B42402 B424A186  |......./..$..$..|
165 ##                         ^-------                             offsets[1] (4-byte)
166 ##                                  ^-------                    offsets[2] (4-byte)
167 ##                                           ^-                 DW_LLE_base_addressx
168 ##                                             ^---             operands[0] (ULEB128) 0x1234
169 ##                                                 ^-           DW_LLE_startx_endx
170 ##                                                    ^---      operands[0] (ULEB128) 0x1234
171 ##                                                        ^---  operands[1] (ULEB128) 0x4321
172 # DWARF32-BE-NEXT:   0020: 010411B4 249F0003 B424A186 0102117D  |....$....$.....}|
173 ##                         --
174 ##                           ^-                                 location descriptions length (ULEB128) 0x04
175 ##                             ^-                               DW_OP_consts
176 ##                               ^----                          operands[0] (SLEB128) +0x1234
177 ##                                    ^-                        DW_OP_stack_value
178 ##                                      ^-                      DW_LLE_end_of_list
179 ##                                        ^-                    DW_LLE_startx_length
180 ##                                           ^---               operands[0] (ULEB128) 0x1234
181 ##                                               ^------        operands[1] (ULEB128) 0x4321
182 ##                                                      ^-      location descriptions length (ULEB128) 0x02
183 ##                                                        ^-    DW_OP_consts
184 ##                                                          ^-  operands[0] (SLEB128) -0x03
185 # DWARF32-BE-NEXT:   0030: 04B424A1 86010311 B4240005 0311B424  |..$......$.....$|
186 ##                         ^-                                   DW_LLE_offset_pair
187 ##                           ^---                               operands[0] (ULEB128) 0x1234
188 ##                               ^------                        operands[1] (ULEB128) 0x4321
189 ##                                      ^-                      location descriptions length (ULEB128) 0x03
190 ##                                        ^-                    DW_OP_consts
191 ##                                           ^---               operands[0] (SLEB128) +0x1234
192 ##                                               ^-             DW_LLE_end_of_list
193 ##                                                 ^-           DW_LLE_default_location
194 ##                                                    ^-        location descriptions length (ULEB128) 0x03
195 ##                                                      ^-      DW_OP_consts
196 ##                                                        ^---  operands[0] (SLEB128) +0x1234
197 # DWARF32-BE-NEXT:   0040: 00000000 40000508 00000000 02000000  |....@...........|
198 ##                         ^-                                   DW_LLE_end_of_list
199 ##                           ^--------                          unit_length (4-byte)
200 ##                                    ^---                      version (2-byte)
201 ##                                        ^-                    address_size (1-byte)
202 ##                                           ^-                 segment_selector_size (1-byte)
203 ##                                             ^--------        offset_entry_count (4-byte)
204 ##                                                      ^-----  offsets[0] (4-byte)
205 # DWARF32-BE-NEXT:   0050: 08000000 27060000 00000000 12340700  |....'........4..|
206 ##                         --
207 ##                           ^--------                          offsets[1] (4-byte)
208 ##                                    ^-                        DW_LLE_base_address
209 ##                                      ^-----------------      operands[0] (8-byte)
210 ##                                                        ^-    DW_LLE_start_end
211 ##                                                          ^-  operands[0] (8-byte)
212 # DWARF32-BE-NEXT:   0060: 00000000 00123400 00000000 00432103  |......4......C!.|
213 ##                         ---------------
214 ##                                        ^-----------------    operands[1] (8-byte)
215 ##                                                          ^-  location descriptions length (ULEB128) 0x03
216 # DWARF32-BE-NEXT:   0070: 11B42400 08000000 00000012 34A18601  |..$.........4...|
217 ##                         ^-                                   DW_OP_consts
218 ##                           ^---                               operands[0] (SLEB128) +0x1234
219 ##                               ^-                             DW_LLE_end_of_list
220 ##                                  ^-                          DW_LLE_start_length
221 ##                                    ^-----------------        operands[0] (8-byte)
222 ##                                                      ^-----  operands[1] (LEB128) 0x4321
223 # DWARF32-BE-NEXT:   0080: 0311B424 00                          |...$.|
224 ##                         ^-                                   location descriptions length (ULEB128) 0x03
225 ##                           ^-                                 DW_OP_consts
226 ##                             ^---                             operands[0] (SLEB128) +0x1234
227 ##                                  ^-                          DW_LLE_end_of_list
228 # DWARF32-BE-NEXT: )
230 ## c) Generate and verify a little endian DWARF64 .debug_loclists section in a 64-bit object file.
232 # RUN: yaml2obj --docnum=2 -DENDIAN=ELFDATA2LSB %s -o %t2.dwarf64.le.o
233 # RUN: llvm-readobj --sections --section-data %t2.dwarf64.le.o | \
234 # RUN:   FileCheck -DSIZE=47 -DADDRALIGN=1 %s --check-prefixes=SHDR,DWARF64-LE
236 # DWARF64-LE-NEXT: SectionData (
237 # DWARF64-LE-NEXT:   0000: FFFFFFFF 23000000 00000000 05000800  |....#...........|
238 ##                         ^-------------------------           unit_length (12-byte)
239 ##                                                    ^---      version (2-byte)
240 ##                                                        ^-    address_size (1-byte)
241 ##                                                          ^-  segment_selector_size (1-byte)
242 # DWARF64-LE-NEXT:   0010: 02000000 10000000 00000000 1A000000  |................|
243 ##                         ^-------                             offset_entry_count (4-byte)
244 ##                                  ^----------------           offsets[0] (8-byte)
245 ##                                                    ^-------  offsets[1] (8-byte)
246 # DWARF64-LE-NEXT:   0020: 00000000 02B424A1 86010311 B42400    |......$......$.|
247 ##                         --------
248 ##                                  ^-                          DW_LLE_startx_endx
249 ##                                    ^---                      operands[0] (ULEB128) 0x1234
250 ##                                        ^------               operands[1] (ULEB128) 0x4321
251 ##                                               ^-             location descriptions length (ULEB128) 0x03
252 ##                                                 ^-           DW_OP_consts
253 ##                                                    ^---      operands[0] (SLEB128) +0x1234
254 ##                                                        ^-    DW_LLE_end_of_list
255 # DWARF64-LE-NEXT: )
257 --- !ELF
258 FileHeader:
259   Class: ELFCLASS64
260   Data:  [[ENDIAN]]
261   Type:  ET_EXEC
262 DWARF:
263   debug_loclists:
264     - Format:  DWARF64
265       Lists:
266         - Entries:
267             - Operator: DW_LLE_startx_endx
268               Values:   [ 0x1234, 0x4321 ]
269               Descriptions:
270                 - Operator: DW_OP_consts
271                   Values:   [ 0x1234 ]
272         - Entries:
273             - Operator: DW_LLE_end_of_list
275 ## d) Generate and verify a big endian DWARF64 .debug_loclists section in a 64-bit object file.
277 # RUN: yaml2obj --docnum=2 -DENDIAN=ELFDATA2MSB %s -o %t2.dwarf64.be.o
278 # RUN: llvm-readobj --sections --section-data %t2.dwarf64.be.o | \
279 # RUN:   FileCheck -DSIZE=47 -DADDRALIGN=1 %s --check-prefixes=SHDR,DWARF64-BE
281 # DWARF64-BE-NEXT: SectionData (
282 # DWARF64-BE-NEXT:   0000: FFFFFFFF 00000000 00000023 00050800  |...........#....|
283 ##                         ^-------------------------           unit_length (12-byte)
284 ##                                                    ^---      version (2-byte)
285 ##                                                        ^-    address_size (1-byte)
286 ##                                                          ^-  segment_selector_size (1-byte)
287 # DWARF64-BE-NEXT:   0010: 00000002 00000000 00000010 00000000  |................|
288 ##                         ^-------                             offset_entry_count (4-byte)
289 ##                                  ^----------------           offsets[0] (8-byte)
290 ##                                                    ^-------  offsets[1] (8-byte)
291 # DWARF64-BE-NEXT:   0020: 0000001A 02B424A1 86010311 B42400    |......$......$.|
292 ##                         --------
293 ##                                  ^-                          DW_LLE_startx_endx
294 ##                                    ^---                      operands[0] (ULEB128) 0x1234
295 ##                                        ^------               operands[1] (ULEB128) 0x4321
296 ##                                               ^-             location descriptions length (ULEB128) 0x03
297 ##                                                 ^-           DW_OP_consts
298 ##                                                    ^---      operands[0] (SLEB128) +0x1234
299 ##                                                        ^-    DW_LLE_end_of_list
300 # DWARF64-BE-NEXT: )
302 ## e) Test that the length, version, segment_selector_size, address_size, offset_entry_count,
303 ## offsets and location descriptions length fields can be specified manually.
305 # RUN: yaml2obj --docnum=3 %s -o %t3.o
306 # RUN: llvm-readelf --hex-dump=.debug_loclists %t3.o | \
307 # RUN:   FileCheck %s --check-prefix=OVERWRITE
309 #      OVERWRITE: Hex dump of section '.debug_loclists':
310 # OVERWRITE-NEXT: 0x00000000 34120000 06000303 04000000 01000000 4...............
311 ##                           ^-------                            unit_length (4-byte) 0x1234
312 ##                                    ^---                       version (2-byte) 0x06
313 ##                                        ^-                     address_size (1-byte) 0x03
314 ##                                          ^-                   segment_selector_size (1-byte) 0x03
315 ##                                             ^-------          offset_entry_count (4-byte) 0x04
316 ##                                                      ^------- offsets[0] (4-byte) 0x01
317 # OVERWRITE-NEXT: 0x00000010 02b424a1 8601a186 019f00            ..$........
318 ##                           ^-                                  DW_LLE_startx_endx
319 ##                             ^---                              operands[0] (ULEB128) 0x1234
320 ##                                 ^------                       operands[1] (ULEB128) 0x4321
321 ##                                        ^------                location descriptions length (ULEB128) 0x4321
322 ##                                               ^-              DW_OP_stack_value
323 ##                                                 ^-            DW_LLE_end_of_list
325 --- !ELF
326 FileHeader:
327   Class: ELFCLASS64
328   Data:  ELFDATA2LSB
329   Type:  ET_EXEC
330 DWARF:
331   debug_loclists:
332     - Length:              0x1234
333       Version:             6
334       AddressSize:         3
335       SegmentSelectorSize: 3
336       OffsetEntryCount:    4
337       Offsets:             [ 0x01 ]
338       Lists:
339         - Entries:
340             - Operator:           DW_LLE_startx_endx
341               Values:             [ 0x1234, 0x4321 ]
342               DescriptionsLength: 0x4321
343               Descriptions:
344                 - Operator: DW_OP_stack_value
345         - Entries:
346             - Operator: DW_LLE_end_of_list
348 ## f) Test that location descriptions can be omitted from the YAML description.
350 # RUN: yaml2obj --docnum=4 %s -o %t4.o
351 # RUN: llvm-readelf --hex-dump=.debug_loclists %t4.o | \
352 # RUN:   FileCheck %s --check-prefix=OMIT-DESCRIPTIONS
354 #      OMIT-DESCRIPTIONS: Hex dump of section '.debug_loclists':
355 # OMIT-DESCRIPTIONS-NEXT: 0x00000000 42000000 05000800 01000000 04000000 B...............
356 # OMIT-DESCRIPTIONS-NEXT: 0x00000010 02b424a1 86010003 b424a186 010004b4 ..$......$......
357 ##                                  ^-                                  DW_LLE_startx_endx
358 ##                                    ^---                              operands[0] (ULEB128) 0x1234
359 ##                                        ^------                       operands[1] (ULEB128) 0x4321
360 ##                                               ^-                     location descriptions length (ULEB128) 0x00
361 ##                                                 ^-                   DW_LLE_startx_length
362 ##                                                    ^---              operands[0] (ULEB128) 0x1234
363 ##                                                        ^------       operands[1] (ULEB128) 0x4321
364 ##                                                               ^-     location descriptions length (ULEB128) 0x00
365 ##                                                                 ^-   DW_LLE_offset_pair
366 ##                                                                   ^- operands[0] (ULEB128) 0x1234
367 # OMIT-DESCRIPTIONS-NEXT: 0x00000020 24a18601 00050007 34120000 00000000 $.......4.......
368 ##                                  --
369 ##                                    ^-----                            operands[1] (ULEB128) 0x4321
370 ##                                           ^-                         location descriptions length (ULEB128) 0x00
371 ##                                             ^-                       DW_LLE_default_location
372 ##                                               ^-                     location descriptions length (ULEB128) 0x00
373 ##                                                 ^-                   DW_LLE_start_end
374 ##                                                    ^---------------- operands[0] (8-byte)
375 # OMIT-DESCRIPTIONS-NEXT: 0x00000030 21430000 00000000 00083412 00000000 !C........4.....
376 ##                                  ^----------------                   operands[1] (8-byte)
377 ##                                                    ^-                location descriptions length (ULEB128) 0x00
378 ##                                                      ^-              DW_LLE_start_length
379 ##                                                        ^------------ operands[0] (8-byte)
380 # OMIT-DESCRIPTIONS-NEXT: 0x00000040 0000a186 0100                       ......
381 ##                                  ----
382 ##                                      ^------                         operands[1] (ULEB128) 0x4321
383 ##                                             ^-                       location descriptions length (ULEB128) 0x00
385 --- !ELF
386 FileHeader:
387   Class: ELFCLASS64
388   Data:  ELFDATA2LSB
389   Type:  ET_EXEC
390 DWARF:
391   debug_loclists:
392     - Lists:
393         - Entries:
394             - Operator: DW_LLE_startx_endx
395               Values:   [ 0x1234, 0x4321 ]
396             - Operator: DW_LLE_startx_length
397               Values:   [ 0x1234, 0x4321 ]
398             - Operator: DW_LLE_offset_pair
399               Values:   [ 0x1234, 0x4321 ]
400             - Operator: DW_LLE_default_location
401             - Operator: DW_LLE_start_end
402               Values:   [ 0x1234, 0x4321 ]
403             - Operator: DW_LLE_start_length
404               Values:   [ 0x1234, 0x4321 ]
406 ## g) Test that the default value of the address_size field in a 32-bit object file is 4.
408 # RUN: yaml2obj --docnum=5 %s -o %t5.o
409 # RUN: llvm-readelf --hex-dump=.debug_loclists %t5.o | \
410 # RUN:   FileCheck %s --check-prefix=ADDRSIZE32
412 #      ADDRSIZE32: Hex dump of section '.debug_loclists':
413 # ADDRSIZE32-NEXT: 0x00000000 24000000 05000400 01000000 04000000 $...............
414 ##                                         ^-                     address_size (1-byte) 0x04
415 # ADDRSIZE32-NEXT: 0x00000010 06341200 00073412 00002143 00000008 .4....4...!C....
416 ##                            ^-                                  DW_LLE_base_address
417 ##                              ^--------                         operands[0] (4-byte)
418 ##                                       ^-                       DW_LLE_start_end
419 ##                                         ^--------              operands[0] (4-byte)
420 ##                                                  ^--------     operands[1] (4-byte)
421 ##                                                           ^-   counted location description
422 ##                                                             ^- DW_LLE_start_length
423 # ADDRSIZE32-NEXT: 0x00000020 34120000 a1860100                   4.......
424 ##                            ^-------                            operands[0] (4-byte)
425 ##                                     ^-----                     operands[1] (ULEB128) 0x4321
426 ##                                           ^-                   counted location description
428 --- !ELF
429 FileHeader:
430   Class: ELFCLASS32
431   Data:  ELFDATA2LSB
432   Type:  ET_EXEC
433 DWARF:
434   debug_loclists:
435     - Lists:
436         - Entries:
437             - Operator: DW_LLE_base_address
438               Values:   [ 0x1234 ]
439             - Operator: DW_LLE_start_end
440               Values:   [ 0x1234, 0x4321 ]
441             - Operator: DW_LLE_start_length
442               Values:   [ 0x1234, 0x4321 ]
444 ## h) Test that the address_size field can be specified manually and the size of
445 ## corresponding operands will be changed accordingly.
447 # RUN: yaml2obj --docnum=6 %s -o %t6.o
448 # RUN: llvm-readelf --hex-dump=.debug_loclists %t6.o | \
449 # RUN:   FileCheck %s --check-prefix=ADDRSIZE32
451 --- !ELF
452 FileHeader:
453   Class: ELFCLASS64
454   Data:  ELFDATA2LSB
455   Type:  ET_EXEC
456 DWARF:
457   debug_loclists:
458     - AddressSize: 4
459       Lists:
460         - Entries:
461             - Operator: DW_LLE_base_address
462               Values:   [ 0x1234 ]
463             - Operator: DW_LLE_start_end
464               Values:   [ 0x1234, 0x4321 ]
465             - Operator: DW_LLE_start_length
466               Values:   [ 0x1234, 0x4321 ]
468 ## i) Test that yaml2obj emits an error message if we try to assign an invalid value to
469 ## 'AddressSize' when there is an entry whose operands contain address.
471 # RUN: not yaml2obj -DOPERATOR=base_address -DVALUES=[0x01] --docnum=7 %s 2>&1 | \
472 # RUN:   FileCheck -DOPERATOR=base_address %s --check-prefix=INVALID-ADDRSIZE
474 # RUN: not yaml2obj -DOPERATOR=start_end -DVALUES=[0x01,0x02] --docnum=7 %s 2>&1 | \
475 # RUN:   FileCheck -DOPERATOR=start_end %s --check-prefix=INVALID-ADDRSIZE
477 # RUN: not yaml2obj -DOPERATOR=start_length -DVALUES=[0x01,0x02] --docnum=7 %s 2>&1 | \
478 # RUN:   FileCheck -DOPERATOR=start_length %s --check-prefix=INVALID-ADDRSIZE
480 # INVALID-ADDRSIZE: yaml2obj: error: unable to write address for the operator DW_LLE_[[OPERATOR]]: invalid integer write size: 3
482 --- !ELF
483 FileHeader:
484   Class: ELFCLASS64
485   Data:  ELFDATA2LSB
486   Type:  ET_EXEC
487 DWARF:
488   debug_loclists:
489     - AddressSize: 3
490       Lists:
491         - Entries:
492             - Operator: DW_LLE_[[OPERATOR]]
493               Values:   [[VALUES]]
495 ## j) Test that yaml2obj emits an error message if we specify invalid numbers of operands
496 ## for a location list encoding.
498 # RUN: not yaml2obj -DOPERATOR=end_of_list -DVALUES=[0x01] --docnum=8 %s 2>&1 | \
499 # RUN:   FileCheck -DOPERATOR=end_of_list -DACTUAL=1 -DEXPECTED=0 %s --check-prefix=INVALID-LLE-OPERANDS
501 # RUN: not yaml2obj -DOPERATOR=base_addressx -DVALUES=[] --docnum=8 %s 2>&1 | \
502 # RUN:   FileCheck -DOPERATOR=base_addressx -DACTUAL=0 -DEXPECTED=1 %s --check-prefix=INVALID-LLE-OPERANDS
504 # RUN: not yaml2obj -DOPERATOR=startx_endx -DVALUES=[0x01] --docnum=8 %s 2>&1 | \
505 # RUN:   FileCheck -DOPERATOR=startx_endx -DACTUAL=1 -DEXPECTED=2 %s --check-prefix=INVALID-LLE-OPERANDS
507 # RUN: not yaml2obj -DOPERATOR=startx_length -DVALUES=[0x01] --docnum=8 %s 2>&1 | \
508 # RUN:   FileCheck -DOPERATOR=startx_length -DACTUAL=1 -DEXPECTED=2 %s --check-prefix=INVALID-LLE-OPERANDS
510 # RUN: not yaml2obj -DOPERATOR=offset_pair -DVALUES=[] --docnum=8 %s 2>&1 | \
511 # RUN:   FileCheck -DOPERATOR=offset_pair -DACTUAL=0 -DEXPECTED=2 %s --check-prefix=INVALID-LLE-OPERANDS
513 # RUN: not yaml2obj -DOPERATOR=default_location -DVALUES=[0x01] --docnum=8 %s 2>&1 | \
514 # RUN:   FileCheck -DOPERATOR=default_location -DACTUAL=1 -DEXPECTED=0 %s --check-prefix=INVALID-LLE-OPERANDS
516 # RUN: not yaml2obj -DOPERATOR=base_address -DVALUES=[0x01,0x02] --docnum=8 %s 2>&1 | \
517 # RUN:   FileCheck -DOPERATOR=base_address -DACTUAL=2 -DEXPECTED=1 %s --check-prefix=INVALID-LLE-OPERANDS
519 # RUN: not yaml2obj -DOPERATOR=start_end -DVALUES=[0x01,0x02,0x03] --docnum=8 %s 2>&1 | \
520 # RUN:   FileCheck -DOPERATOR=start_end -DACTUAL=3 -DEXPECTED=2 %s --check-prefix=INVALID-LLE-OPERANDS
522 # RUN: not yaml2obj -DOPERATOR=start_length -DVALUES=[0x01] --docnum=8 %s 2>&1 | \
523 # RUN:   FileCheck -DOPERATOR=start_length -DACTUAL=1 -DEXPECTED=2 %s --check-prefix=INVALID-LLE-OPERANDS
525 # INVALID-LLE-OPERANDS: yaml2obj: error: invalid number ([[ACTUAL]]) of operands for the operator: DW_LLE_[[OPERATOR]], [[EXPECTED]] expected
527 --- !ELF
528 FileHeader:
529   Class: ELFCLASS64
530   Data:  ELFDATA2LSB
531   Type:  ET_EXEC
532 DWARF:
533   debug_loclists:
534     - Lists:
535         - Entries:
536             - Operator: DW_LLE_[[OPERATOR]]
537               Values:   [[VALUES]]
539 ## k) Test that yaml2obj emits an error message if we specify invalid numbers of operands
540 ## for a DWARF expression operator.
542 # RUN: not yaml2obj --docnum=9 -DOPERATOR=consts -DVALUES=[0x01,0x02] %s 2>&1 | \
543 # RUN:   FileCheck -DACTUAL=2 -DEXPECTED=1 -DOPERATOR=consts %s --check-prefix=INVALID-OP-OPERANDS
545 # RUN: not yaml2obj --docnum=9 -DOPERATOR=stack_value -DVALUES=[0x01] %s 2>&1 | \
546 # RUN:   FileCheck -DACTUAL=1 -DEXPECTED=0 -DOPERATOR=stack_value %s --check-prefix=INVALID-OP-OPERANDS
548 # INVALID-OP-OPERANDS: yaml2obj: error: invalid number ([[ACTUAL]]) of operands for the operator: DW_OP_[[OPERATOR]], [[EXPECTED]] expected
550 --- !ELF
551 FileHeader:
552   Class: ELFCLASS64
553   Data:  ELFDATA2LSB
554   Type:  ET_EXEC
555 DWARF:
556   debug_loclists:
557     - Lists:
558         - Entries:
559             - Operator: DW_LLE_startx_endx
560               Values:   [ 0x01, 0x02 ]
561               Descriptions:
562                 - Operator: DW_OP_[[OPERATOR]]
563                   Values:   [[VALUES]]
565 ## l) Test that an empty list is allowed for a location list table.
567 # RUN: yaml2obj --docnum=10 %s -o %t10.o
568 # RUN: llvm-readelf --hex-dump=.debug_loclists %t10.o | \
569 # RUN:   FileCheck %s --check-prefix=EMPTY-LIST
571 #      EMPTY-LIST: Hex dump of section '.debug_loclists':
572 # EMPTY-LIST-NEXT: 0x00000000 08000000 05000800 00000000 ............
573 ##                            ^-------                   unit_length (4-byte)
574 ##                                     ^---              version (2-byte)
575 ##                                         ^-            address_size (1-byte)
576 ##                                           ^-          segment_selector_size (1-byte)
577 ##                                              ^------- offset_entry_count (4-byte)
579 --- !ELF
580 FileHeader:
581   Class: ELFCLASS64
582   Data:  ELFDATA2LSB
583   Type:  ET_EXEC
584 DWARF:
585   debug_loclists:
586     - Lists: []
588 ## m) Generate the .debug_loclists section from raw section content.
590 # RUN: yaml2obj --docnum=11 %s -o %t11.o
591 # RUN: llvm-readobj --sections --section-data %t11.o | \
592 # RUN:   FileCheck %s -DSIZE=3 -DADDRALIGN=0 --check-prefixes=SHDR,ARBITRARY-CONTENT
594 #      ARBITRARY-CONTENT: SectionData (
595 # ARBITRARY-CONTENT-NEXT:   0000: 112233
596 # ARBITRARY-CONTENT-NEXT: )
598 --- !ELF
599 FileHeader:
600   Class: ELFCLASS64
601   Data:  ELFDATA2LSB
602   Type:  ET_EXEC
603 Sections:
604   - Name:    .debug_loclists
605     Type:    SHT_PROGBITS
606     Content: "112233"
608 ## n) Generate the .debug_loclists section when the "Size" is specified.
610 # RUN: yaml2obj --docnum=12 %s -o %t12.o
611 # RUN: llvm-readelf --hex-dump=.debug_loclists %t12.o | \
612 # RUN:   FileCheck %s --check-prefix=SIZE
614 #       SIZE: Hex dump of section '.debug_loclists':
615 #  SIZE-NEXT: 0x00000000 00000000 00000000 00000000 00000000 ................
616 # SIZE-EMPTY:
618 --- !ELF
619 FileHeader:
620   Class: ELFCLASS64
621   Data:  ELFDATA2LSB
622   Type:  ET_EXEC
623 Sections:
624   - Name: .debug_loclists
625     Type: SHT_PROGBITS
626     Size: 0x10
628 ## o) Test that yaml2obj emits an error message when both the "Size" and the
629 ## "debug_loclists" entry are specified at the same time.
631 # RUN: not yaml2obj --docnum=13 %s 2>&1 | FileCheck %s --check-prefix=ERROR
633 # ERROR: yaml2obj: error: cannot specify section '.debug_loclists' contents in the 'DWARF' entry and the 'Content' or 'Size' in the 'Sections' entry at the same time
635 --- !ELF
636 FileHeader:
637   Class: ELFCLASS64
638   Data:  ELFDATA2LSB
639   Type:  ET_EXEC
640 Sections:
641   - Name: .debug_loclists
642     Type: SHT_PROGBITS
643     Size: 0x10
644 DWARF:
645   debug_loclists:
646     - Lists: []
648 ## p) Test that yaml2obj emits an error message when both the "Content" and the
649 ## "debug_loclists" entry are specified at the same time.
651 # RUN: not yaml2obj --docnum=14 %s 2>&1 | FileCheck %s --check-prefix=ERROR
653 --- !ELF
654 FileHeader:
655   Class: ELFCLASS64
656   Data:  ELFDATA2LSB
657   Type:  ET_EXEC
658 Sections:
659   - Name:    .debug_loclists
660     Type:    SHT_PROGBITS
661     Content: "00"
662 DWARF:
663   debug_loclists:
664     - Lists: []
666 ## q) Test that all the properties can be overridden by the section header when
667 ## the "debug_loclists" entry doesn't exist.
669 # RUN: yaml2obj --docnum=15 %s -o %t15.o
670 # RUN: llvm-readelf --sections %t15.o | FileCheck %s --check-prefix=OVERRIDDEN
672 #      OVERRIDDEN: [Nr] Name            Type   Address          Off    Size   ES Flg Lk Inf Al
673 #      OVERRIDDEN: [ 1] .debug_loclists STRTAB 0000000000002020 000050 00000c 01   A  2   1  2
674 # OVERRIDDEN-NEXT: [ 2] .sec            STRTAB 0000000000000000 00005c 000000 00      0   0  0
676 --- !ELF
677 FileHeader:
678   Class: ELFCLASS64
679   Data:  ELFDATA2LSB
680   Type:  ET_EXEC
681 Sections:
682   - Name:         .debug_loclists
683     Type:         SHT_STRTAB  ## SHT_PROGBITS by default.
684     Flags:        [SHF_ALLOC] ## 0 by default.
685     Link:         .sec        ## 0 by default.
686     EntSize:      1           ## 0 by default.
687     Info:         1           ## 0 by default.
688     AddressAlign: 2           ## 0 by default.
689     Address:      0x2020      ## 0x00 by default.
690     Offset:       0x50        ## 0x40 for the first section.
691     Size:         0x0c        ## Set the "Size" so that we can reuse the check tag "OVERRIDDEN".
692   - Name:         .sec        ## Linked by .debug_loclists.
693     Type:         SHT_STRTAB
695 ## r) Test that all the properties can be overridden by the section header when
696 ## the "debug_loclists" entry exists.
698 # RUN: yaml2obj --docnum=16 %s -o %t16.o
699 # RUN: llvm-readelf --sections %t16.o | FileCheck %s --check-prefix=OVERRIDDEN
701 --- !ELF
702 FileHeader:
703   Class: ELFCLASS64
704   Data:  ELFDATA2LSB
705   Type:  ET_EXEC
706 Sections:
707   - Name:         .debug_loclists
708     Type:         SHT_STRTAB  ## SHT_PROGBITS by default.
709     Flags:        [SHF_ALLOC] ## 0 by default.
710     Link:         .sec        ## 0 by default.
711     EntSize:      1           ## 0 by default.
712     Info:         1           ## 0 by default.
713     AddressAlign: 2           ## 1 by default.
714     Address:      0x2020      ## 0x00 by default.
715     Offset:       0x50        ## 0x40 for the first section.
716   - Name:         .sec        ## Linked by .debug_loclists.
717     Type:         SHT_STRTAB
718 DWARF:
719   debug_loclists:
720     - Lists: []
722 ## s) Test that the .debug_loclists section header is emitted if the "debug_loclists"
723 ## entry is empty.
725 # RUN: yaml2obj --docnum=17 %s -o %t17.o
726 # RUN: llvm-readobj --sections --section-data %t17.o | \
727 # RUN:   FileCheck -DSIZE=0 -DADDRALIGN=1 %s --check-prefixes=SHDR,EMPTY-CONTENT
729 # EMPTY-CONTENT-NEXT: SectionData (
730 # EMPTY-CONTENT-NEXT: )
732 --- !ELF
733 FileHeader:
734   Class: ELFCLASS64
735   Data:  ELFDATA2LSB
736   Type:  ET_EXEC
737 DWARF:
738   debug_loclists: []
740 ## t) Test that yaml2obj emits an error message if we use an unimplemented DWARF expression
741 ## operator.
743 # RUN: not yaml2obj --docnum=18 -DOP=0x01 %s 2>&1 | \
744 # RUN:   FileCheck -DOP=0x1 %s --check-prefix=UNSUPPORTED-OP
746 # UNSUPPORTED-OP: yaml2obj: error: DWARF expression: [[OP]] is not supported
748 # RUN: not yaml2obj --docnum=18 -DOP=DW_OP_entry_value %s 2>&1 | \
749 # RUN:   FileCheck -DOP=DW_OP_entry_value %s --check-prefix=UNSUPPORTED-OP
752 --- !ELF
753 FileHeader:
754   Class: ELFCLASS64
755   Data:  ELFDATA2LSB
756   Type:  ET_EXEC
757 DWARF:
758   debug_loclists:
759     - Lists:
760         - Entries:
761             - Operator: DW_LLE_default_location
762               Descriptions:
763                 - Operator: [[OP]]
765 ## u) Test that we are able to generate a location list via raw binary data.
767 # RUN: yaml2obj --docnum=19 %s -o %t19.o
768 # RUN: llvm-readelf --hex-dump=.debug_loclists %t19.o | \
769 # RUN:   FileCheck %s --check-prefix=CUSTOM-LIST
771 #      CUSTOM-LIST: Hex dump of section '.debug_loclists':
772 # CUSTOM-LIST-NEXT: 0x00000000 2a000000 05000800 03000000 0c000000 *...............
773 ##                             ^-------                            unit_length (4-byte)
774 ##                                      ^---                       version (2-byte)
775 ##                                          ^-                     address_size (1-byte)
776 ##                                            ^-                   segment_selector_size (1-byte)
777 ##                                               ^-------          offset_entry_count (4-byte)
778 ##                                                        ^------- offsets[0] (4-byte)
779 # CUSTOM-LIST-NEXT: 0x00000010 12000000 1a000000 02b424b4 24001234 ..........$.$..4
780 ##                             ^-------                            offsets[1] (4-byte)
781 ##                                      ^-------                   offsets[2] (4-byte)
782 ##                                               ^-                DW_LLE_startx_endx
783 ##                                                 ^---            operands[0] (ULEB128) 0x1234
784 ##                                                     ^----       operands[1] (ULEB128) 0x1234
785 ##                                                          ^-     location descriptions length (ULEB128) 0x00
786 ##                                                            ^--- custom list content
787 # CUSTOM-LIST-NEXT: 0x00000020 567890ab cdefabcd ef123456 7890     Vx........4Vx.
788 ##                             -------------
789 ##                                          ^-----------------     custom list content
791 --- !ELF
792 FileHeader:
793   Class: ELFCLASS64
794   Data:  ELFDATA2LSB
795   Type:  ET_EXEC
796 DWARF:
797   debug_loclists:
798     - Lists:
799         - Entries:
800             - Operator: DW_LLE_startx_endx
801               Values:   [ 0x1234, 0x1234 ]
802         - Content: '1234567890abcdef'
803         - Content: 'abcdef1234567890'
805 ## v) Test that yaml2obj emits an error message when 'Content' and 'Entries' are specified
806 ## at the same time.
808 # RUN: not yaml2obj --docnum=20 %s 2>&1 | FileCheck %s --check-prefix=ERR
810 #      ERR: YAML:{{.*}}: error: Entries and Content can't be used together
811 # ERR-NEXT:         - Entries: []
812 # ERR-NEXT:           ^
814 --- !ELF
815 FileHeader:
816   Class: ELFCLASS64
817   Data:  ELFDATA2LSB
818   Type:  ET_EXEC
819 DWARF:
820   debug_loclists:
821     - Lists:
822         - Entries: []
823           Content: ''
825 ## w) Test that when the "OffsetEntryCount" is specified to be 0 and "Offsets" is not specified,
826 ## the offsets array is not emitted.
828 # RUN: yaml2obj --docnum=21 -DOFFSETENTRIES=0 %s -o %t21.o
829 # RUN: llvm-readelf --hex-dump=.debug_loclists %t21.o | \
830 # RUN:   FileCheck %s --check-prefix=NO-OFFSETS
832 #      NO-OFFSETS: Hex dump of section '.debug_loclists':
833 # NO-OFFSETS-NEXT: 0x00000000 0e000000 05000800 00000000 01010201 ................
834 ##                            ^-------                            unit_length (4-byte)
835 ##                                     ^---                       version (2-byte)
836 ##                                         ^-                     address_size (1-byte)
837 ##                                           ^-                   segment_selector_size (1-byte)
838 ##                                              ^-------          offset_entry_count (4-byte)
839 ##                                                       ^-       DW_LLE_base_addressx
840 ##                                                         ^-     operands[0] (ULEB128) 0x01
841 ##                                                           ^-   DW_LLE_startx_endx
842 ##                                                             ^- operands[0] (ULEB128) 0x01
843 # NO-OFFSETS-NEXT: 0x00000010 0200                                ..
844 ##                            ^-                                  operands[1] (ULEB128) 0x02
845 ##                              ^-                                location descriptions length (ULEB128) 0x00
847 --- !ELF
848 FileHeader:
849   Class: ELFCLASS64
850   Data:  ELFDATA2LSB
851   Type:  ET_EXEC
852 DWARF:
853   debug_loclists:
854     - OffsetEntryCount: [[OFFSETENTRIES=<none>]]
855       Offsets:          [[OFFSETS=<none>]]
856       Lists:
857         - Entries:
858             - Operator: DW_LLE_base_addressx
859               Values:   [ 0x01 ]
860             - Operator: DW_LLE_startx_endx
861               Values:   [ 0x01, 0x02 ]
863 ## x) Test that when the "Offsets" entry is specified to be empty and the "OffsetEntryCount" is not specified,
864 ## the offsets array will be omitted.
866 # RUN: yaml2obj --docnum=21 -DOFFSETS=[] %s -o %t22.o
867 # RUN: llvm-readelf --hex-dump=.debug_loclists %t22.o | \
868 # RUN:   FileCheck %s --check-prefix=NO-OFFSETS
870 ## y) Test that if "Offsets" is specified, the offsets array will be emitted accordingly, even when
871 ## the "OffsetEntryCount" is specified to be 0.
873 # RUN: yaml2obj --docnum=21 -DOFFSETENTRIES=0 -DOFFSETS=[0x01,0x02,0x03] %s -o %t23.o
874 # RUN: llvm-readelf --hex-dump=.debug_loclists %t23.o | \
875 # RUN:   FileCheck %s --check-prefix=OFFSETS
877 #      OFFSETS: Hex dump of section '.debug_loclists':
878 # OFFSETS-NEXT: 0x00000000 0e000000 05000800 00000000 01000000 ................
879 ##                         ^-------                            unit_length (4-byte)
880 ##                                  ^---                       version (2-byte)
881 ##                                      ^-                     address_size (1-byte)
882 ##                                        ^-                   segment_selector_size (1-byte)
883 ##                                           ^-------          offset_entry_count (4-byte)
884 ##                                                    ^------- offsets[0] (4-byte)
885 # OFFSETS-NEXT: 0x00000010 02000000 03000000 01010201 0200     ..............
886 ##                         ^-------                            offsets[1] (4-byte)
887 ##                                  ^-------                   offsets[2] (4-byte)
888 ##                                           ^-                DW_LLE_base_addressx
889 ##                                             ^-              operands[0] (ULEB128) 0x01
890 ##                                               ^-            DW_LLE_startx_endx
891 ##                                                 ^-          operands[0] (ULEB128) 0x01
892 ##                                                    ^-       operands[1] (ULEB128) 0x02
893 ##                                                      ^-     location descriptions length (ULEB128) 0x00