_Z3barv:
.Lfunc_begin0:
.file 0 "/path" "test.cpp" md5 0x9ff11a8404ab4d032ee2dd4f5f8c4140
- .file 1 "test.cpp" md5 0x9ff11a8404ab4d032ee2dd4f5f8c4140
- .loc 1 2 0 # test.cpp:2:0
- .loc 1 2 20 prologue_end # test.cpp:2:20
+ .loc 0 2 0 # test.cpp:2:0
+ .loc 0 2 20 prologue_end # test.cpp:2:20
callq _Z3foov
- .loc 1 2 13 is_stmt 0 # test.cpp:2:13
+ .loc 0 2 13 is_stmt 0 # test.cpp:2:13
.Lfunc_end0:
.size _Z3barv, .Lfunc_end0-_Z3barv
# -- End function
.type _Z3bazv,@function
_Z3bazv: # @_Z3bazv
.Lfunc_begin1:
- .loc 1 3 0 is_stmt 1 # test.cpp:3:0
- .loc 1 3 20 prologue_end # test.cpp:3:20
+ .loc 0 3 0 is_stmt 1 # test.cpp:3:0
+ .loc 0 3 20 prologue_end # test.cpp:3:20
callq _Z3foov
- .loc 1 3 13 is_stmt 0 # test.cpp:3:13
+ .loc 0 3 13 is_stmt 0 # test.cpp:3:13
.Lfunc_end1:
.size _Z3bazv, .Lfunc_end1-_Z3bazv
main:
.Lfunc_begin0:
.file 0 "/home/path" "test.cpp" md5 0x8ed32099ab837bd13543fd3e8102739f
- .file 1 "test.cpp" md5 0x8ed32099ab837bd13543fd3e8102739f
- .loc 1 3 10 prologue_end
+ .loc 0 3 10 prologue_end
jmp _Z3foov
.Lfunc_end0:
bool hasFileAtIndex(uint64_t FileIndex) const;
/// Extracts filename by its index in filename table in prologue.
+ /// In Dwarf 4, the files are 1-indexed and the current compilation file
+ /// name is not represented in the list. In Dwarf 5, the files are
+ /// 0-indexed and the primary source file has the index 0.
/// Returns true on success.
bool getFileNameByIndex(uint64_t FileIndex, const char *CompDir,
DILineInfoSpecifier::FileLineInfoKind Kind,
SequenceVector Sequences;
private:
+ const llvm::DWARFDebugLine::FileNameEntry &
+ getFileNameEntry(uint64_t Index) const;
uint32_t findRowInSeq(const DWARFDebugLine::Sequence &Seq,
object::SectionedAddress Address) const;
Optional<StringRef>
class SMLoc;
class SourceMgr;
-/// Instances of this class represent the name of the dwarf
-/// .file directive and its associated dwarf file number in the MC file,
-/// and MCDwarfFile's are created and uniqued by the MCContext class where
-/// the file number for each is its index into the vector of DwarfFiles (note
-/// index 0 is not used and not a valid dwarf file number).
+/// Instances of this class represent the name of the dwarf .file directive and
+/// its associated dwarf file number in the MC file. MCDwarfFile's are created
+/// and uniqued by the MCContext class. In Dwarf 4 file numbers start from 1;
+/// i.e. the entry with file number 1 is the first element in the vector of
+/// DwarfFiles and there is no MCDwarfFile with file number 0. In Dwarf 5 file
+/// numbers start from 0, with the MCDwarfFile with file number 0 being the
+/// primary source file, and file numbers correspond to their index in the
+/// vector.
struct MCDwarfFile {
// The base name of the file without its directory path.
std::string Name;
Expected<unsigned> tryGetFile(StringRef &Directory, StringRef &FileName,
Optional<MD5::MD5Result> Checksum,
Optional<StringRef> Source,
+ uint16_t DwarfVersion,
unsigned FileNumber = 0);
std::pair<MCSymbol *, MCSymbol *>
Emit(MCStreamer *MCOS, MCDwarfLineTableParams Params,
return MCDwarfFiles.empty() || (HasAllMD5 == HasAnyMD5);
}
+ void setRootFile(StringRef Directory, StringRef FileName,
+ Optional<MD5::MD5Result> Checksum,
+ Optional<StringRef> Source) {
+ CompilationDir = Directory;
+ RootFile.Name = FileName;
+ RootFile.DirIndex = 0;
+ RootFile.Checksum = Checksum;
+ RootFile.Source = Source;
+ trackMD5Usage(Checksum.hasValue());
+ HasSource = Source.hasValue();
+ }
+
private:
void emitV2FileDirTables(MCStreamer *MCOS) const;
void emitV5FileDirTables(MCStreamer *MCOS, Optional<MCDwarfLineStr> &LineStr) const;
class MCDwarfDwoLineTable {
MCDwarfLineTableHeader Header;
+ bool HasSplitLineTable = false;
public:
void maybeSetRootFile(StringRef Directory, StringRef FileName,
- Optional<MD5::MD5Result> Checksum, Optional<StringRef> Source) {
+ Optional<MD5::MD5Result> Checksum,
+ Optional<StringRef> Source) {
if (!Header.RootFile.Name.empty())
return;
- Header.CompilationDir = Directory;
- Header.RootFile.Name = FileName;
- Header.RootFile.DirIndex = 0;
- Header.RootFile.Checksum = Checksum;
- Header.RootFile.Source = Source;
- Header.trackMD5Usage(Checksum.hasValue());
- Header.HasSource = Source.hasValue();
+ Header.setRootFile(Directory, FileName, Checksum, Source);
}
unsigned getFile(StringRef Directory, StringRef FileName,
- Optional<MD5::MD5Result> Checksum, Optional<StringRef> Source) {
- return cantFail(Header.tryGetFile(Directory, FileName, Checksum, Source));
+ Optional<MD5::MD5Result> Checksum, uint16_t DwarfVersion,
+ Optional<StringRef> Source) {
+ HasSplitLineTable = true;
+ return cantFail(Header.tryGetFile(Directory, FileName, Checksum, Source,
+ DwarfVersion));
}
void Emit(MCStreamer &MCOS, MCDwarfLineTableParams Params,
Expected<unsigned> tryGetFile(StringRef &Directory, StringRef &FileName,
Optional<MD5::MD5Result> Checksum,
Optional<StringRef> Source,
+ uint16_t DwarfVersion,
unsigned FileNumber = 0);
unsigned getFile(StringRef &Directory, StringRef &FileName,
Optional<MD5::MD5Result> Checksum, Optional<StringRef> Source,
- unsigned FileNumber = 0) {
+ uint16_t DwarfVersion, unsigned FileNumber = 0) {
return cantFail(tryGetFile(Directory, FileName, Checksum, Source,
- FileNumber));
+ DwarfVersion, FileNumber));
}
void setRootFile(StringRef Directory, StringRef FileName,
addSectionOffset(getUnitDie(), dwarf::DW_AT_stmt_list, 0);
}
return SplitLineTable->getFile(File->getDirectory(), File->getFilename(),
- getMD5AsBytes(File), File->getSource());
+ getMD5AsBytes(File),
+ Asm->OutContext.getDwarfVersion(),
+ File->getSource());
}
void DwarfUnit::addOpAddress(DIELoc &Die, const MCSymbol *Sym) {
return;
unsigned FileID = getOrCreateSourceID(File);
- assert(FileID && "Invalid file id");
addUInt(Die, dwarf::DW_AT_decl_file, None, FileID);
addUInt(Die, dwarf::DW_AT_decl_line, None, Line);
}
}
bool DWARFDebugLine::LineTable::hasFileAtIndex(uint64_t FileIndex) const {
+ uint16_t DwarfVersion = Prologue.getVersion();
+ assert(DwarfVersion != 0 && "LineTable has no dwarf version information");
+ if (DwarfVersion >= 5)
+ return FileIndex < Prologue.FileNames.size();
return FileIndex != 0 && FileIndex <= Prologue.FileNames.size();
}
+const llvm::DWARFDebugLine::FileNameEntry &
+DWARFDebugLine::LineTable::getFileNameEntry(uint64_t Index) const {
+ uint16_t DwarfVersion = Prologue.getVersion();
+ assert(DwarfVersion != 0 && "LineTable has no dwarf version information");
+ // Unlike previous versions, in Dwarf 5 the file names is 0-indexed.
+ if (DwarfVersion >= 5)
+ return Prologue.FileNames[Index];
+ else
+ return Prologue.FileNames[Index - 1];
+}
+
Optional<StringRef> DWARFDebugLine::LineTable::getSourceByIndex(uint64_t FileIndex,
FileLineInfoKind Kind) const {
if (Kind == FileLineInfoKind::None || !hasFileAtIndex(FileIndex))
return None;
- const FileNameEntry &Entry = Prologue.FileNames[FileIndex - 1];
+ const FileNameEntry &Entry = getFileNameEntry(FileIndex);
if (Optional<const char *> source = Entry.Source.getAsCString())
return StringRef(*source);
return None;
std::string &Result) const {
if (Kind == FileLineInfoKind::None || !hasFileAtIndex(FileIndex))
return false;
- const FileNameEntry &Entry = Prologue.FileNames[FileIndex - 1];
+ const FileNameEntry &Entry = getFileNameEntry(FileIndex);
StringRef FileName = Entry.Name.getAsCString().getValue();
if (Kind != FileLineInfoKind::AbsoluteFilePath ||
isPathAbsoluteOnWindowsOrPosix(FileName)) {
MCDwarfLineTable &Table = getContext().getMCDwarfLineTable(CUID);
unsigned NumFiles = Table.getMCDwarfFiles().size();
Expected<unsigned> FileNoOrErr =
- Table.tryGetFile(Directory, Filename, Checksum, Source, FileNo);
+ Table.tryGetFile(Directory, Filename, Checksum, Source,
+ getContext().getDwarfVersion(), FileNo);
if (!FileNoOrErr)
return FileNoOrErr.takeError();
FileNo = FileNoOrErr.get();
Optional<StringRef> Source,
unsigned CUID) {
MCDwarfLineTable &Table = MCDwarfLineTablesCUMap[CUID];
- return Table.tryGetFile(Directory, FileName, Checksum, Source, FileNumber);
+ return Table.tryGetFile(Directory, FileName, Checksum, Source, DwarfVersion,
+ FileNumber);
}
/// isValidDwarfFileNumber - takes a dwarf file number and returns true if it
bool MCContext::isValidDwarfFileNumber(unsigned FileNumber, unsigned CUID) {
const MCDwarfLineTable &LineTable = getMCDwarfLineTable(CUID);
if (FileNumber == 0)
- return getDwarfVersion() >= 5 && LineTable.hasRootFile();
+ return getDwarfVersion() >= 5;
if (FileNumber >= LineTable.getMCDwarfFiles().size())
return false;
void MCDwarfDwoLineTable::Emit(MCStreamer &MCOS, MCDwarfLineTableParams Params,
MCSection *Section) const {
- if (Header.MCDwarfFiles.empty())
+ if (!HasSplitLineTable)
return;
Optional<MCDwarfLineStr> NoLineStr(None);
MCOS.SwitchSection(Section);
StringRef &FileName,
Optional<MD5::MD5Result> Checksum,
Optional<StringRef> Source,
+ uint16_t DwarfVersion,
unsigned FileNumber) {
- return Header.tryGetFile(Directory, FileName, Checksum, Source, FileNumber);
+ return Header.tryGetFile(Directory, FileName, Checksum, Source, DwarfVersion,
+ FileNumber);
+}
+
+bool isRootFile(const MCDwarfFile &RootFile, StringRef &Directory,
+ StringRef &FileName, Optional<MD5::MD5Result> Checksum) {
+ if (RootFile.Name.empty() || RootFile.Name != FileName.data())
+ return false;
+ return RootFile.Checksum == Checksum;
}
Expected<unsigned>
StringRef &FileName,
Optional<MD5::MD5Result> Checksum,
Optional<StringRef> Source,
+ uint16_t DwarfVersion,
unsigned FileNumber) {
if (Directory == CompilationDir)
Directory = "";
trackMD5Usage(Checksum.hasValue());
HasSource = (Source != None);
}
+ if (isRootFile(RootFile, Directory, FileName, Checksum) && DwarfVersion >= 5)
+ return 0;
if (FileNumber == 0) {
// File numbers start with 1 and/or after any file numbers
// allocated by inline-assembler .file directives.
// RUN: llvm-dwarfdump -v %t | FileCheck -check-prefix DWARF -check-prefix DWARF45 %s
// RUN: llvm-dwarfdump --debug-line %t | FileCheck -check-prefix DWARF-DL -check-prefix DWARF-DL-5 -DDWVER=5 -DDWFILE=0 %s
// RUN: llvm-objdump -r %t | FileCheck -check-prefix RELOC -check-prefix RELOC5 %s
-// RUN: llvm-mc < %s -triple=armv7-linux-gnueabi -filetype=obj -o %t -g -fdebug-compilation-dir=/tmp
+// RUN: llvm-mc < %s -triple=armv7-linux-gnueabi -filetype=obj -o %t -g -dwarf-version 4 -fdebug-compilation-dir=/tmp
// RUN: llvm-dwarfdump -v %t | FileCheck -check-prefix DWARF -check-prefix DWARF45 %s
-// RUN: llvm-dwarfdump --debug-line %t | FileCheck -check-prefix DWARF-DL -DDWVER=4 -DDWFILE=1 %s
+// RUN: llvm-dwarfdump --debug-line %t | FileCheck -check-prefix DWARF-DL -check-prefix DWARF-DL-4 -DDWVER=4 -DDWFILE=1 %s
// RUN: llvm-objdump -r %t | FileCheck -check-prefix RELOC -check-prefix RELOC4 %s
// RUN: llvm-mc < %s -triple=armv7-linux-gnueabi -filetype=obj -o %t -g -dwarf-version 3 -fdebug-compilation-dir=/tmp
// RUN: llvm-dwarfdump -v %t | FileCheck -check-prefix DWARF -check-prefix DWARF3 %s
// DWARF-DL-5: include_directories[ 0] = "/tmp"
// DWARF-DL: file_names[ [[DWFILE]]]:
// DWARF-DL: name: "{{(<stdin>|-)}}"
-// DWARF-DL: 0x0000000000000000 17 0 1 0 0 is_stmt
-// DWARF-DL-NEXT: 0x0000000000000004 17 0 1 0 0 is_stmt end_sequence
-// DWARF-DL-NEXT: 0x0000000000000000 21 0 1 0 0 is_stmt
-// DWARF-DL-NEXT: 0x0000000000000004 21 0 1 0 0 is_stmt end_sequence
+// DWARF-DL-5: 0x0000000000000000 17 0 0 0 0 is_stmt
+// DWARF-DL-5-NEXT: 0x0000000000000004 17 0 0 0 0 is_stmt end_sequence
+// DWARF-DL-5-NEXT: 0x0000000000000000 21 0 0 0 0 is_stmt
+// DWARF-DL-5-NEXT: 0x0000000000000004 21 0 0 0 0 is_stmt end_sequence
+// DWARF-DL-4: 0x0000000000000000 17 0 1 0 0 is_stmt
+// DWARF-DL-4-NEXT: 0x0000000000000004 17 0 1 0 0 is_stmt end_sequence
+// DWARF-DL-4-NEXT: 0x0000000000000000 21 0 1 0 0 is_stmt
+// DWARF-DL-4-NEXT: 0x0000000000000004 21 0 1 0 0 is_stmt end_sequence
// DWARF: .debug_ranges contents:
; RUN: %llc_dwarf -filetype=asm -dwarf-version=5 %s -o - | FileCheck %s -check-prefix=ASM
; RUN: %llc_dwarf -filetype=obj -dwarf-version=5 %s -o - | llvm-dwarfdump -debug-line - | FileCheck %s -check-prefix=OBJ
; ASM: .file 0 "{{.+}}" md5
-; ASM: .file 1 "{{.+}}" md5
-; ASM: .file 2 "t1.cpp"
+; ASM: .file 1 "t1.cpp"
; ASM-NOT: md5
; OBJ: file_names[ 0]:
; OBJ-NOT: md5
# CHECK: file_names[ 1]:
# CHECK-NEXT: name: "header.h"
# CHECK-NEXT: dir_index: 1
-# CHECK: file_names[ 2]:
-# CHECK-NEXT: name: "root.cpp"
+# CHECK-4: file_names[ 2]:
+# CHECK-4-NEXT: name: "root.cpp"
# CHECK-4-NEXT: dir_index: 2
-# CHECK-5-NEXT: dir_index: 0
# ASM-NOT: .file
# ASM-5: .file 0 "/test" "root.cpp"
# ASM: .file 1 "/include" "header.h"
# ASM-4: .file 2 "/test" "root.cpp"
-# ASM-5: .file 2 "root.cpp"
# ASM-NOT: .file
# WARN: file 0 not supported prior to DWARF-5
_Z2f1v: # @_Z2f1v
.Lfunc_begin0:
.file 0 "/home/avl" "test.cpp" md5 0xefae234cc05b45384d782316d3a5d338
- .file 1 "test.cpp" md5 0xefae234cc05b45384d782316d3a5d338
- .loc 1 1 0 # test.cpp:1:0
+ .loc 0 1 0 # test.cpp:1:0
.cfi_startproc
# %bb.0: # %entry
pushq %rbp
movq %rsp, %rbp
.cfi_def_cfa_register %rbp
.Ltmp0:
- .loc 1 1 12 prologue_end # test.cpp:1:12
+ .loc 0 1 12 prologue_end # test.cpp:1:12
popq %rbp
.cfi_def_cfa %rsp, 8
retq
.type _Z2f2v,@function
_Z2f2v: # @_Z2f2v
.Lfunc_begin1:
- .loc 1 2 0 # test.cpp:2:0
+ .loc 0 2 0 # test.cpp:2:0
.cfi_startproc
# %bb.0: # %entry
pushq %rbp
movq %rsp, %rbp
.cfi_def_cfa_register %rbp
.Ltmp2:
- .loc 1 2 12 prologue_end # test.cpp:2:12
+ .loc 0 2 12 prologue_end # test.cpp:2:12
popq %rbp
.cfi_def_cfa %rsp, 8
retq