1# RUN: llvm-mc -triple i386-apple-darwin9 %s -filetype=obj -o %t.o
2# RUN: llvm-dwarfdump -v %t.o | FileCheck --check-prefix=COMMON %s
3#
4# Test object to verify dwarfdump handles v5 string offset tables in Mach-O.
5# This is similar to dwarfdump-str-offsets.s with 2 CUs and 1 TU, but no
6# split sections.
7#
8	.section	__DWARF,__debug_str,regular,debug
9Linfo_string:
10	.asciz "Handmade DWARF producer"
11str_CU1:
12        .asciz "Compile_Unit_1"
13str_CU1_dir:
14        .asciz "/home/test/CU1"
15str_CU2:
16        .asciz "Compile_Unit_2"
17str_CU2_dir:
18        .asciz "/home/test/CU2"
19str_TU:
20        .asciz "Type_Unit"
21str_TU_type:
22        .asciz "MyStruct"
23str_Subprogram:
24        .asciz "MyFunc"
25str_Variable1:
26        .asciz "MyVar1"
27str_Variable2:
28        .asciz "MyVar2"
29str_Variable3:
30        .asciz "MyVar3"
31
32	.section	__DWARF,__debug_str_offs,regular,debug
33Ldebug_str_offsets:
34        .long Ldebug_str_offsets_segment0_end-Ldebug_str_offsets_base0+4
35        .short 5    # DWARF version
36        .short 0    # Padding
37Ldebug_str_offsets_base0:
38        .long str_producer
39        .long str_CU1
40        .long str_CU1_dir
41        .long str_Subprogram
42        .long str_Variable1
43        .long str_Variable2
44        .long str_Variable3
45Ldebug_str_offsets_segment0_end:
46# A 4-byte gap.
47        .long 0
48# CU2's contribution (DWARF64 format)
49        .long 0xffffffff
50        .quad Ldebug_str_offsets_segment1_end-Ldebug_str_offsets_base1+4
51        .short 5    # DWARF version
52        .short 0    # Padding
53Ldebug_str_offsets_base1:
54        .quad str_producer
55        .quad str_CU2
56        .quad str_CU2_dir
57Ldebug_str_offsets_segment1_end:
58# The TU's contribution
59        .long Ldebug_str_offsets_segment2_end-Ldebug_str_offsets_base2+4
60        .short 5    # DWARF version
61        .short 0    # Padding
62Ldebug_str_offsets_base2:
63        .long str_TU
64        .long str_TU_type
65Ldebug_str_offsets_segment2_end:
66
67	.section	__DWARF,__debug_abbrev,regular,debug
68Lsection_abbrev:
69        .byte 0x01  # Abbrev code
70        .byte 0x11  # DW_TAG_compile_unit
71        .byte 0x01  # DW_CHILDREN_yes
72        .byte 0x25  # DW_AT_producer
73        .byte 0x1a  # DW_FORM_strx
74        .byte 0x03  # DW_AT_name
75        .byte 0x1a  # DW_FORM_strx
76        .byte 0x72  # DW_AT_str_offsets_base
77        .byte 0x17  # DW_FORM_sec_offset
78        .byte 0x1b  # DW_AT_comp_dir
79        .byte 0x1a  # DW_FORM_strx
80        .byte 0x00  # EOM(1)
81        .byte 0x00  # EOM(2)
82        .byte 0x02  # Abbrev code
83        .byte 0x41  # DW_TAG_type_unit
84        .byte 0x01  # DW_CHILDREN_yes
85        .byte 0x03  # DW_AT_name
86        .byte 0x1a  # DW_FORM_strx
87        .byte 0x72  # DW_AT_str_offsets_base
88        .byte 0x17  # DW_FORM_sec_offset
89        .byte 0x00  # EOM(1)
90        .byte 0x00  # EOM(2)
91        .byte 0x03  # Abbrev code
92        .byte 0x13  # DW_TAG_structure_type
93        .byte 0x00  # DW_CHILDREN_no (no members)
94        .byte 0x03  # DW_AT_name
95        .byte 0x1a  # DW_FORM_strx
96        .byte 0x00  # EOM(1)
97        .byte 0x00  # EOM(2)
98        .byte 0x04  # Abbrev code
99        .byte 0x2e  # DW_TAG_subprogram
100        .byte 0x01  # DW_CHILDREN_yes
101        .byte 0x03  # DW_AT_name
102        .byte 0x25  # DW_FORM_strx1
103        .byte 0x00  # EOM(1)
104        .byte 0x00  # EOM(2)
105        .byte 0x05  # Abbrev code
106        .byte 0x34  # DW_TAG_variable
107        .byte 0x00  # DW_CHILDREN_no
108        .byte 0x03  # DW_AT_name
109        .byte 0x26  # DW_FORM_strx2
110        .byte 0x00  # EOM(1)
111        .byte 0x00  # EOM(2)
112        .byte 0x06  # Abbrev code
113        .byte 0x34  # DW_TAG_variable
114        .byte 0x00  # DW_CHILDREN_no
115        .byte 0x03  # DW_AT_name
116        .byte 0x27  # DW_FORM_strx3
117        .byte 0x00  # EOM(1)
118        .byte 0x00  # EOM(2)
119        .byte 0x07  # Abbrev code
120        .byte 0x34  # DW_TAG_variable
121        .byte 0x00  # DW_CHILDREN_no
122        .byte 0x03  # DW_AT_name
123        .byte 0x28  # DW_FORM_strx4
124        .byte 0x00  # EOM(1)
125        .byte 0x00  # EOM(2)
126        .byte 0x00  # EOM(3)
127
128	.section	__DWARF,__debug_info,regular,debug
129Lsection_info:
130# DWARF v5 CU header.
131        .long  CU1_5_end-CU1_5_version  # Length of Unit
132CU1_5_version:
133        .short 5               # DWARF version number
134        .byte 1                # DWARF Unit Type
135        .byte 8                # Address Size (in bytes)
136        .long 0                # Offset Into Abbrev. Section
137# The compile-unit DIE, which has a DW_AT_producer, DW_AT_name,
138# DW_AT_str_offsets and DW_AT_compdir.
139        .byte 1                # Abbreviation code
140        .byte 0                # The index of the producer string
141        .byte 1                # The index of the CU name string
142        .long Ldebug_str_offsets_base0-Ldebug_str_offsets
143        .byte 2                # The index of the comp dir string
144# A subprogram DIE with DW_AT_name, using DW_FORM_strx1.
145        .byte 4                # Abbreviation code
146        .byte 3                # Subprogram name string (DW_FORM_strx1)
147# A variable DIE with DW_AT_name, using DW_FORM_strx2.
148        .byte 5                # Abbreviation code
149        .short 0x0004          # Subprogram name string (DW_FORM_strx2)
150# A variable DIE with DW_AT_name, using DW_FORM_strx3.
151        .byte 6                # Abbreviation code
152        .byte 5                # Subprogram name string (DW_FORM_strx3)
153        .short 0               # Subprogram name string (DW_FORM_strx3)
154# A variable DIE with DW_AT_name, using DW_FORM_strx4.
155        .byte 7                # Abbreviation code
156        .quad 0x00000006       # Subprogram name string (DW_FORM_strx4)
157        .byte 0 # NULL
158        .byte 0 # NULL
159        .byte 0 # NULL
160CU1_5_end:
161
162# DWARF v5 CU header
163        .long  CU2_5_end-CU2_5_version  # Length of Unit
164CU2_5_version:
165        .short 5               # DWARF version number
166        .byte 1                # DWARF Unit Type
167        .byte 8                # Address Size (in bytes)
168        .long 0                # Offset Into Abbrev. Section
169# The compile-unit DIE, which has a DW_AT_producer, DW_AT_name,
170# DW_AT_str_offsets and DW_AT_compdir.
171        .byte 1                # Abbreviation code
172        .byte 0                # The index of the producer string
173        .byte 1                # The index of the CU name string
174        .long Ldebug_str_offsets_base1-Ldebug_str_offsets
175        .byte 2                # The index of the comp dir string
176        .byte 0 # NULL
177CU2_5_end:
178
179	.section	__DWARF,__debug_types,regular,debug
180# DWARF v5 Type unit header.
181TU_5_start:
182        .long  TU_5_end-TU_5_version  # Length of Unit
183TU_5_version:
184        .short 5               # DWARF version number
185        .byte 2                # DWARF Unit Type
186        .byte 8                # Address Size (in bytes)
187        .long 0                # Offset Into Abbrev. Section
188        .quad 0x0011223344556677 # Type Signature
189        .long TU_5_type-TU_5_start # Type offset
190# The type-unit DIE, which has a name.
191        .byte 2                # Abbreviation code
192        .byte 0                # Index of the unit type name string
193        .long Ldebug_str_offsets_base2-Ldebug_str_offsets  # offset into the str_offsets section
194# The type DIE, which has a name.
195TU_5_type:
196        .byte 3                # Abbreviation code
197        .byte 1                # Index of the type name string
198        .byte 0 # NULL
199        .byte 0 # NULL
200TU_5_end:
201
202
203.subsections_via_symbols
204
205# We are using a hand-constructed object file and are interest in the correct
206# diplay of the DW_str_offsetsbase attribute and the correct display of strings.
207#
208# Abbreviation for DW_AT_str_offsets_base
209# COMMON:      .debug_abbrev contents:
210# COMMON-NOT:  contents:
211# COMMON:      DW_TAG_compile_unit
212# COMMON-NOT:  DW_TAG
213# COMMON:      DW_AT_str_offsets_base DW_FORM_sec_offset
214#
215# Verify that strings are displayed correctly as indexed strings
216# COMMON:      .debug_info contents:
217# COMMON-NOT:  contents:
218# COMMON:      DW_TAG_compile_unit
219# COMMON-NEXT: DW_AT_producer [DW_FORM_strx] ( indexed (00000000) string = "Handmade DWARF producer")
220# COMMON-NEXT: DW_AT_name [DW_FORM_strx] ( indexed (00000001) string = "Compile_Unit_1")
221# COMMON-NEXT: DW_AT_str_offsets_base [DW_FORM_sec_offset] (0x00000008)
222# COMMON-NEXT: DW_AT_comp_dir [DW_FORM_strx] ( indexed (00000002) string = "/home/test/CU1")
223# COMMON-NOT:  NULL
224# COMMON:      DW_TAG_subprogram
225# COMMON-NEXT: DW_AT_name [DW_FORM_strx1] ( indexed (00000003) string = "MyFunc")
226# COMMON-NOT:  NULL
227# COMMON:      DW_TAG_variable
228# COMMON-NEXT: DW_AT_name [DW_FORM_strx2] ( indexed (00000004) string = "MyVar1")
229# COMMON-NOT:  NULL
230# COMMON:      DW_TAG_variable
231# COMMON-NEXT: DW_AT_name [DW_FORM_strx3] ( indexed (00000005) string = "MyVar2")
232# COMMON-NOT:  NULL
233# COMMON:      DW_TAG_variable
234# COMMON-NEXT: DW_AT_name [DW_FORM_strx4] ( indexed (00000006) string = "MyVar3")
235#
236# Second compile unit (b.cpp)
237# COMMON:      DW_TAG_compile_unit
238# COMMON-NEXT: DW_AT_producer [DW_FORM_strx] ( indexed (00000000) string = "Handmade DWARF producer")
239# COMMON-NEXT: DW_AT_name [DW_FORM_strx] ( indexed (00000001) string = "Compile_Unit_2")
240# COMMON-NEXT: DW_AT_str_offsets_base [DW_FORM_sec_offset] (0x00000038)
241# COMMON-NEXT: DW_AT_comp_dir [DW_FORM_strx] ( indexed (00000002) string = "/home/test/CU2")
242#
243# The type unit
244# COMMON:      .debug_types contents:
245# COMMON:      DW_TAG_type_unit
246# COMMON-NEXT: DW_AT_name [DW_FORM_strx] ( indexed (00000000) string = "Type_Unit")
247# COMMON-NEXT: DW_AT_str_offsets_base [DW_FORM_sec_offset]       (0x00000058)
248# COMMON:      DW_TAG_structure_type
249# COMMON-NEXT: DW_AT_name [DW_FORM_strx] ( indexed (00000001) string = "MyStruct")
250#
251# The .debug_str_offsets section
252# COMMON:      .debug_str_offsets contents:
253# COMMON-NEXT: 0x00000000: Contribution size = 32, Format = DWARF32, Version = 5
254# COMMON-NEXT: 0x00000008: 00000000 "Handmade DWARF producer"
255# COMMON-NEXT: 0x0000000c: 00000018 "Compile_Unit_1"
256# COMMON-NEXT: 0x00000010: 00000027 "/home/test/CU1"
257# COMMON-NEXT: 0x00000014: 00000067 "MyFunc"
258# COMMON-NEXT: 0x00000018: 0000006e "MyVar1"
259# COMMON-NEXT: 0x0000001c: 00000075 "MyVar2"
260# COMMON-NEXT: 0x00000020: 0000007c "MyVar3"
261# COMMON-NEXT: 0x00000024: Gap, length = 4
262# COMMON-NEXT: 0x00000028: Contribution size = 28, Format = DWARF64, Version = 5
263# COMMON-NEXT: 0x00000038: 00000000 "Handmade DWARF producer"
264# COMMON-NEXT: 0x00000040: 00000036 "Compile_Unit_2"
265# COMMON-NEXT: 0x00000048: 00000045 "/home/test/CU2"
266# COMMON-NEXT: 0x00000050: Contribution size = 12, Format = DWARF32, Version = 5
267# COMMON-NEXT: 0x00000058: 00000054 "Type_Unit"
268# COMMON-NEXT: 0x0000005c: 0000005e "MyStruct"
269