bool IsLittleEndian;
bool Is64BitAddrSize;
std::vector<AbbrevTable> DebugAbbrev;
- std::vector<StringRef> DebugStrings;
+ Optional<std::vector<StringRef>> DebugStrings;
Optional<std::vector<StringOffsetsTable>> DebugStrOffsets;
Optional<std::vector<ARange>> DebugAranges;
std::vector<Ranges> DebugRanges;
}
Error DWARFYAML::emitDebugStr(raw_ostream &OS, const DWARFYAML::Data &DI) {
- for (auto Str : DI.DebugStrings) {
+ for (StringRef Str : *DI.DebugStrings) {
OS.write(Str.data(), Str.size());
OS.write('\0');
}
SetVector<StringRef> DWARFYAML::Data::getNonEmptySectionNames() const {
SetVector<StringRef> SecNames;
- if (!DebugStrings.empty())
+ if (DebugStrings)
SecNames.insert("debug_str");
if (DebugAranges)
SecNames.insert("debug_aranges");
-# RUN: yaml2obj %s | obj2yaml | FileCheck %s
+## a) Test that obj2yaml is able to dump the __debug_str section.
+
+# RUN: yaml2obj --docnum=1 %s | obj2yaml | FileCheck %s
--- !mach-o
FileHeader:
#CHECK: - int
#CHECK: - char
+## b) Test dumping an empty __debug_str section.
+
+# RUN: yaml2obj --docnum=2 -DCONTENT='[]' %s | obj2yaml | FileCheck %s --check-prefix=EMPTY-CONTENT
+
+# EMPTY-CONTENT: Sections:
+# EMPTY-CONTENT-NEXT: - sectname: __debug_str
+# EMPTY-CONTENT-NEXT: segname: __DWARF
+# EMPTY-CONTENT-NEXT: addr: 0x0000000000000000
+# EMPTY-CONTENT-NEXT: size: 0
+# EMPTY-CONTENT-NEXT: offset: 0x00000210
+# EMPTY-CONTENT-NEXT: align: 0
+# EMPTY-CONTENT-NEXT: reloff: 0x00000000
+# EMPTY-CONTENT-NEXT: nreloc: 0
+# EMPTY-CONTENT-NEXT: flags: 0x00000000
+# EMPTY-CONTENT-NEXT: reserved1: 0x00000000
+# EMPTY-CONTENT-NEXT: reserved2: 0x00000000
+# EMPTY-CONTENT-NEXT: reserved3: 0x00000000
+# EMPTY-CONTENT-NEXT: DWARF:
+# EMPTY-CONTENT-NEXT: debug_str: []
+
+--- !mach-o
+FileHeader:
+ magic: 0xFEEDFACF
+ cputype: 0x01000007
+ cpusubtype: 0x00000003
+ filetype: 0x0000000A
+ ncmds: 1
+ sizeofcmds: 232
+ flags: 0x00000000
+ reserved: 0x00000000
+LoadCommands:
+ - cmd: LC_SEGMENT_64
+ cmdsize: 152
+ segname: __DWARF
+ vmaddr: 0x00
+ vmsize: 0x00
+ fileoff: 0x00
+ filesize: 0x00
+ maxprot: 0
+ initprot: 0
+ nsects: 1
+ flags: 0
+ Sections:
+ - sectname: __debug_str
+ segname: __DWARF
+ addr: 0x00
+ size: [[SIZE=0]]
+ offset: 0x210
+ align: 0
+ reloff: 0x00000000
+ nreloc: 0
+ flags: 0x00000000
+ reserved1: 0x00000000
+ reserved2: 0x00000000
+ reserved3: 0x00000000
+DWARF:
+ debug_str:
+ [[CONTENT]]
+
+## c) Test generating and dumping a __debug_str section who only has an empty string.
+
+# RUN: yaml2obj --docnum=2 -DCONTENT='[ "" ]' -DSIZE=1 %s | obj2yaml | FileCheck %s --check-prefix=EMPTY-STRING
+
+# EMPTY-STRING: DWARF:
+# EMPTY-STRING-NEXT: debug_str:
+# EMPTY-STRING-NEXT: - ''
+# EMPTY-STRING-NEXT: ...
## Check the default sh_type, sh_entsize, sh_info, sh_flags and sh_addralign of the
## .debug_str section header.
-# RUN: llvm-readelf -S %t1.o | FileCheck %s --check-prefix=SHDRS-DEFAULT
+# RUN: llvm-readelf -S %t1.o | FileCheck -DSIZE=000006 %s --check-prefix=SHDRS-DEFAULT
-# SHDRS-DEFAULT: Name Type Address Off Size ES Flg Lk Inf Al
-# SHDRS-DEFAULT: .debug_str PROGBITS 0000000000000000 000040 000006 01 MS 0 0 1
+# SHDRS-DEFAULT: Name Type Address Off Size ES Flg Lk Inf Al
+# SHDRS-DEFAULT: .debug_str PROGBITS 0000000000000000 000040 [[SIZE]] 01 MS 0 0 1
--- !ELF
FileHeader:
DWARF:
debug_str:
- a
+
+## i) Test that the .debug_str section header is emitted if the "debug_str"
+## entry is empty.
+
+# RUN: yaml2obj --docnum=10 %s -o %t10.o
+# RUN: llvm-readelf -S %t10.o | FileCheck -DSIZE=000000 %s --check-prefix=SHDRS-DEFAULT
+
+--- !ELF
+FileHeader:
+ Class: ELFCLASS64
+ Data: ELFDATA2LSB
+ Type: ET_EXEC
+DWARF:
+ debug_str: []
void dumpDebugStrings(DWARFContext &DCtx, DWARFYAML::Data &Y) {
StringRef RemainingTable = DCtx.getDWARFObj().getStrSection();
+ Y.DebugStrings.emplace();
while (RemainingTable.size() > 0) {
auto SymbolPair = RemainingTable.split('\0');
RemainingTable = SymbolPair.second;
- Y.DebugStrings.push_back(SymbolPair.first);
+ Y.DebugStrings->push_back(SymbolPair.first);
}
}