From 0e47a8d17fe85b4ab810a17cde4178b2729f2363 Mon Sep 17 00:00:00 2001 From: Xing GUO Date: Fri, 11 Sep 2020 08:42:16 +0800 Subject: [PATCH] [obj2yaml] Add support for dumping the .debug_ranges section. This patch adds support for dumping the .debug_ranges section to elf2yaml. Reviewed By: jhenderson Differential Revision: https://reviews.llvm.org/D87429 --- .../tools/obj2yaml/ELF/DWARF/debug-ranges.yaml | 233 +++++++++++++++++++++ llvm/tools/obj2yaml/elf2yaml.cpp | 2 + 2 files changed, 235 insertions(+) create mode 100644 llvm/test/tools/obj2yaml/ELF/DWARF/debug-ranges.yaml 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 index 0000000..0e3fbae --- /dev/null +++ b/llvm/test/tools/obj2yaml/ELF/DWARF/debug-ranges.yaml @@ -0,0 +1,233 @@ +## 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 %s -DBITS=32 -DLOWOFFSET=0xFFFFFFFF \ +# RUN: -DHIGHOFFSET=0x10 | obj2yaml | \ +# RUN: FileCheck %s --check-prefix=BASIC -DADDRSIZE=0x04 \ +# RUN: -DOFFSET=0x0000000000000018 -DLOWOFFSET=0x00000000FFFFFFFF \ +# RUN: -DHIGHOFFSET=0x0000000000000010 + +## 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 %s -DBITS=32 -DENDIAN=MSB -DLOWOFFSET=0xFFFFFFFF \ +# RUN: -DHIGHOFFSET=0x10 | obj2yaml | \ +# RUN: FileCheck %s --check-prefix=BASIC -DADDRSIZE=0x04 \ +# RUN: -DOFFSET=0x0000000000000018 -DLOWOFFSET=0x00000000FFFFFFFF \ +# RUN: -DHIGHOFFSET=0x0000000000000010 + +## 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 %s -DBITS=32 -DADDRSIZE1=8 \ +# RUN: -DADDRSIZE2=8 -DADDRSIZE3=8 -DADDRSIZE4=8 \ +# RUN: -DLOWOFFSET=0xFFFFFFFFFFFFFFFF -DHIGHOFFSET=0x10 | obj2yaml | \ +# RUN: FileCheck %s --check-prefix=BASIC -DADDRSIZE=0x08 \ +# RUN: -DOFFSET=0x0000000000000030 -DLOWOFFSET=0xFFFFFFFFFFFFFFFF \ +# RUN: -DHIGHOFFSET=0x0000000000000010 + +## 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 %s -DBITS=32 -DENDIAN=MSB -DADDRSIZE1=8 \ +# RUN: -DADDRSIZE2=8 -DADDRSIZE3=8 -DADDRSIZE4=8 \ +# RUN: -DLOWOFFSET=0xFFFFFFFFFFFFFFFF -DHIGHOFFSET=0x10 | obj2yaml | \ +# RUN: FileCheck %s --check-prefix=BASIC -DADDRSIZE=0x08 \ +# RUN: -DOFFSET=0x0000000000000030 -DLOWOFFSET=0xFFFFFFFFFFFFFFFF \ +# RUN: -DHIGHOFFSET=0x0000000000000010 + +## 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 %s -DLOWOFFSET=0xFFFFFFFFFFFFFFFF \ +# RUN: -DHIGHOFFSET=0x10 | obj2yaml | \ +# RUN: FileCheck %s --check-prefix=BASIC -DADDRSIZE=0x08 \ +# RUN: -DOFFSET=0x0000000000000030 -DLOWOFFSET=0xFFFFFFFFFFFFFFFF \ +# RUN: -DHIGHOFFSET=0x0000000000000010 + +## 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 %s -DENDIAN=MSB -DLOWOFFSET=0xFFFFFFFFFFFFFFFF \ +# RUN: -DHIGHOFFSET=0x10 | obj2yaml | \ +# RUN: FileCheck %s --check-prefix=BASIC -DADDRSIZE=0x08 \ +# RUN: -DOFFSET=0x0000000000000030 -DLOWOFFSET=0xFFFFFFFFFFFFFFFF \ +# RUN: -DHIGHOFFSET=0x0000000000000010 + +## 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 %s -DADDRSIZE1=4 -DADDRSIZE2=4 -DADDRSIZE3=4 \ +# RUN: -DADDRSIZE4=4 -DLOWOFFSET=0xFFFFFFFFFFFFFFFF \ +# RUN: -DHIGHOFFSET=0x10 | obj2yaml | \ +# RUN: FileCheck %s --check-prefix=BASIC -DADDRSIZE=0x04 \ +# RUN: -DOFFSET=0x0000000000000018 -DLOWOFFSET=0x00000000FFFFFFFF \ +# RUN: -DHIGHOFFSET=0x0000000000000010 + +## 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 %s -DADDRSIZE1=4 -DADDRSIZE2=4 -DADDRSIZE3=4 \ +# RUN: -DADDRSIZE4=4 -DLOWOFFSET=0xFFFFFFFFFFFFFFFF \ +# RUN: -DHIGHOFFSET=0x10 | obj2yaml | \ +# RUN: FileCheck %s --check-prefix=BASIC -DADDRSIZE=0x04 \ +# RUN: -DOFFSET=0x0000000000000018 -DLOWOFFSET=0x00000000FFFFFFFF \ +# RUN: -DHIGHOFFSET=0x0000000000000010 + + +# 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: [[OFFSET]] +# BASIC-NEXT: AddrSize: [[ADDRSIZE]] +# BASIC-NEXT: Entries: +# BASIC-NEXT: - LowOffset: [[LOWOFFSET]] +# BASIC-NEXT: HighOffset: [[HIGHOFFSET]] + +--- !ELF +FileHeader: + Class: ELFCLASS[[BITS=64]] + Data: ELFDATA2[[ENDIAN=LSB]] + Type: ET_EXEC +DWARF: + ## The debug_ranges parser depends on the address_size field + ## of compilation units. We add the .debug_info section to + ## assist the parser. + 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 | \ +# RUN: 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-SAME: {{^}}2000000000000000 +## ^--------------- HighOffset +# RAW-SAME: {{^}}3000000000000000 +## ^--------------- LowOffset +# RAW-SAME: {{^}}4000000000000000 +## ^--------------- HighOffset +# RAW-SAME: {{^}}0000000000000000 +## ^--------------- +# RAW-SAME: {{^}}0000000000000000 +## ---------------- terminator +# RAW-SAME: {{^}}1000000000000000 +## ^--------------- LowOffset +# RAW-SAME: {{^}}2000000000000000 +## ^--------------- HighOffset +# RAW-SAME: {{^}}0000000000000000 +## ^--------------- +# RAW-SAME: {{^}}0000000000000000' +## ---------------- terminator + +## c) Test dumping an empty .debug_ranges section. + +# RUN: yaml2obj --docnum=2 %s | obj2yaml | \ +# RUN: FileCheck %s --check-prefix=EMPTY --implicit-check-not=Sections: + +# 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 | \ +# RUN: FileCheck %s -DTYPE=STRTAB --check-prefixes=COMMON + +## Override the sh_flags field. +# RUN: yaml2obj --docnum=3 -DFLAGS=[SHF_ALLOC] %s | obj2yaml | \ +# RUN: FileCheck %s -DTYPE=PROGBITS --check-prefixes=COMMON,FLAGS + +## Override the sh_link field. +# RUN: yaml2obj --docnum=3 -DLINK='.sec' %s | obj2yaml | \ +# RUN: FileCheck %s -DTYPE=PROGBITS --check-prefixes=COMMON,LINK + +## Override the sh_entsize field. +# RUN: yaml2obj --docnum=3 -DENTSIZE=3 %s | obj2yaml | \ +# RUN: FileCheck %s -DTYPE=PROGBITS --check-prefixes=COMMON,ENTSIZE + +## Override the sh_info field. +# RUN: yaml2obj --docnum=3 -DINFO=3 %s | obj2yaml | \ +# RUN: FileCheck %s -DTYPE=PROGBITS --check-prefixes=COMMON,INFO + +## Override the sh_addralign field. +# RUN: yaml2obj --docnum=3 -DADDRALIGN=3 %s | obj2yaml | \ +# RUN: FileCheck %s -DTYPE=PROGBITS --check-prefixes=COMMON,ADDRALIGN + +## Override the sh_address field. +# RUN: yaml2obj --docnum=3 -DADDRESS=0x2020 %s | obj2yaml | \ +# RUN: FileCheck %s -DTYPE=PROGBITS --check-prefixes=COMMON,ADDRESS + +# COMMON: - Name: .debug_ranges +# COMMON-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 + +# COMMON: debug_ranges: +# COMMON-NEXT: - Offset: 0x0000000000000000 +# COMMON-NEXT: AddrSize: 0x08 +# COMMON-NEXT: Entries: +# COMMON-NEXT: - LowOffset: 0x0000000000000010 +# COMMON-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 index 94819cb..22fbdd2 100644 --- a/llvm/tools/obj2yaml/elf2yaml.cpp +++ b/llvm/tools/obj2yaml/elf2yaml.cpp @@ -416,6 +416,8 @@ Optional ELFDumper::dumpDWARFSections( 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; -- 2.7.4