diff options
author | Paul Robinson <paul.robinson@sony.com> | 2018-03-06 01:59:56 +0000 |
---|---|---|
committer | Paul Robinson <paul.robinson@sony.com> | 2018-03-06 01:59:56 +0000 |
commit | d5069ba3da031774ad6b751f0f72c65e7dda9b04 (patch) | |
tree | efa6dae9e93355da9e17edf2ba279c6ae71bdbf9 /llvm/lib/MC/MCAsmStreamer.cpp | |
parent | b8b9af2ad46ff1ed901956c155c48c15cb585fa9 (diff) | |
download | llvm-d5069ba3da031774ad6b751f0f72c65e7dda9b04.zip llvm-d5069ba3da031774ad6b751f0f72c65e7dda9b04.tar.gz llvm-d5069ba3da031774ad6b751f0f72c65e7dda9b04.tar.bz2 |
[DWARFv5] Emit file 0 to the line table.
DWARF v5 specifies that the root file (also given in the DW_AT_name
attribute of the compilation unit DIE) should be emitted explicitly to
the line table's list of files. This makes the line table more
independent of the .debug_info section.
Differential Revision: https://reviews.llvm.org/D44054
llvm-svn: 326758
Diffstat (limited to 'llvm/lib/MC/MCAsmStreamer.cpp')
-rw-r--r-- | llvm/lib/MC/MCAsmStreamer.cpp | 86 |
1 files changed, 58 insertions, 28 deletions
diff --git a/llvm/lib/MC/MCAsmStreamer.cpp b/llvm/lib/MC/MCAsmStreamer.cpp index f254cb5..0a006ec 100644 --- a/llvm/lib/MC/MCAsmStreamer.cpp +++ b/llvm/lib/MC/MCAsmStreamer.cpp @@ -218,6 +218,10 @@ public: MD5::MD5Result *Checksum = 0, Optional<StringRef> Source = None, unsigned CUID = 0) override; + void emitDwarfFile0Directive(StringRef Directory, StringRef Filename, + MD5::MD5Result *Checksum, + Optional<StringRef> Source, + unsigned CUID = 0) override; void EmitDwarfLocDirective(unsigned FileNo, unsigned Line, unsigned Column, unsigned Flags, unsigned Isa, unsigned Discriminator, @@ -1076,21 +1080,10 @@ void MCAsmStreamer::EmitFileDirective(StringRef Filename) { EmitEOL(); } -Expected<unsigned> MCAsmStreamer::tryEmitDwarfFileDirective( - unsigned FileNo, StringRef Directory, StringRef Filename, - MD5::MD5Result *Checksum, Optional<StringRef> Source, unsigned CUID) { - assert(CUID == 0); - - MCDwarfLineTable &Table = getContext().getMCDwarfLineTable(CUID); - unsigned NumFiles = Table.getMCDwarfFiles().size(); - Expected<unsigned> FileNoOrErr = - Table.tryGetFile(Directory, Filename, Checksum, Source, FileNo); - if (!FileNoOrErr) - return FileNoOrErr.takeError(); - FileNo = FileNoOrErr.get(); - if (NumFiles == Table.getMCDwarfFiles().size()) - return FileNo; - +void printDwarfFileDirective(unsigned FileNo, StringRef Directory, + StringRef Filename, MD5::MD5Result *Checksum, + Optional<StringRef> Source, bool UseDwarfDirectory, + raw_svector_ostream &OS) { SmallString<128> FullPathName; if (!UseDwarfDirectory && !Directory.empty()) { @@ -1104,31 +1097,68 @@ Expected<unsigned> MCAsmStreamer::tryEmitDwarfFileDirective( } } - SmallString<128> Str; - raw_svector_ostream OS1(Str); - OS1 << "\t.file\t" << FileNo << ' '; + OS << "\t.file\t" << FileNo << ' '; if (!Directory.empty()) { - PrintQuotedString(Directory, OS1); - OS1 << ' '; + PrintQuotedString(Directory, OS); + OS << ' '; } - PrintQuotedString(Filename, OS1); + PrintQuotedString(Filename, OS); if (Checksum) { - OS1 << " md5 "; - PrintQuotedString(Checksum->digest(), OS1); + OS << " md5 "; + PrintQuotedString(Checksum->digest(), OS); } if (Source) { - OS1 << " source "; - PrintQuotedString(*Source, OS1); + OS << " source "; + PrintQuotedString(*Source, OS); } - if (MCTargetStreamer *TS = getTargetStreamer()) { +} + +Expected<unsigned> MCAsmStreamer::tryEmitDwarfFileDirective( + unsigned FileNo, StringRef Directory, StringRef Filename, + MD5::MD5Result *Checksum, Optional<StringRef> Source, unsigned CUID) { + assert(CUID == 0 && "multiple CUs not supported by MCAsmStreamer"); + + MCDwarfLineTable &Table = getContext().getMCDwarfLineTable(CUID); + unsigned NumFiles = Table.getMCDwarfFiles().size(); + Expected<unsigned> FileNoOrErr = + Table.tryGetFile(Directory, Filename, Checksum, Source, FileNo); + if (!FileNoOrErr) + return FileNoOrErr.takeError(); + FileNo = FileNoOrErr.get(); + if (NumFiles == Table.getMCDwarfFiles().size()) + return FileNo; + + SmallString<128> Str; + raw_svector_ostream OS1(Str); + printDwarfFileDirective(FileNo, Directory, Filename, Checksum, Source, + UseDwarfDirectory, OS1); + + if (MCTargetStreamer *TS = getTargetStreamer()) TS->emitDwarfFileDirective(OS1.str()); - } else { + else EmitRawText(OS1.str()); - } return FileNo; } +void MCAsmStreamer::emitDwarfFile0Directive(StringRef Directory, + StringRef Filename, + MD5::MD5Result *Checksum, + Optional<StringRef> Source, + unsigned CUID) { + assert(CUID == 0); + + SmallString<128> Str; + raw_svector_ostream OS1(Str); + printDwarfFileDirective(0, Directory, Filename, Checksum, Source, + UseDwarfDirectory, OS1); + + if (MCTargetStreamer *TS = getTargetStreamer()) + TS->emitDwarfFileDirective(OS1.str()); + else + EmitRawText(OS1.str()); +} + void MCAsmStreamer::EmitDwarfLocDirective(unsigned FileNo, unsigned Line, unsigned Column, unsigned Flags, unsigned Isa, |