Commit d54883f0 authored by Paul Robinson's avatar Paul Robinson
Browse files

[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
parent 6405f2f9
Loading
Loading
Loading
Loading
+7 −2
Original line number Diff line number Diff line
@@ -537,8 +537,13 @@ namespace llvm {
      DwarfCompileUnitID = CUIndex;
    }

    void setMCLineTableCompilationDir(unsigned CUID, StringRef CompilationDir) {
      getMCDwarfLineTable(CUID).setCompilationDir(CompilationDir);
    /// Specifies the "root" file and directory of the compilation unit.
    /// These are "file 0" and "directory 0" in DWARF v5.
    void setMCLineTableRootFile(unsigned CUID, StringRef CompilationDir,
                                StringRef Filename, MD5::MD5Result *Checksum,
                                Optional<StringRef> Source) {
      getMCDwarfLineTable(CUID).setRootFile(CompilationDir, Filename, Checksum,
                                            Source);
    }

    /// Saves the information from the currently parsed dwarf .loc directive
+23 −6
Original line number Diff line number Diff line
@@ -214,6 +214,7 @@ struct MCDwarfLineTableHeader {
  SmallVector<MCDwarfFile, 3> MCDwarfFiles;
  StringMap<unsigned> SourceIdMap;
  StringRef CompilationDir;
  MCDwarfFile RootFile;
  bool HasMD5 = false;
  bool HasSource = false;

@@ -241,8 +242,17 @@ class MCDwarfDwoLineTable {
  MCDwarfLineTableHeader Header;

public:
  void setCompilationDir(StringRef CompilationDir) {
    Header.CompilationDir = CompilationDir;
  void maybeSetRootFile(StringRef Directory, StringRef FileName,
                        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.HasMD5 = (Checksum != nullptr);
    Header.HasSource = Source.hasValue();
  }

  unsigned getFile(StringRef Directory, StringRef FileName,
@@ -276,6 +286,17 @@ public:
                               FileNumber));
  }

  void setRootFile(StringRef Directory, StringRef FileName,
                   MD5::MD5Result *Checksum, Optional<StringRef> Source) {
    Header.CompilationDir = Directory;
    Header.RootFile.Name = FileName;
    Header.RootFile.DirIndex = 0;
    Header.RootFile.Checksum = Checksum;
    Header.RootFile.Source = Source;
    Header.HasMD5 = (Checksum != nullptr);
    Header.HasSource = Source.hasValue();
  }

  MCSymbol *getLabel() const {
    return Header.Label;
  }
@@ -284,10 +305,6 @@ public:
    Header.Label = Label;
  }

  void setCompilationDir(StringRef CompilationDir) {
    Header.CompilationDir = CompilationDir;
  }

  const SmallVectorImpl<std::string> &getMCDwarfDirs() const {
    return Header.MCDwarfDirs;
  }
+6 −0
Original line number Diff line number Diff line
@@ -774,6 +774,12 @@ public:
      MD5::MD5Result *Checksum = nullptr, Optional<StringRef> Source = None,
      unsigned CUID = 0);

  /// Specify the "root" file of the compilation, using the ".file 0" extension.
  virtual void emitDwarfFile0Directive(StringRef Directory, StringRef Filename,
                                       MD5::MD5Result *Checksum,
                                       Optional<StringRef> Source,
                                       unsigned CUID = 0);

  /// \brief This implements the DWARF2 '.loc fileno lineno ...' assembler
  /// directive.
  virtual void EmitDwarfLocDirective(unsigned FileNo, unsigned Line,
+7 −4
Original line number Diff line number Diff line
@@ -476,8 +476,9 @@ DwarfDebug::getOrCreateDwarfCompileUnit(const DICompileUnit *DIUnit) {
  // explicitly describe the directory of all files, never relying on the
  // compilation directory.
  if (!Asm->OutStreamer->hasRawTextSupport() || SingleCU)
    Asm->OutStreamer->getContext().setMCLineTableCompilationDir(
        NewCU.getUniqueID(), CompilationDir);
    Asm->OutStreamer->emitDwarfFile0Directive(
        CompilationDir, FN, NewCU.getMD5AsBytes(DIUnit->getFile()),
        DIUnit->getSource(), NewCU.getUniqueID());

  StringRef Producer = DIUnit->getProducer();
  StringRef Flags = DIUnit->getFlags();
@@ -2110,8 +2111,10 @@ void DwarfDebug::emitDebugStrDWO() {
MCDwarfDwoLineTable *DwarfDebug::getDwoLineTable(const DwarfCompileUnit &CU) {
  if (!useSplitDwarf())
    return nullptr;
  if (SingleCU)
    SplitTypeUnitFileTable.setCompilationDir(CU.getCUNode()->getDirectory());
  const DICompileUnit *DIUnit = CU.getCUNode();
  SplitTypeUnitFileTable.maybeSetRootFile(
      DIUnit->getDirectory(), DIUnit->getFilename(),
      CU.getMD5AsBytes(DIUnit->getFile()), DIUnit->getSource());
  return &SplitTypeUnitFileTable;
}

+1 −1
Original line number Diff line number Diff line
@@ -284,7 +284,7 @@ void DwarfUnit::addSectionOffset(DIE &Die, dwarf::Attribute Attribute,
    addUInt(Die, Attribute, dwarf::DW_FORM_data4, Integer);
}

MD5::MD5Result *DwarfUnit::getMD5AsBytes(const DIFile *File) {
MD5::MD5Result *DwarfUnit::getMD5AsBytes(const DIFile *File) const {
  assert(File);
  Optional<DIFile::ChecksumInfo<StringRef>> Checksum = File->getChecksum();
  if (!Checksum || Checksum->Kind != DIFile::CSK_MD5)
Loading