1## Test that yaml2obj and obj2yaml can create mach-o files with valid
2## __debug_ranges section.
3##
4## The DWARF should end up looking like:
5##
6## 0x0000000b: DW_TAG_compile_unit
7##               DW_AT_name        ("/tmp/main.c")
8##               DW_AT_language    (DW_LANG_C_plus_plus)
9##               DW_AT_low_pc      (0x0000000000000000)
10##               DW_AT_ranges      (0x00000000
11##                  [0x0000000000000000, 0x0000000000000020)
12##                  [0x0000000000000000, 0x0000000000000030)
13##                  [0x0000000000001000, 0x0000000000002000))
14##               DW_AT_stmt_list   (0x00000000)
15##
16## 0x00000022:   DW_TAG_subprogram
17##                 DW_AT_name      ("stripped1")
18##                 DW_AT_low_pc    (0x0000000000000000)
19##                 DW_AT_high_pc   (0x0000000000000020)
20##
21## 0x00000033:   DW_TAG_subprogram
22##                 DW_AT_name      ("stripped2")
23##                 DW_AT_low_pc    (0x0000000000000000)
24##                 DW_AT_high_pc   (0x0000000000000030)
25##
26## 0x00000048:   DW_TAG_subprogram
27##                 DW_AT_name      ("main")
28##                 DW_AT_low_pc    (0x0000000000001000)
29##                 DW_AT_high_pc   (0x0000000000002000)
30##
31## 0x00000059:   NULL
32
33# RUN: yaml2obj %s > %t
34# RUN: llvm-dwarfdump %t | FileCheck %s
35# RUN: obj2yaml %t | FileCheck --check-prefix=YAML %s
36
37# CHECK:      DW_AT_ranges	(0x00000000
38# CHECK-NEXT: [0x0000000000000000, 0x0000000000000020)
39# CHECK-NEXT: [0x0000000000000000, 0x0000000000000030)
40# CHECK-NEXT: [0x0000000000001000, 0x0000000000002000))
41
42# YAML:      - sectname:        __debug_ranges
43# YAML-NEXT:   segname:         __DWARF
44# YAML-NEXT:   addr:            0x7A
45# YAML-NEXT:   size:            80
46# YAML-NEXT:   offset:          0x28A
47
48# YAML:      debug_ranges:
49# YAML-NEXT:   - Offset:          0x0
50# YAML-NEXT:     AddrSize:        0x8
51# YAML-NEXT:     Entries:
52# YAML-NEXT:       - LowOffset:       0x0
53# YAML-NEXT:         HighOffset:      0x20
54# YAML-NEXT:       - LowOffset:       0x0
55# YAML-NEXT:         HighOffset:      0x30
56# YAML-NEXT:       - LowOffset:       0xFFFFFFFFFFFFFFFF
57# YAML-NEXT:         HighOffset:      0x1000
58# YAML-NEXT:       - LowOffset:       0x0
59# YAML-NEXT:         HighOffset:      0x1000
60
61--- !mach-o
62FileHeader:
63  magic:           0xFEEDFACF
64  cputype:         0x01000007
65  cpusubtype:      0x00000003
66  filetype:        0x00000001
67  ncmds:           4
68  sizeofcmds:      464
69  flags:           0x00002000
70  reserved:        0x00000000
71LoadCommands:
72  - cmd:             LC_SEGMENT_64
73    cmdsize:         392
74    segname:         ''
75    vmaddr:          0
76    vmsize:          240
77    fileoff:         528
78    filesize:        240
79    maxprot:         7
80    initprot:        7
81    nsects:          4
82    flags:           0
83    Sections:
84      - sectname:        __debug_abbrev
85        segname:         __DWARF
86        addr:            0x0000000000000000
87        size:            36
88        offset:          0x00000210
89        align:           0
90        reloff:          0x00000000
91        nreloc:          0
92        flags:           0x00000000
93        reserved1:       0x00000000
94        reserved2:       0x00000000
95        reserved3:       0x00000000
96      - sectname:        __debug_info
97        segname:         __DWARF
98        addr:            0x0000000000000024
99        size:            86
100        offset:          0x00000234
101        align:           0
102        reloff:          0x00000000
103        nreloc:          0
104        flags:           0x00000000
105        reserved1:       0x00000000
106        reserved2:       0x00000000
107        reserved3:       0x00000000
108      - sectname:        __debug_ranges
109        segname:         __DWARF
110        addr:            0x000000000000007A
111        size:            80
112        offset:          0x0000028A
113        align:           0
114        reloff:          0x00000000
115        nreloc:          0
116        flags:           0x00000000
117        reserved1:       0x00000000
118        reserved2:       0x00000000
119        reserved3:       0x00000000
120      - sectname:        __debug_str
121        segname:         __DWARF
122        addr:            0x00000000000000CA
123        size:            38
124        offset:          0x000002DA
125        align:           0
126        reloff:          0x00000000
127        nreloc:          0
128        flags:           0x00000000
129        reserved1:       0x00000000
130        reserved2:       0x00000000
131        reserved3:       0x00000000
132  - cmd:             LC_SYMTAB
133    cmdsize:         24
134    symoff:          0
135    nsyms:           0
136    stroff:          768
137    strsize:         8
138  - cmd:             LC_BUILD_VERSION
139    cmdsize:         32
140    platform:        1
141    minos:           658944
142    sdk:             658944
143    ntools:          1
144    Tools:
145      - tool:            3
146        version:         34734080
147  - cmd:             LC_DATA_IN_CODE
148    cmdsize:         16
149    dataoff:         768
150    datasize:        0
151LinkEditData:
152  StringTable:
153    - ' '
154    - ''
155    - ''
156    - ''
157    - ''
158    - ''
159    - ''
160DWARF:
161  debug_str:
162    - ''
163    - '/tmp/main.c'
164    - stripped1
165    - stripped2
166    - main
167  debug_abbrev:
168    - Table:
169        - Code:            0x00000001
170          Tag:             DW_TAG_compile_unit
171          Children:        DW_CHILDREN_yes
172          Attributes:
173            - Attribute:       DW_AT_name
174              Form:            DW_FORM_strp
175            - Attribute:       DW_AT_language
176              Form:            DW_FORM_data2
177            - Attribute:       DW_AT_low_pc
178              Form:            DW_FORM_addr
179            - Attribute:       DW_AT_ranges
180              Form:            DW_FORM_sec_offset
181        - Code:            0x00000002
182          Tag:             DW_TAG_subprogram
183          Children:        DW_CHILDREN_no
184          Attributes:
185            - Attribute:       DW_AT_name
186              Form:            DW_FORM_strp
187            - Attribute:       DW_AT_low_pc
188              Form:            DW_FORM_addr
189            - Attribute:       DW_AT_high_pc
190              Form:            DW_FORM_data4
191        - Code:            0x00000003
192          Tag:             DW_TAG_subprogram
193          Children:        DW_CHILDREN_no
194          Attributes:
195            - Attribute:       DW_AT_name
196              Form:            DW_FORM_strp
197            - Attribute:       DW_AT_low_pc
198              Form:            DW_FORM_addr
199            - Attribute:       DW_AT_high_pc
200              Form:            DW_FORM_addr
201  debug_ranges:
202    - Offset:          0x00000000
203      Entries:
204        - LowOffset:       0x0000000000000000
205          HighOffset:      0x0000000000000020
206        - LowOffset:       0x0000000000000000
207          HighOffset:      0x0000000000000030
208        - LowOffset:       0xFFFFFFFFFFFFFFFF
209          HighOffset:      0x0000000000001000
210        - LowOffset:       0x0000000000000000
211          HighOffset:      0x0000000000001000
212  debug_info:
213    - Length:          82
214      Version:         4
215      AbbrOffset:      0
216      AddrSize:        8
217      Entries:
218        - AbbrCode:        0x00000001
219          Values:
220            - Value:           0x0000000000000001
221            - Value:           0x0000000000000004
222            - Value:           0x0000000000000000
223            - Value:           0x0000000000000000
224        - AbbrCode:        0x00000002
225          Values:
226            - Value:           0x000000000000000D
227            - Value:           0x0000000000000000
228            - Value:           0x0000000000000020
229        - AbbrCode:        0x00000003
230          Values:
231            - Value:           0x0000000000000017
232            - Value:           0x0000000000000000
233            - Value:           0x0000000000000030
234        - AbbrCode:        0x00000002
235          Values:
236            - Value:           0x0000000000000021
237            - Value:           0x0000000000001000
238            - Value:           0x0000000000001000
239        - AbbrCode:        0x00000000
240          Values:          []
241...
242
243## Test generating and dumping an empty __debug_ranges section.
244
245# RUN: yaml2obj --docnum=2 %s | obj2yaml | FileCheck %s --check-prefix=EMPTY
246
247#      EMPTY: DWARF:
248# EMPTY-NEXT:   debug_ranges:    []
249# EMPTY-NEXT: ...
250
251--- !mach-o
252FileHeader:
253  magic:      0xFEEDFACF
254  cputype:    0x01000007
255  cpusubtype: 0x00000003
256  filetype:   0x0000000A
257  ncmds:      1
258  sizeofcmds: 232
259  flags:      0x00000000
260  reserved:   0x00000000
261LoadCommands:
262  - cmd:      LC_SEGMENT_64
263    cmdsize:  152
264    segname:  __DWARF
265    vmaddr:   0x00
266    vmsize:   0x00
267    fileoff:  0x00
268    filesize: 0x00
269    maxprot:  0
270    initprot: 0
271    nsects:   1
272    flags:    0
273    Sections:
274      - sectname:  __debug_ranges
275        segname:   __DWARF
276        addr:      0x00
277        size:      [[SIZE=0]]
278        offset:    0x210
279        align:     0
280        reloff:    0x00000000
281        nreloc:    0
282        flags:     0x00000000
283        reserved1: 0x00000000
284        reserved2: 0x00000000
285        reserved3: 0x00000000
286        content:   [[CONTENT=<none>]]
287
288## Test generating and dumping a __debug_ranges section whose size isn't a
289## multiple of the address size. This test case is to ensure that when the
290## parser fails, the content of the __debug_ranges section will be dumped into
291## the 'content' entry and the 'debug_ranges' entry will not exist.
292
293# RUN: yaml2obj --docnum=2 -DSIZE=3 -DCONTENT='010203' %s | obj2yaml | FileCheck %s --check-prefix=FAILS
294
295#  FAILS-NOT: DWARF:
296#      FAILS: Sections:
297# FAILS-NEXT:   - sectname:  __debug_ranges
298# FAILS-NEXT:     segname:   __DWARF
299# FAILS-NEXT:     addr:      0x0
300# FAILS-NEXT:     size:      3
301# FAILS-NEXT:     offset:    0x210
302# FAILS-NEXT:     align:     0
303# FAILS-NEXT:     reloff:    0x0
304# FAILS-NEXT:     nreloc:    0
305# FAILS-NEXT:     flags:     0x0
306# FAILS-NEXT:     reserved1: 0x0
307# FAILS-NEXT:     reserved2: 0x0
308# FAILS-NEXT:     reserved3: 0x0
309# FAILS-NEXT:     content:   '010203'
310# FAILS-NEXT: ...
311