[llvm] 0e47a8d - [obj2yaml] Add support for dumping the .debug_ranges section.
Xing GUO via llvm-commits
llvm-commits at lists.llvm.org
Thu Sep 10 17:48:45 PDT 2020
Author: Xing GUO
Date: 2020-09-11T08:47:01+08:00
New Revision: 0e47a8d17fe85b4ab810a17cde4178b2729f2363
URL: https://github.com/llvm/llvm-project/commit/0e47a8d17fe85b4ab810a17cde4178b2729f2363
DIFF: https://github.com/llvm/llvm-project/commit/0e47a8d17fe85b4ab810a17cde4178b2729f2363.diff
LOG: [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
Added:
llvm/test/tools/obj2yaml/ELF/DWARF/debug-ranges.yaml
Modified:
llvm/tools/obj2yaml/elf2yaml.cpp
Removed:
################################################################################
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 000000000000..0e3fbae13071
--- /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
+##
diff erent 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=<none>]]
+ - Version: 4
+ AddrSize: [[ADDRSIZE2=<none>]]
+ debug_ranges:
+ - AddrSize: [[ADDRSIZE3=<none>]]
+ Entries:
+ - LowOffset: 0x10
+ HighOffset: 0x20
+ - LowOffset: 0x30
+ HighOffset: 0x40
+ - AddrSize: [[ADDRSIZE4=<none>]]
+ 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=<none>]]
+ Link: [[LINK='']]
+ EntSize: [[ENTSIZE=<none>]]
+ Info: [[INFO=<none>]]
+ AddressAlign: [[ADDRALIGN=0]]
+ Address: [[ADDRESS=<none>]]
+ - 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 94819cb8d87d..22fbdd2ed72e 100644
--- a/llvm/tools/obj2yaml/elf2yaml.cpp
+++ b/llvm/tools/obj2yaml/elf2yaml.cpp
@@ -416,6 +416,8 @@ Optional<DWARFYAML::Data> ELFDumper<ELFT>::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;
More information about the llvm-commits
mailing list