diff --git a/llvm/test/tools/obj2yaml/ELF/DWARF/debug-ranges.yaml b/llvm/test/tools/obj2yaml/ELF/DWARF/debug-ranges.yaml new file mode 100644 --- /dev/null +++ b/llvm/test/tools/obj2yaml/ELF/DWARF/debug-ranges.yaml @@ -0,0 +1,181 @@ +## Test how we dump the .debug_ranges section. + +## a) Test dumping the .debug_ranges section from various object files with different endian and bits. + +## Dump the .debug_ranges section from a 32-bit little endian object file where the address_size of debug_info is 4. +# RUN: yaml2obj --docnum=1 -DBITS=32 -DLOWOFFSET=0xffffffff -DHIGHOFFSET=0x10 %s | \ +# RUN: obj2yaml | FileCheck -DADDRSIZE=0x04 -D#%x,OFFSET=0x18 -D#%x,LOWOFFSET=0xffffffff -D#%x,HIGHOFFSET=0x10 %s --check-prefix=BASIC + +## Dump the .debug_ranges section from a 32-bit big endian object file where the address_size of debug_info is 4. +# RUN: yaml2obj --docnum=1 -DBITS=32 -DENDIAN=MSB -DLOWOFFSET=0xffffffff -DHIGHOFFSET=0x10 %s | \ +# RUN: obj2yaml | FileCheck -DADDRSIZE=0x04 -D#%x,OFFSET=0x18 -D#%x,LOWOFFSET=0xffffffff -D#%x,HIGHOFFSET=0x10 %s --check-prefix=BASIC + +## Dump the .debug_ranges section from a 32-bit little endian object file where the address_size of debug_info is 8. +# RUN: yaml2obj --docnum=1 -DBITS=32 -DADDRSIZE1=8 -DADDRSIZE2=8 -DADDRSIZE3=8 -DADDRSIZE4=8 -DLOWOFFSET=0xffffffffffffffff -DHIGHOFFSET=0x10 %s | \ +# RUN: obj2yaml | FileCheck -DADDRSIZE=0x08 -D#%x,OFFSET=0x30 -D#%x,LOWOFFSET=0xffffffffffffffff -D#%x,HIGHOFFSET=0x10 %s --check-prefix=BASIC + +## Dump the .debug_ranges section from a 32-bit big endian object file where the address_size of debug_info is 8. +# RUN: yaml2obj --docnum=1 -DBITS=32 -DENDIAN=MSB -DADDRSIZE1=8 -DADDRSIZE2=8 -DADDRSIZE3=8 -DADDRSIZE4=8 -DLOWOFFSET=0xffffffffffffffff -DHIGHOFFSET=0x10 %s | \ +# RUN: obj2yaml | FileCheck -DADDRSIZE=0x08 -D#%x,OFFSET=0x30 -D#%x,LOWOFFSET=0xffffffffffffffff -D#%x,HIGHOFFSET=0x10 %s --check-prefix=BASIC + +## Dump the .debug_ranges section from a 64-bit little endian object file where the address_size of debug_info is 8. +# RUN: yaml2obj --docnum=1 -DLOWOFFSET=0xffffffffffffffff -DHIGHOFFSET=0x10 %s | \ +# RUN: obj2yaml | FileCheck -DADDRSIZE=0x08 -D#%x,OFFSET=0x30 -D#%x,LOWOFFSET=0xffffffffffffffff -D#%x,HIGHOFFSET=0x10 %s --check-prefix=BASIC + +## Dump the .debug_ranges section from a 64-bit big endian object file where the address_size of debug_info is 8. +# RUN: yaml2obj --docnum=1 -DENDIAN=MSB -DLOWOFFSET=0xffffffffffffffff -DHIGHOFFSET=0x10 %s | \ +# RUN: obj2yaml | FileCheck -DADDRSIZE=0x08 -D#%x,OFFSET=0x30 -D#%x,LOWOFFSET=0xffffffffffffffff -D#%x,HIGHOFFSET=0x10 %s --check-prefix=BASIC + +## Dump the .debug_ranges section from a 64-bit little endian object file where the address_size of debug_info is 4. +# RUN: yaml2obj --docnum=1 -DADDRSIZE1=4 -DADDRSIZE2=4 -DADDRSIZE3=4 -DADDRSIZE4=4 -DLOWOFFSET=0xffffffff -DHIGHOFFSET=0x10 %s | \ +# RUN: obj2yaml | FileCheck -DADDRSIZE=0x04 -D#%x,OFFSET=0x18 -D#%x,LOWOFFSET=0xffffffff -D#%x,HIGHOFFSET=0x10 %s --check-prefix=BASIC + +## Dump the .debug_ranges section from a 64-bit big endian object file where the address_size of debug_info is 4. +# RUN: yaml2obj --docnum=1 -DENDIAN=MSB -DADDRSIZE1=4 -DADDRSIZE2=4 -DADDRSIZE3=4 -DADDRSIZE4=4 -DLOWOFFSET=0xffffffff -DHIGHOFFSET=0x10 %s | \ +# RUN: obj2yaml | FileCheck -DADDRSIZE=0x04 -D#%x,OFFSET=0x18 -D#%x,LOWOFFSET=0xffffffff -D#%x,HIGHOFFSET=0x10 %s --check-prefix=BASIC + +# BASIC-NOT: debug_ranges +# BASIC: debug_ranges: +# BASIC-NEXT: - Offset: 0x0000000000000000 +# BASIC-NEXT: AddrSize: [[ADDRSIZE]] +# BASIC-NEXT: Entries: +# BASIC-NEXT: - LowOffset: 0x0000000000000010 +# BASIC-NEXT: HighOffset: 0x0000000000000020 +# BASIC-NEXT: - LowOffset: 0x0000000000000030 +# BASIC-NEXT: HighOffset: 0x0000000000000040 +# BASIC-NEXT: - Offset: 0x[[#%.16X,OFFSET]] +# BASIC-NEXT: AddrSize: [[ADDRSIZE]] +# BASIC-NEXT: Entries: +# BASIC-NEXT: - LowOffset: 0x[[#%.16X,LOWOFFSET]] +# BASIC-NEXT: HighOffset: 0x[[#%.16X,HIGHOFFSET]] + +--- !ELF +FileHeader: + Class: ELFCLASS[[BITS=64]] + Data: ELFDATA2[[ENDIAN=LSB]] + Type: ET_EXEC +DWARF: + debug_info: + - Version: 4 + AddrSize: [[ADDRSIZE1=]] + - Version: 4 + AddrSize: [[ADDRSIZE2=]] + debug_ranges: + - AddrSize: [[ADDRSIZE3=]] + Entries: + - LowOffset: 0x10 + HighOffset: 0x20 + - LowOffset: 0x30 + HighOffset: 0x40 + - AddrSize: [[ADDRSIZE4=]] + Entries: + - LowOffset: [[LOWOFFSET=0x10]] + HighOffset: [[HIGHOFFSET=0x20]] + +## b) Test that obj2yaml dumps the .debug_ranges as a raw content section when the parser fails. +## In this case, the address_size of the two compilation units doesn't match. + +# RUN: yaml2obj --docnum=1 -DADDRSIZE1=4 -DADDRSIZE2=8 %s | obj2yaml | FileCheck %s --check-prefix=RAW --implicit-check-not=debug_ranges + +# RAW: - Name: .debug_ranges +# RAW-NEXT: Type: SHT_PROGBITS +# RAW-NEXT: AddressAlign: 0x0000000000000001 +# RAW-NEXT: Content: '1000000000000000 +## ^--------------- LowOffset +# RAW: 2000000000000000 +## ^--------------- HighOffset +# RAW: 3000000000000000 +## ^--------------- LowOffset +# RAW: 4000000000000000 +## ^--------------- HighOffset +# RAW: 0000000000000000 +## ^--------------- +# RAW: 0000000000000000 +## ---------------- terminator +# RAW: 1000000000000000 +## ^--------------- LowOffset +# RAW: 2000000000000000 +## ^--------------- HighOffset +# RAW: 0000000000000000 +## ^--------------- +# RAW: 0000000000000000' +## ---------------- terminator + +## c) Test dumping an empty .debug_ranges section. + +# RUN: yaml2obj --docnum=2 %s | obj2yaml | FileCheck %s --check-prefix=EMPTY --implicit-check-not=debug_ranges + +# EMPTY: DWARF: +# EMPTY-NEXT: debug_ranges: [] + +--- !ELF +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + Type: ET_EXEC +DWARF: + debug_ranges: [] + +## d) Test dumping a .debug_ranges section whose section header properties are overridden. + +## Override the sh_type field. +# RUN: yaml2obj --docnum=3 -DTYPE=SHT_STRTAB %s | obj2yaml | FileCheck %s -DTYPE=STRTAB --check-prefixes=RANGES,SHDR + +## Override the sh_flags field. +# RUN: yaml2obj --docnum=3 -DFLAGS=[SHF_ALLOC] %s | obj2yaml | FileCheck %s -DTYPE=PROGBITS --check-prefixes=RANGES,SHDR,FLAGS + +## Override the sh_link field. +# RUN: yaml2obj --docnum=3 -DLINK='.sec' %s | obj2yaml | FileCheck %s -DTYPE=PROGBITS --check-prefixes=RANGES,SHDR,LINK + +## Override the sh_entsize field. +# RUN: yaml2obj --docnum=3 -DENTSIZE=3 %s | obj2yaml | FileCheck %s -DTYPE=PROGBITS --check-prefixes=RANGES,SHDR,ENTSIZE + +## Override the sh_info field. +# RUN: yaml2obj --docnum=3 -DINFO=3 %s | obj2yaml | FileCheck %s -DTYPE=PROGBITS --check-prefixes=RANGES,SHDR,INFO + +## Override the sh_addralign field. +# RUN: yaml2obj --docnum=3 -DADDRALIGN=3 %s | obj2yaml | FileCheck %s -DTYPE=PROGBITS --check-prefixes=RANGES,SHDR,ADDRALIGN + +## Override the sh_address field. +# RUN: yaml2obj --docnum=3 -DADDRESS=0x2020 %s | obj2yaml | FileCheck %s -DTYPE=PROGBITS --check-prefixes=RANGES,SHDR,ADDRESS + +# SHDR: - Name: .debug_ranges +# SHDR-NEXT: Type: SHT_[[TYPE]] +# FLAGS-NEXT: Flags: [ SHF_ALLOC ] +# LINK-NEXT: Link: .sec +# ENTSIZE-NEXT: EntSize: 0x0000000000000003 +# INFO-NEXT: Info: 0x0000000000000003 +# ADDRALIGN-NEXT: AddressAlign: 0x0000000000000003 +# ADDRESS-NEXT: Address: 0x0000000000002020 + +# RANGES: debug_ranges: +# RANGES-NEXT: - Offset: 0x0000000000000000 +# RANGES-NEXT: AddrSize: 0x08 +# RANGES-NEXT: Entries: +# RANGES-NEXT: - LowOffset: 0x0000000000000010 +# RANGES-NEXT: HighOffset: 0x0000000000000020 + +--- !ELF +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + Type: ET_EXEC +Sections: + - Name: .debug_ranges + Type: [[TYPE=SHT_PROGBITS]] + Flags: [[FLAGS=]] + Link: [[LINK='']] + EntSize: [[ENTSIZE=]] + Info: [[INFO=]] + AddressAlign: [[ADDRALIGN=0]] + Address: [[ADDRESS=]] + - Name: .sec + Type: SHT_PROGBITS +DWARF: + debug_info: + - Version: 4 + AddrSize: 8 + debug_ranges: + - Entries: + - LowOffset: 0x10 + HighOffset: 0x20 diff --git a/llvm/tools/obj2yaml/elf2yaml.cpp b/llvm/tools/obj2yaml/elf2yaml.cpp --- a/llvm/tools/obj2yaml/elf2yaml.cpp +++ b/llvm/tools/obj2yaml/elf2yaml.cpp @@ -416,6 +416,8 @@ Err = dumpDebugARanges(*DWARFCtx.get(), DWARF); else if (RawSec->Name == ".debug_str") Err = dumpDebugStrings(*DWARFCtx.get(), DWARF); + else if (RawSec->Name == ".debug_ranges") + Err = dumpDebugRanges(*DWARFCtx.get(), DWARF); else continue;