311 lines · yaml
1## Test that yaml2obj and obj2yaml can create mach-o files with valid2## __debug_ranges section.3##4## The DWARF should end up looking like:5##6## 0x0000000b: DW_TAG_compile_unit7## 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 (0x0000000011## [0x0000000000000000, 0x0000000000000020)12## [0x0000000000000000, 0x0000000000000030)13## [0x0000000000001000, 0x0000000000002000))14## DW_AT_stmt_list (0x00000000)15##16## 0x00000022: DW_TAG_subprogram17## DW_AT_name ("stripped1")18## DW_AT_low_pc (0x0000000000000000)19## DW_AT_high_pc (0x0000000000000020)20##21## 0x00000033: DW_TAG_subprogram22## DW_AT_name ("stripped2")23## DW_AT_low_pc (0x0000000000000000)24## DW_AT_high_pc (0x0000000000000030)25##26## 0x00000048: DW_TAG_subprogram27## DW_AT_name ("main")28## DW_AT_low_pc (0x0000000000001000)29## DW_AT_high_pc (0x0000000000002000)30##31## 0x00000059: NULL32 33# RUN: yaml2obj %s > %t34# RUN: llvm-dwarfdump %t | FileCheck %s35# RUN: obj2yaml %t | FileCheck --check-prefix=YAML %s36 37# CHECK: DW_AT_ranges (0x0000000038# CHECK-NEXT: [0x0000000000000000, 0x0000000000000020)39# CHECK-NEXT: [0x0000000000000000, 0x0000000000000030)40# CHECK-NEXT: [0x0000000000001000, 0x0000000000002000))41 42# YAML: - sectname: __debug_ranges43# YAML-NEXT: segname: __DWARF44# YAML-NEXT: addr: 0x7A45# YAML-NEXT: size: 8046# YAML-NEXT: offset: 0x28A47 48# YAML: debug_ranges:49# YAML-NEXT: - Offset: 0x050# YAML-NEXT: AddrSize: 0x851# YAML-NEXT: Entries:52# YAML-NEXT: - LowOffset: 0x053# YAML-NEXT: HighOffset: 0x2054# YAML-NEXT: - LowOffset: 0x055# YAML-NEXT: HighOffset: 0x3056# YAML-NEXT: - LowOffset: 0xFFFFFFFFFFFFFFFF57# YAML-NEXT: HighOffset: 0x100058# YAML-NEXT: - LowOffset: 0x059# YAML-NEXT: HighOffset: 0x100060 61--- !mach-o62FileHeader:63 magic: 0xFEEDFACF64 cputype: 0x0100000765 cpusubtype: 0x0000000366 filetype: 0x0000000167 ncmds: 468 sizeofcmds: 46469 flags: 0x0000200070 reserved: 0x0000000071LoadCommands:72 - cmd: LC_SEGMENT_6473 cmdsize: 39274 segname: ''75 vmaddr: 076 vmsize: 24077 fileoff: 52878 filesize: 24079 maxprot: 780 initprot: 781 nsects: 482 flags: 083 Sections:84 - sectname: __debug_abbrev85 segname: __DWARF86 addr: 0x000000000000000087 size: 3688 offset: 0x0000021089 align: 090 reloff: 0x0000000091 nreloc: 092 flags: 0x0000000093 reserved1: 0x0000000094 reserved2: 0x0000000095 reserved3: 0x0000000096 - sectname: __debug_info97 segname: __DWARF98 addr: 0x000000000000002499 size: 86100 offset: 0x00000234101 align: 0102 reloff: 0x00000000103 nreloc: 0104 flags: 0x00000000105 reserved1: 0x00000000106 reserved2: 0x00000000107 reserved3: 0x00000000108 - sectname: __debug_ranges109 segname: __DWARF110 addr: 0x000000000000007A111 size: 80112 offset: 0x0000028A113 align: 0114 reloff: 0x00000000115 nreloc: 0116 flags: 0x00000000117 reserved1: 0x00000000118 reserved2: 0x00000000119 reserved3: 0x00000000120 - sectname: __debug_str121 segname: __DWARF122 addr: 0x00000000000000CA123 size: 38124 offset: 0x000002DA125 align: 0126 reloff: 0x00000000127 nreloc: 0128 flags: 0x00000000129 reserved1: 0x00000000130 reserved2: 0x00000000131 reserved3: 0x00000000132 - cmd: LC_SYMTAB133 cmdsize: 24134 symoff: 0135 nsyms: 0136 stroff: 768137 strsize: 8138 - cmd: LC_BUILD_VERSION139 cmdsize: 32140 platform: 1141 minos: 658944142 sdk: 658944143 ntools: 1144 Tools:145 - tool: 3146 version: 34734080147 - cmd: LC_DATA_IN_CODE148 cmdsize: 16149 dataoff: 768150 datasize: 0151LinkEditData:152 StringTable:153 - ' '154 - ''155 - ''156 - ''157 - ''158 - ''159 - ''160DWARF:161 debug_str:162 - ''163 - '/tmp/main.c'164 - stripped1165 - stripped2166 - main167 debug_abbrev:168 - Table:169 - Code: 0x00000001170 Tag: DW_TAG_compile_unit171 Children: DW_CHILDREN_yes172 Attributes:173 - Attribute: DW_AT_name174 Form: DW_FORM_strp175 - Attribute: DW_AT_language176 Form: DW_FORM_data2177 - Attribute: DW_AT_low_pc178 Form: DW_FORM_addr179 - Attribute: DW_AT_ranges180 Form: DW_FORM_sec_offset181 - Code: 0x00000002182 Tag: DW_TAG_subprogram183 Children: DW_CHILDREN_no184 Attributes:185 - Attribute: DW_AT_name186 Form: DW_FORM_strp187 - Attribute: DW_AT_low_pc188 Form: DW_FORM_addr189 - Attribute: DW_AT_high_pc190 Form: DW_FORM_data4191 - Code: 0x00000003192 Tag: DW_TAG_subprogram193 Children: DW_CHILDREN_no194 Attributes:195 - Attribute: DW_AT_name196 Form: DW_FORM_strp197 - Attribute: DW_AT_low_pc198 Form: DW_FORM_addr199 - Attribute: DW_AT_high_pc200 Form: DW_FORM_addr201 debug_ranges:202 - Offset: 0x00000000203 Entries:204 - LowOffset: 0x0000000000000000205 HighOffset: 0x0000000000000020206 - LowOffset: 0x0000000000000000207 HighOffset: 0x0000000000000030208 - LowOffset: 0xFFFFFFFFFFFFFFFF209 HighOffset: 0x0000000000001000210 - LowOffset: 0x0000000000000000211 HighOffset: 0x0000000000001000212 debug_info:213 - Length: 82214 Version: 4215 AbbrOffset: 0216 AddrSize: 8217 Entries:218 - AbbrCode: 0x00000001219 Values:220 - Value: 0x0000000000000001221 - Value: 0x0000000000000004222 - Value: 0x0000000000000000223 - Value: 0x0000000000000000224 - AbbrCode: 0x00000002225 Values:226 - Value: 0x000000000000000D227 - Value: 0x0000000000000000228 - Value: 0x0000000000000020229 - AbbrCode: 0x00000003230 Values:231 - Value: 0x0000000000000017232 - Value: 0x0000000000000000233 - Value: 0x0000000000000030234 - AbbrCode: 0x00000002235 Values:236 - Value: 0x0000000000000021237 - Value: 0x0000000000001000238 - Value: 0x0000000000001000239 - AbbrCode: 0x00000000240 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=EMPTY246 247# EMPTY: DWARF:248# EMPTY-NEXT: debug_ranges: []249# EMPTY-NEXT: ...250 251--- !mach-o252FileHeader:253 magic: 0xFEEDFACF254 cputype: 0x01000007255 cpusubtype: 0x00000003256 filetype: 0x0000000A257 ncmds: 1258 sizeofcmds: 232259 flags: 0x00000000260 reserved: 0x00000000261LoadCommands:262 - cmd: LC_SEGMENT_64263 cmdsize: 152264 segname: __DWARF265 vmaddr: 0x00266 vmsize: 0x00267 fileoff: 0x00268 filesize: 0x00269 maxprot: 0270 initprot: 0271 nsects: 1272 flags: 0273 Sections:274 - sectname: __debug_ranges275 segname: __DWARF276 addr: 0x00277 size: [[SIZE=0]]278 offset: 0x210279 align: 0280 reloff: 0x00000000281 nreloc: 0282 flags: 0x00000000283 reserved1: 0x00000000284 reserved2: 0x00000000285 reserved3: 0x00000000286 content: [[CONTENT=<none>]]287 288## Test generating and dumping a __debug_ranges section whose size isn't a289## multiple of the address size. This test case is to ensure that when the290## parser fails, the content of the __debug_ranges section will be dumped into291## 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=FAILS294 295# FAILS-NOT: DWARF:296# FAILS: Sections:297# FAILS-NEXT: - sectname: __debug_ranges298# FAILS-NEXT: segname: __DWARF299# FAILS-NEXT: addr: 0x0300# FAILS-NEXT: size: 3301# FAILS-NEXT: offset: 0x210302# FAILS-NEXT: align: 0303# FAILS-NEXT: reloff: 0x0304# FAILS-NEXT: nreloc: 0305# FAILS-NEXT: flags: 0x0306# FAILS-NEXT: reserved1: 0x0307# FAILS-NEXT: reserved2: 0x0308# FAILS-NEXT: reserved3: 0x0309# FAILS-NEXT: content: '010203'310# FAILS-NEXT: ...311