[DebugInfo][NFC] Remove unused variable/fix variable naming
authorJames Henderson <jh7370@my.bristol.ac.uk>
Fri, 3 Jan 2020 15:29:21 +0000 (15:29 +0000)
committerJames Henderson <jh7370@my.bristol.ac.uk>
Fri, 10 Jan 2020 15:00:56 +0000 (15:00 +0000)
Reviewed by: MaskRay

Differential Revision: https://reviews.llvm.org/D72159

llvm/lib/DebugInfo/DWARF/DWARFDebugLine.cpp

index 73480ce..8ba6b2e 100644 (file)
-//===- DWARFDebugLine.cpp -------------------------------------------------===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-
-#include "llvm/DebugInfo/DWARF/DWARFDebugLine.h"
-#include "llvm/ADT/Optional.h"
-#include "llvm/ADT/SmallString.h"
-#include "llvm/ADT/SmallVector.h"
-#include "llvm/ADT/StringRef.h"
-#include "llvm/BinaryFormat/Dwarf.h"
-#include "llvm/DebugInfo/DWARF/DWARFFormValue.h"
-#include "llvm/DebugInfo/DWARF/DWARFRelocMap.h"
-#include "llvm/Support/Errc.h"
-#include "llvm/Support/Format.h"
-#include "llvm/Support/WithColor.h"
-#include "llvm/Support/raw_ostream.h"
-#include <algorithm>
-#include <cassert>
-#include <cinttypes>
-#include <cstdint>
-#include <cstdio>
-#include <utility>
-
-using namespace llvm;
-using namespace dwarf;
-
-using FileLineInfoKind = DILineInfoSpecifier::FileLineInfoKind;
-
-namespace {
-
-struct ContentDescriptor {
-  dwarf::LineNumberEntryFormat Type;
-  dwarf::Form Form;
-};
-
-using ContentDescriptors = SmallVector<ContentDescriptor, 4>;
-
-} // end anonymous namespace
-
-void DWARFDebugLine::ContentTypeTracker::trackContentType(
-    dwarf::LineNumberEntryFormat ContentType) {
-  switch (ContentType) {
-  case dwarf::DW_LNCT_timestamp:
-    HasModTime = true;
-    break;
-  case dwarf::DW_LNCT_size:
-    HasLength = true;
-    break;
-  case dwarf::DW_LNCT_MD5:
-    HasMD5 = true;
-    break;
-  case dwarf::DW_LNCT_LLVM_source:
-    HasSource = true;
-    break;
-  default:
-    // We only care about values we consider optional, and new values may be
-    // added in the vendor extension range, so we do not match exhaustively.
-    break;
-  }
-}
-
-DWARFDebugLine::Prologue::Prologue() { clear(); }
-
-bool DWARFDebugLine::Prologue::hasFileAtIndex(uint64_t FileIndex) const {
-  uint16_t DwarfVersion = getVersion();
-  assert(DwarfVersion != 0 &&
-         "line table prologue has no dwarf version information");
-  if (DwarfVersion >= 5)
-    return FileIndex < FileNames.size();
-  return FileIndex != 0 && FileIndex <= FileNames.size();
-}
-
-const llvm::DWARFDebugLine::FileNameEntry &
-DWARFDebugLine::Prologue::getFileNameEntry(uint64_t Index) const {
-  uint16_t DwarfVersion = getVersion();
-  assert(DwarfVersion != 0 &&
-         "line table prologue has no dwarf version information");
-  // In DWARF v5 the file names are 0-indexed.
-  if (DwarfVersion >= 5)
-    return FileNames[Index];
-  return FileNames[Index - 1];
-}
-
-void DWARFDebugLine::Prologue::clear() {
-  TotalLength = PrologueLength = 0;
-  SegSelectorSize = 0;
-  MinInstLength = MaxOpsPerInst = DefaultIsStmt = LineBase = LineRange = 0;
-  OpcodeBase = 0;
-  FormParams = dwarf::FormParams({0, 0, DWARF32});
-  ContentTypes = ContentTypeTracker();
-  StandardOpcodeLengths.clear();
-  IncludeDirectories.clear();
-  FileNames.clear();
-}
-
-void DWARFDebugLine::Prologue::dump(raw_ostream &OS,
-                                    DIDumpOptions DumpOptions) const {
-  OS << "Line table prologue:\n"
-     << format("    total_length: 0x%8.8" PRIx64 "\n", TotalLength)
-     << format("         version: %u\n", getVersion());
-  if (getVersion() >= 5)
-    OS << format("    address_size: %u\n", getAddressSize())
-       << format(" seg_select_size: %u\n", SegSelectorSize);
-  OS << format(" prologue_length: 0x%8.8" PRIx64 "\n", PrologueLength)
-     << format(" min_inst_length: %u\n", MinInstLength)
-     << format(getVersion() >= 4 ? "max_ops_per_inst: %u\n" : "", MaxOpsPerInst)
-     << format(" default_is_stmt: %u\n", DefaultIsStmt)
-     << format("       line_base: %i\n", LineBase)
-     << format("      line_range: %u\n", LineRange)
-     << format("     opcode_base: %u\n", OpcodeBase);
-
-  for (uint32_t I = 0; I != StandardOpcodeLengths.size(); ++I)
-    OS << format("standard_opcode_lengths[%s] = %u\n",
-                 LNStandardString(I + 1).data(), StandardOpcodeLengths[I]);
-
-  if (!IncludeDirectories.empty()) {
-    // DWARF v5 starts directory indexes at 0.
-    uint32_t DirBase = getVersion() >= 5 ? 0 : 1;
-    for (uint32_t I = 0; I != IncludeDirectories.size(); ++I) {
-      OS << format("include_directories[%3u] = ", I + DirBase);
-      IncludeDirectories[I].dump(OS, DumpOptions);
-      OS << '\n';
-    }
-  }
-
-  if (!FileNames.empty()) {
-    // DWARF v5 starts file indexes at 0.
-    uint32_t FileBase = getVersion() >= 5 ? 0 : 1;
-    for (uint32_t I = 0; I != FileNames.size(); ++I) {
-      const FileNameEntry &FileEntry = FileNames[I];
-      OS <<   format("file_names[%3u]:\n", I + FileBase);
-      OS <<          "           name: ";
-      FileEntry.Name.dump(OS, DumpOptions);
-      OS << '\n'
-         <<   format("      dir_index: %" PRIu64 "\n", FileEntry.DirIdx);
-      if (ContentTypes.HasMD5)
-        OS <<        "   md5_checksum: " << FileEntry.Checksum.digest() << '\n';
-      if (ContentTypes.HasModTime)
-        OS << format("       mod_time: 0x%8.8" PRIx64 "\n", FileEntry.ModTime);
-      if (ContentTypes.HasLength)
-        OS << format("         length: 0x%8.8" PRIx64 "\n", FileEntry.Length);
-      if (ContentTypes.HasSource) {
-        OS <<        "         source: ";
-        FileEntry.Source.dump(OS, DumpOptions);
-        OS << '\n';
-      }
-    }
-  }
-}
-
-// Parse v2-v4 directory and file tables.
-static void
-parseV2DirFileTables(const DWARFDataExtractor &DebugLineData,
-                     uint64_t *OffsetPtr, uint64_t EndPrologueOffset,
-                     DWARFDebugLine::ContentTypeTracker &ContentTypes,
-                     std::vector<DWARFFormValue> &IncludeDirectories,
-                     std::vector<DWARFDebugLine::FileNameEntry> &FileNames) {
-  while (*OffsetPtr < EndPrologueOffset) {
-    StringRef S = DebugLineData.getCStrRef(OffsetPtr);
-    if (S.empty())
-      break;
-    DWARFFormValue Dir =
-        DWARFFormValue::createFromPValue(dwarf::DW_FORM_string, S.data());
-    IncludeDirectories.push_back(Dir);
-  }
-
-  while (*OffsetPtr < EndPrologueOffset) {
-    StringRef Name = DebugLineData.getCStrRef(OffsetPtr);
-    if (Name.empty())
-      break;
-    DWARFDebugLine::FileNameEntry FileEntry;
-    FileEntry.Name =
-        DWARFFormValue::createFromPValue(dwarf::DW_FORM_string, Name.data());
-    FileEntry.DirIdx = DebugLineData.getULEB128(OffsetPtr);
-    FileEntry.ModTime = DebugLineData.getULEB128(OffsetPtr);
-    FileEntry.Length = DebugLineData.getULEB128(OffsetPtr);
-    FileNames.push_back(FileEntry);
-  }
-
-  ContentTypes.HasModTime = true;
-  ContentTypes.HasLength = true;
-}
-
-// Parse v5 directory/file entry content descriptions.
-// Returns the descriptors, or an error if we did not find a path or ran off
-// the end of the prologue.
-static llvm::Expected<ContentDescriptors>
-parseV5EntryFormat(const DWARFDataExtractor &DebugLineData, uint64_t *OffsetPtr,
-                   uint64_t EndPrologueOffset,
-                   DWARFDebugLine::ContentTypeTracker *ContentTypes) {
-  ContentDescriptors Descriptors;
-  int FormatCount = DebugLineData.getU8(OffsetPtr);
-  bool HasPath = false;
-  for (int I = 0; I != FormatCount; ++I) {
-    ContentDescriptor Descriptor;
-    Descriptor.Type =
-      dwarf::LineNumberEntryFormat(DebugLineData.getULEB128(OffsetPtr));
-    Descriptor.Form = dwarf::Form(DebugLineData.getULEB128(OffsetPtr));
-    if (Descriptor.Type == dwarf::DW_LNCT_path)
-      HasPath = true;
-    if (ContentTypes)
-      ContentTypes->trackContentType(Descriptor.Type);
-    Descriptors.push_back(Descriptor);
-  }
-
-  if (!HasPath)
-    return createStringError(errc::invalid_argument,
-                             "failed to parse entry content descriptions"
-                             " because no path was found");
-  return Descriptors;
-}
-
-static Error
-parseV5DirFileTables(const DWARFDataExtractor &DebugLineData,
-                     uint64_t *OffsetPtr, uint64_t EndPrologueOffset,
-                     const dwarf::FormParams &FormParams,
-                     const DWARFContext &Ctx, const DWARFUnit *U,
-                     DWARFDebugLine::ContentTypeTracker &ContentTypes,
-                     std::vector<DWARFFormValue> &IncludeDirectories,
-                     std::vector<DWARFDebugLine::FileNameEntry> &FileNames) {
-  // Get the directory entry description.
-  llvm::Expected<ContentDescriptors> DirDescriptors =
-      parseV5EntryFormat(DebugLineData, OffsetPtr, EndPrologueOffset, nullptr);
-  if (!DirDescriptors)
-    return DirDescriptors.takeError();
-
-  // Get the directory entries, according to the format described above.
-  int DirEntryCount = DebugLineData.getU8(OffsetPtr);
-  for (int I = 0; I != DirEntryCount; ++I) {
-    for (auto Descriptor : *DirDescriptors) {
-      DWARFFormValue Value(Descriptor.Form);
-      switch (Descriptor.Type) {
-      case DW_LNCT_path:
-        if (!Value.extractValue(DebugLineData, OffsetPtr, FormParams, &Ctx, U))
-          return createStringError(errc::invalid_argument,
-                                   "failed to parse directory entry because "
-                                   "extracting the form value failed.");
-        IncludeDirectories.push_back(Value);
-        break;
-      default:
-        if (!Value.skipValue(DebugLineData, OffsetPtr, FormParams))
-          return createStringError(errc::invalid_argument,
-                                   "failed to parse directory entry because "
-                                   "skipping the form value failed.");
-      }
-    }
-  }
-
-  // Get the file entry description.
-  llvm::Expected<ContentDescriptors> FileDescriptors = parseV5EntryFormat(
-      DebugLineData, OffsetPtr, EndPrologueOffset, &ContentTypes);
-  if (!FileDescriptors)
-    return FileDescriptors.takeError();
-
-  // Get the file entries, according to the format described above.
-  int FileEntryCount = DebugLineData.getU8(OffsetPtr);
-  for (int I = 0; I != FileEntryCount; ++I) {
-    DWARFDebugLine::FileNameEntry FileEntry;
-    for (auto Descriptor : *FileDescriptors) {
-      DWARFFormValue Value(Descriptor.Form);
-      if (!Value.extractValue(DebugLineData, OffsetPtr, FormParams, &Ctx, U))
-        return createStringError(errc::invalid_argument,
-                                 "failed to parse file entry because "
-                                 "extracting the form value failed.");
-      switch (Descriptor.Type) {
-      case DW_LNCT_path:
-        FileEntry.Name = Value;
-        break;
-      case DW_LNCT_LLVM_source:
-        FileEntry.Source = Value;
-        break;
-      case DW_LNCT_directory_index:
-        FileEntry.DirIdx = Value.getAsUnsignedConstant().getValue();
-        break;
-      case DW_LNCT_timestamp:
-        FileEntry.ModTime = Value.getAsUnsignedConstant().getValue();
-        break;
-      case DW_LNCT_size:
-        FileEntry.Length = Value.getAsUnsignedConstant().getValue();
-        break;
-      case DW_LNCT_MD5:
-        if (!Value.getAsBlock() || Value.getAsBlock().getValue().size() != 16)
-          return createStringError(
-              errc::invalid_argument,
-              "failed to parse file entry because the MD5 hash is invalid");
-        std::uninitialized_copy_n(Value.getAsBlock().getValue().begin(), 16,
-                                  FileEntry.Checksum.Bytes.begin());
-        break;
-      default:
-        break;
-      }
-    }
-    FileNames.push_back(FileEntry);
-  }
-  return Error::success();
-}
-
-Error DWARFDebugLine::Prologue::parse(const DWARFDataExtractor &DebugLineData,
-                                      uint64_t *OffsetPtr,
-                                      const DWARFContext &Ctx,
-                                      const DWARFUnit *U) {
-  const uint64_t PrologueOffset = *OffsetPtr;
-
-  clear();
-  TotalLength = DebugLineData.getRelocatedValue(4, OffsetPtr);
-  if (TotalLength == dwarf::DW_LENGTH_DWARF64) {
-    FormParams.Format = dwarf::DWARF64;
-    TotalLength = DebugLineData.getU64(OffsetPtr);
-  } else if (TotalLength >= dwarf::DW_LENGTH_lo_reserved) {
-    return createStringError(errc::invalid_argument,
-        "parsing line table prologue at offset 0x%8.8" PRIx64
-        " unsupported reserved unit length found of value 0x%8.8" PRIx64,
-        PrologueOffset, TotalLength);
-  }
-  FormParams.Version = DebugLineData.getU16(OffsetPtr);
-  if (getVersion() < 2)
-    return createStringError(errc::not_supported,
-                       "parsing line table prologue at offset 0x%8.8" PRIx64
-                       " found unsupported version 0x%2.2" PRIx16,
-                       PrologueOffset, getVersion());
-
-  if (getVersion() >= 5) {
-    FormParams.AddrSize = DebugLineData.getU8(OffsetPtr);
-    assert((DebugLineData.getAddressSize() == 0 ||
-            DebugLineData.getAddressSize() == getAddressSize()) &&
-           "Line table header and data extractor disagree");
-    SegSelectorSize = DebugLineData.getU8(OffsetPtr);
-  }
-
-  PrologueLength =
-      DebugLineData.getRelocatedValue(sizeofPrologueLength(), OffsetPtr);
-  const uint64_t EndPrologueOffset = PrologueLength + *OffsetPtr;
-  MinInstLength = DebugLineData.getU8(OffsetPtr);
-  if (getVersion() >= 4)
-    MaxOpsPerInst = DebugLineData.getU8(OffsetPtr);
-  DefaultIsStmt = DebugLineData.getU8(OffsetPtr);
-  LineBase = DebugLineData.getU8(OffsetPtr);
-  LineRange = DebugLineData.getU8(OffsetPtr);
-  OpcodeBase = DebugLineData.getU8(OffsetPtr);
-
-  StandardOpcodeLengths.reserve(OpcodeBase - 1);
-  for (uint32_t I = 1; I < OpcodeBase; ++I) {
-    uint8_t OpLen = DebugLineData.getU8(OffsetPtr);
-    StandardOpcodeLengths.push_back(OpLen);
-  }
-
-  if (getVersion() >= 5) {
-    if (Error e = parseV5DirFileTables(
-            DebugLineData, OffsetPtr, EndPrologueOffset, FormParams, Ctx, U,
-            ContentTypes, IncludeDirectories, FileNames)) {
-      return joinErrors(
-          createStringError(
-              errc::invalid_argument,
-              "parsing line table prologue at 0x%8.8" PRIx64
-              " found an invalid directory or file table description at"
-              " 0x%8.8" PRIx64,
-              PrologueOffset, *OffsetPtr),
-          std::move(e));
-    }
-  } else
-    parseV2DirFileTables(DebugLineData, OffsetPtr, EndPrologueOffset,
-                         ContentTypes, IncludeDirectories, FileNames);
-
-  if (*OffsetPtr != EndPrologueOffset)
-    return createStringError(errc::invalid_argument,
-                       "parsing line table prologue at 0x%8.8" PRIx64
-                       " should have ended at 0x%8.8" PRIx64
-                       " but it ended at 0x%8.8" PRIx64,
-                       PrologueOffset, EndPrologueOffset, *OffsetPtr);
-  return Error::success();
-}
-
-DWARFDebugLine::Row::Row(bool DefaultIsStmt) { reset(DefaultIsStmt); }
-
-void DWARFDebugLine::Row::postAppend() {
-  Discriminator = 0;
-  BasicBlock = false;
-  PrologueEnd = false;
-  EpilogueBegin = false;
-}
-
-void DWARFDebugLine::Row::reset(bool DefaultIsStmt) {
-  Address.Address = 0;
-  Address.SectionIndex = object::SectionedAddress::UndefSection;
-  Line = 1;
-  Column = 0;
-  File = 1;
-  Isa = 0;
-  Discriminator = 0;
-  IsStmt = DefaultIsStmt;
-  BasicBlock = false;
-  EndSequence = false;
-  PrologueEnd = false;
-  EpilogueBegin = false;
-}
-
-void DWARFDebugLine::Row::dumpTableHeader(raw_ostream &OS) {
-  OS << "Address            Line   Column File   ISA Discriminator Flags\n"
-     << "------------------ ------ ------ ------ --- ------------- "
-        "-------------\n";
-}
-
-void DWARFDebugLine::Row::dump(raw_ostream &OS) const {
-  OS << format("0x%16.16" PRIx64 " %6u %6u", Address.Address, Line, Column)
-     << format(" %6u %3u %13u ", File, Isa, Discriminator)
-     << (IsStmt ? " is_stmt" : "") << (BasicBlock ? " basic_block" : "")
-     << (PrologueEnd ? " prologue_end" : "")
-     << (EpilogueBegin ? " epilogue_begin" : "")
-     << (EndSequence ? " end_sequence" : "") << '\n';
-}
-
-DWARFDebugLine::Sequence::Sequence() { reset(); }
-
-void DWARFDebugLine::Sequence::reset() {
-  LowPC = 0;
-  HighPC = 0;
-  SectionIndex = object::SectionedAddress::UndefSection;
-  FirstRowIndex = 0;
-  LastRowIndex = 0;
-  Empty = true;
-}
-
-DWARFDebugLine::LineTable::LineTable() { clear(); }
-
-void DWARFDebugLine::LineTable::dump(raw_ostream &OS,
-                                     DIDumpOptions DumpOptions) const {
-  Prologue.dump(OS, DumpOptions);
-
-  if (!Rows.empty()) {
-    OS << '\n';
-    Row::dumpTableHeader(OS);
-    for (const Row &R : Rows) {
-      R.dump(OS);
-    }
-  }
-
-  // Terminate the table with a final blank line to clearly delineate it from
-  // later dumps.
-  OS << '\n';
-}
-
-void DWARFDebugLine::LineTable::clear() {
-  Prologue.clear();
-  Rows.clear();
-  Sequences.clear();
-}
-
-DWARFDebugLine::ParsingState::ParsingState(struct LineTable *LT)
-    : LineTable(LT) {
-  resetRowAndSequence();
-}
-
-void DWARFDebugLine::ParsingState::resetRowAndSequence() {
-  Row.reset(LineTable->Prologue.DefaultIsStmt);
-  Sequence.reset();
-}
-
-void DWARFDebugLine::ParsingState::appendRowToMatrix() {
-  unsigned RowNumber = LineTable->Rows.size();
-  if (Sequence.Empty) {
-    // Record the beginning of instruction sequence.
-    Sequence.Empty = false;
-    Sequence.LowPC = Row.Address.Address;
-    Sequence.FirstRowIndex = RowNumber;
-  }
-  LineTable->appendRow(Row);
-  if (Row.EndSequence) {
-    // Record the end of instruction sequence.
-    Sequence.HighPC = Row.Address.Address;
-    Sequence.LastRowIndex = RowNumber + 1;
-    Sequence.SectionIndex = Row.Address.SectionIndex;
-    if (Sequence.isValid())
-      LineTable->appendSequence(Sequence);
-    Sequence.reset();
-  }
-  Row.postAppend();
-}
-
-const DWARFDebugLine::LineTable *
-DWARFDebugLine::getLineTable(uint64_t Offset) const {
-  LineTableConstIter Pos = LineTableMap.find(Offset);
-  if (Pos != LineTableMap.end())
-    return &Pos->second;
-  return nullptr;
-}
-
-Expected<const DWARFDebugLine::LineTable *> DWARFDebugLine::getOrParseLineTable(
-    DWARFDataExtractor &DebugLineData, uint64_t Offset, const DWARFContext &Ctx,
-    const DWARFUnit *U, function_ref<void(Error)> RecoverableErrorCallback) {
-  if (!DebugLineData.isValidOffset(Offset))
-    return createStringError(errc::invalid_argument, "offset 0x%8.8" PRIx64
-                       " is not a valid debug line section offset",
-                       Offset);
-
-  std::pair<LineTableIter, bool> Pos =
-      LineTableMap.insert(LineTableMapTy::value_type(Offset, LineTable()));
-  LineTable *LT = &Pos.first->second;
-  if (Pos.second) {
-    if (Error Err =
-            LT->parse(DebugLineData, &Offset, Ctx, U, RecoverableErrorCallback))
-      return std::move(Err);
-    return LT;
-  }
-  return LT;
-}
-
-Error DWARFDebugLine::LineTable::parse(
-    DWARFDataExtractor &DebugLineData, uint64_t *OffsetPtr,
-    const DWARFContext &Ctx, const DWARFUnit *U,
-    function_ref<void(Error)> RecoverableErrorCallback, raw_ostream *OS) {
-  const uint64_t DebugLineOffset = *OffsetPtr;
-
-  clear();
-
-  Error PrologueErr = Prologue.parse(DebugLineData, OffsetPtr, Ctx, U);
-
-  if (OS) {
-    // The presence of OS signals verbose dumping.
-    DIDumpOptions DumpOptions;
-    DumpOptions.Verbose = true;
-    Prologue.dump(*OS, DumpOptions);
-  }
-
-  if (PrologueErr)
-    return PrologueErr;
-
-  uint64_t ProgramLength = Prologue.TotalLength + Prologue.sizeofTotalLength();
-  if (!DebugLineData.isValidOffsetForDataOfSize(DebugLineOffset,
-                                                ProgramLength)) {
-    assert(DebugLineData.size() > DebugLineOffset &&
-           "prologue parsing should handle invalid offset");
-    uint64_t BytesRemaining = DebugLineData.size() - DebugLineOffset;
-    RecoverableErrorCallback(
-        createStringError(errc::invalid_argument,
-                          "line table program with offset 0x%8.8" PRIx64
-                          " has length 0x%8.8" PRIx64 " but only 0x%8.8" PRIx64
-                          " bytes are available",
-                          DebugLineOffset, ProgramLength, BytesRemaining));
-    // Continue by capping the length at the number of remaining bytes.
-    ProgramLength = BytesRemaining;
-  }
-
-  const uint64_t EndOffset = DebugLineOffset + ProgramLength;
-
-  // See if we should tell the data extractor the address size.
-  if (DebugLineData.getAddressSize() == 0)
-    DebugLineData.setAddressSize(Prologue.getAddressSize());
-  else
-    assert(Prologue.getAddressSize() == 0 ||
-           Prologue.getAddressSize() == DebugLineData.getAddressSize());
-
-  ParsingState State(this);
-
-  while (*OffsetPtr < EndOffset) {
-    if (OS)
-      *OS << format("0x%08.08" PRIx64 ": ", *OffsetPtr);
-
-    uint8_t Opcode = DebugLineData.getU8(OffsetPtr);
-
-    if (OS)
-      *OS << format("%02.02" PRIx8 " ", Opcode);
-
-    if (Opcode == 0) {
-      // Extended Opcodes always start with a zero opcode followed by
-      // a uleb128 length so you can skip ones you don't know about
-      uint64_t Len = DebugLineData.getULEB128(OffsetPtr);
-      uint64_t ExtOffset = *OffsetPtr;
-
-      // Tolerate zero-length; assume length is correct and soldier on.
-      if (Len == 0) {
-        if (OS)
-          *OS << "Badly formed extended line op (length 0)\n";
-        continue;
-      }
-
-      uint8_t SubOpcode = DebugLineData.getU8(OffsetPtr);
-      if (OS)
-        *OS << LNExtendedString(SubOpcode);
-      switch (SubOpcode) {
-      case DW_LNE_end_sequence:
-        // Set the end_sequence register of the state machine to true and
-        // append a row to the matrix using the current values of the
-        // state-machine registers. Then reset the registers to the initial
-        // values specified above. Every statement program sequence must end
-        // with a DW_LNE_end_sequence instruction which creates a row whose
-        // address is that of the byte after the last target machine instruction
-        // of the sequence.
-        State.Row.EndSequence = true;
-        if (OS) {
-          *OS << "\n";
-          OS->indent(12);
-          State.Row.dump(*OS);
-        }
-        State.appendRowToMatrix();
-        State.resetRowAndSequence();
-        break;
-
-      case DW_LNE_set_address:
-        // Takes a single relocatable address as an operand. The size of the
-        // operand is the size appropriate to hold an address on the target
-        // machine. Set the address register to the value given by the
-        // relocatable address. All of the other statement program opcodes
-        // that affect the address register add a delta to it. This instruction
-        // stores a relocatable value into it instead.
-        //
-        // Make sure the extractor knows the address size.  If not, infer it
-        // from the size of the operand.
-        if (DebugLineData.getAddressSize() == 0)
-          DebugLineData.setAddressSize(Len - 1);
-        else if (DebugLineData.getAddressSize() != Len - 1) {
-          return createStringError(errc::invalid_argument,
-                             "mismatching address size at offset 0x%8.8" PRIx64
-                             " expected 0x%2.2" PRIx8 " found 0x%2.2" PRIx64,
-                             ExtOffset, DebugLineData.getAddressSize(),
-                             Len - 1);
-        }
-        State.Row.Address.Address = DebugLineData.getRelocatedAddress(
-            OffsetPtr, &State.Row.Address.SectionIndex);
-        if (OS)
-          *OS << format(" (0x%16.16" PRIx64 ")", State.Row.Address.Address);
-        break;
-
-      case DW_LNE_define_file:
-        // Takes 4 arguments. The first is a null terminated string containing
-        // a source file name. The second is an unsigned LEB128 number
-        // representing the directory index of the directory in which the file
-        // was found. The third is an unsigned LEB128 number representing the
-        // time of last modification of the file. The fourth is an unsigned
-        // LEB128 number representing the length in bytes of the file. The time
-        // and length fields may contain LEB128(0) if the information is not
-        // available.
-        //
-        // The directory index represents an entry in the include_directories
-        // section of the statement program prologue. The index is LEB128(0)
-        // if the file was found in the current directory of the compilation,
-        // LEB128(1) if it was found in the first directory in the
-        // include_directories section, and so on. The directory index is
-        // ignored for file names that represent full path names.
-        //
-        // The files are numbered, starting at 1, in the order in which they
-        // appear; the names in the prologue come before names defined by
-        // the DW_LNE_define_file instruction. These numbers are used in the
-        // the file register of the state machine.
-        {
-          FileNameEntry FileEntry;
-          const char *Name = DebugLineData.getCStr(OffsetPtr);
-          FileEntry.Name =
-              DWARFFormValue::createFromPValue(dwarf::DW_FORM_string, Name);
-          FileEntry.DirIdx = DebugLineData.getULEB128(OffsetPtr);
-          FileEntry.ModTime = DebugLineData.getULEB128(OffsetPtr);
-          FileEntry.Length = DebugLineData.getULEB128(OffsetPtr);
-          Prologue.FileNames.push_back(FileEntry);
-          if (OS)
-            *OS << " (" << Name << ", dir=" << FileEntry.DirIdx << ", mod_time="
-                << format("(0x%16.16" PRIx64 ")", FileEntry.ModTime)
-                << ", length=" << FileEntry.Length << ")";
-        }
-        break;
-
-      case DW_LNE_set_discriminator:
-        State.Row.Discriminator = DebugLineData.getULEB128(OffsetPtr);
-        if (OS)
-          *OS << " (" << State.Row.Discriminator << ")";
-        break;
-
-      default:
-        if (OS)
-          *OS << format("Unrecognized extended op 0x%02.02" PRIx8, SubOpcode)
-              << format(" length %" PRIx64, Len);
-        // Len doesn't include the zero opcode byte or the length itself, but
-        // it does include the sub_opcode, so we have to adjust for that.
-        (*OffsetPtr) += Len - 1;
-        break;
-      }
-      // Make sure the stated and parsed lengths are the same.
-      // Otherwise we have an unparseable line-number program.
-      if (*OffsetPtr - ExtOffset != Len)
-        return createStringError(errc::illegal_byte_sequence,
-                           "unexpected line op length at offset 0x%8.8" PRIx64
-                           " expected 0x%2.2" PRIx64 " found 0x%2.2" PRIx64,
-                           ExtOffset, Len, *OffsetPtr - ExtOffset);
-    } else if (Opcode < Prologue.OpcodeBase) {
-      if (OS)
-        *OS << LNStandardString(Opcode);
-      switch (Opcode) {
-      // Standard Opcodes
-      case DW_LNS_copy:
-        // Takes no arguments. Append a row to the matrix using the
-        // current values of the state-machine registers.
-        if (OS) {
-          *OS << "\n";
-          OS->indent(12);
-          State.Row.dump(*OS);
-          *OS << "\n";
-        }
-        State.appendRowToMatrix();
-        break;
-
-      case DW_LNS_advance_pc:
-        // Takes a single unsigned LEB128 operand, multiplies it by the
-        // min_inst_length field of the prologue, and adds the
-        // result to the address register of the state machine.
-        {
-          uint64_t AddrOffset =
-              DebugLineData.getULEB128(OffsetPtr) * Prologue.MinInstLength;
-          State.Row.Address.Address += AddrOffset;
-          if (OS)
-            *OS << " (" << AddrOffset << ")";
-        }
-        break;
-
-      case DW_LNS_advance_line:
-        // Takes a single signed LEB128 operand and adds that value to
-        // the line register of the state machine.
-        State.Row.Line += DebugLineData.getSLEB128(OffsetPtr);
-        if (OS)
-          *OS << " (" << State.Row.Line << ")";
-        break;
-
-      case DW_LNS_set_file:
-        // Takes a single unsigned LEB128 operand and stores it in the file
-        // register of the state machine.
-        State.Row.File = DebugLineData.getULEB128(OffsetPtr);
-        if (OS)
-          *OS << " (" << State.Row.File << ")";
-        break;
-
-      case DW_LNS_set_column:
-        // Takes a single unsigned LEB128 operand and stores it in the
-        // column register of the state machine.
-        State.Row.Column = DebugLineData.getULEB128(OffsetPtr);
-        if (OS)
-          *OS << " (" << State.Row.Column << ")";
-        break;
-
-      case DW_LNS_negate_stmt:
-        // Takes no arguments. Set the is_stmt register of the state
-        // machine to the logical negation of its current value.
-        State.Row.IsStmt = !State.Row.IsStmt;
-        break;
-
-      case DW_LNS_set_basic_block:
-        // Takes no arguments. Set the basic_block register of the
-        // state machine to true
-        State.Row.BasicBlock = true;
-        break;
-
-      case DW_LNS_const_add_pc:
-        // Takes no arguments. Add to the address register of the state
-        // machine the address increment value corresponding to special
-        // opcode 255. The motivation for DW_LNS_const_add_pc is this:
-        // when the statement program needs to advance the address by a
-        // small amount, it can use a single special opcode, which occupies
-        // a single byte. When it needs to advance the address by up to
-        // twice the range of the last special opcode, it can use
-        // DW_LNS_const_add_pc followed by a special opcode, for a total
-        // of two bytes. Only if it needs to advance the address by more
-        // than twice that range will it need to use both DW_LNS_advance_pc
-        // and a special opcode, requiring three or more bytes.
-        {
-          uint8_t AdjustOpcode = 255 - Prologue.OpcodeBase;
-          uint64_t AddrOffset =
-              (AdjustOpcode / Prologue.LineRange) * Prologue.MinInstLength;
-          State.Row.Address.Address += AddrOffset;
-          if (OS)
-            *OS
-                << format(" (0x%16.16" PRIx64 ")", AddrOffset);
-        }
-        break;
-
-      case DW_LNS_fixed_advance_pc:
-        // Takes a single uhalf operand. Add to the address register of
-        // the state machine the value of the (unencoded) operand. This
-        // is the only extended opcode that takes an argument that is not
-        // a variable length number. The motivation for DW_LNS_fixed_advance_pc
-        // is this: existing assemblers cannot emit DW_LNS_advance_pc or
-        // special opcodes because they cannot encode LEB128 numbers or
-        // judge when the computation of a special opcode overflows and
-        // requires the use of DW_LNS_advance_pc. Such assemblers, however,
-        // can use DW_LNS_fixed_advance_pc instead, sacrificing compression.
-        {
-          uint16_t PCOffset = DebugLineData.getRelocatedValue(2, OffsetPtr);
-          State.Row.Address.Address += PCOffset;
-          if (OS)
-            *OS
-                << format(" (0x%4.4" PRIx16 ")", PCOffset);
-        }
-        break;
-
-      case DW_LNS_set_prologue_end:
-        // Takes no arguments. Set the prologue_end register of the
-        // state machine to true
-        State.Row.PrologueEnd = true;
-        break;
-
-      case DW_LNS_set_epilogue_begin:
-        // Takes no arguments. Set the basic_block register of the
-        // state machine to true
-        State.Row.EpilogueBegin = true;
-        break;
-
-      case DW_LNS_set_isa:
-        // Takes a single unsigned LEB128 operand and stores it in the
-        // column register of the state machine.
-        State.Row.Isa = DebugLineData.getULEB128(OffsetPtr);
-        if (OS)
-          *OS << " (" << (uint64_t)State.Row.Isa << ")";
-        break;
-
-      default:
-        // Handle any unknown standard opcodes here. We know the lengths
-        // of such opcodes because they are specified in the prologue
-        // as a multiple of LEB128 operands for each opcode.
-        {
-          assert(Opcode - 1U < Prologue.StandardOpcodeLengths.size());
-          uint8_t OpcodeLength = Prologue.StandardOpcodeLengths[Opcode - 1];
-          for (uint8_t I = 0; I < OpcodeLength; ++I) {
-            uint64_t Value = DebugLineData.getULEB128(OffsetPtr);
-            if (OS)
-              *OS << format("Skipping ULEB128 value: 0x%16.16" PRIx64 ")\n",
-                            Value);
-          }
-        }
-        break;
-      }
-    } else {
-      // Special Opcodes
-
-      // A special opcode value is chosen based on the amount that needs
-      // to be added to the line and address registers. The maximum line
-      // increment for a special opcode is the value of the line_base
-      // field in the header, plus the value of the line_range field,
-      // minus 1 (line base + line range - 1). If the desired line
-      // increment is greater than the maximum line increment, a standard
-      // opcode must be used instead of a special opcode. The "address
-      // advance" is calculated by dividing the desired address increment
-      // by the minimum_instruction_length field from the header. The
-      // special opcode is then calculated using the following formula:
-      //
-      //  opcode = (desired line increment - line_base) +
-      //           (line_range * address advance) + opcode_base
-      //
-      // If the resulting opcode is greater than 255, a standard opcode
-      // must be used instead.
-      //
-      // To decode a special opcode, subtract the opcode_base from the
-      // opcode itself to give the adjusted opcode. The amount to
-      // increment the address register is the result of the adjusted
-      // opcode divided by the line_range multiplied by the
-      // minimum_instruction_length field from the header. That is:
-      //
-      //  address increment = (adjusted opcode / line_range) *
-      //                      minimum_instruction_length
-      //
-      // The amount to increment the line register is the line_base plus
-      // the result of the adjusted opcode modulo the line_range. That is:
-      //
-      // line increment = line_base + (adjusted opcode % line_range)
-
-      uint8_t AdjustOpcode = Opcode - Prologue.OpcodeBase;
-      uint64_t AddrOffset =
-          (AdjustOpcode / Prologue.LineRange) * Prologue.MinInstLength;
-      int32_t LineOffset =
-          Prologue.LineBase + (AdjustOpcode % Prologue.LineRange);
-      State.Row.Line += LineOffset;
-      State.Row.Address.Address += AddrOffset;
-
-      if (OS) {
-        *OS << "address += " << AddrOffset << ",  line += " << LineOffset
-            << "\n";
-        OS->indent(12);
-        State.Row.dump(*OS);
-      }
-
-      State.appendRowToMatrix();
-    }
-    if(OS)
-      *OS << "\n";
-  }
-
-  if (!State.Sequence.Empty)
-    RecoverableErrorCallback(createStringError(
-        errc::illegal_byte_sequence,
-        "last sequence in debug line table at offset 0x%8.8" PRIx64
-        " is not terminated",
-        DebugLineOffset));
-
-  // Sort all sequences so that address lookup will work faster.
-  if (!Sequences.empty()) {
-    llvm::sort(Sequences, Sequence::orderByHighPC);
-    // Note: actually, instruction address ranges of sequences should not
-    // overlap (in shared objects and executables). If they do, the address
-    // lookup would still work, though, but result would be ambiguous.
-    // We don't report warning in this case. For example,
-    // sometimes .so compiled from multiple object files contains a few
-    // rudimentary sequences for address ranges [0x0, 0xsomething).
-  }
-
-  return Error::success();
-}
-
-uint32_t DWARFDebugLine::LineTable::findRowInSeq(
-    const DWARFDebugLine::Sequence &Seq,
-    object::SectionedAddress Address) const {
-  if (!Seq.containsPC(Address))
-    return UnknownRowIndex;
-  assert(Seq.SectionIndex == Address.SectionIndex);
-  // In some cases, e.g. first instruction in a function, the compiler generates
-  // two entries, both with the same address. We want the last one.
-  //
-  // In general we want a non-empty range: the last row whose address is less
-  // than or equal to Address. This can be computed as upper_bound - 1.
-  DWARFDebugLine::Row Row;
-  Row.Address = Address;
-  RowIter FirstRow = Rows.begin() + Seq.FirstRowIndex;
-  RowIter LastRow = Rows.begin() + Seq.LastRowIndex;
-  assert(FirstRow->Address.Address <= Row.Address.Address &&
-         Row.Address.Address < LastRow[-1].Address.Address);
-  RowIter RowPos = std::upper_bound(FirstRow + 1, LastRow - 1, Row,
-                                    DWARFDebugLine::Row::orderByAddress) -
-                   1;
-  assert(Seq.SectionIndex == RowPos->Address.SectionIndex);
-  return RowPos - Rows.begin();
-}
-
-uint32_t DWARFDebugLine::LineTable::lookupAddress(
-    object::SectionedAddress Address) const {
-
-  // Search for relocatable addresses
-  uint32_t Result = lookupAddressImpl(Address);
-
-  if (Result != UnknownRowIndex ||
-      Address.SectionIndex == object::SectionedAddress::UndefSection)
-    return Result;
-
-  // Search for absolute addresses
-  Address.SectionIndex = object::SectionedAddress::UndefSection;
-  return lookupAddressImpl(Address);
-}
-
-uint32_t DWARFDebugLine::LineTable::lookupAddressImpl(
-    object::SectionedAddress Address) const {
-  // First, find an instruction sequence containing the given address.
-  DWARFDebugLine::Sequence Sequence;
-  Sequence.SectionIndex = Address.SectionIndex;
-  Sequence.HighPC = Address.Address;
-  SequenceIter It = llvm::upper_bound(Sequences, Sequence,
-                                      DWARFDebugLine::Sequence::orderByHighPC);
-  if (It == Sequences.end() || It->SectionIndex != Address.SectionIndex)
-    return UnknownRowIndex;
-  return findRowInSeq(*It, Address);
-}
-
-bool DWARFDebugLine::LineTable::lookupAddressRange(
-    object::SectionedAddress Address, uint64_t Size,
-    std::vector<uint32_t> &Result) const {
-
-  // Search for relocatable addresses
-  if (lookupAddressRangeImpl(Address, Size, Result))
-    return true;
-
-  if (Address.SectionIndex == object::SectionedAddress::UndefSection)
-    return false;
-
-  // Search for absolute addresses
-  Address.SectionIndex = object::SectionedAddress::UndefSection;
-  return lookupAddressRangeImpl(Address, Size, Result);
-}
-
-bool DWARFDebugLine::LineTable::lookupAddressRangeImpl(
-    object::SectionedAddress Address, uint64_t Size,
-    std::vector<uint32_t> &Result) const {
-  if (Sequences.empty())
-    return false;
-  uint64_t EndAddr = Address.Address + Size;
-  // First, find an instruction sequence containing the given address.
-  DWARFDebugLine::Sequence Sequence;
-  Sequence.SectionIndex = Address.SectionIndex;
-  Sequence.HighPC = Address.Address;
-  SequenceIter LastSeq = Sequences.end();
-  SequenceIter SeqPos = llvm::upper_bound(
-      Sequences, Sequence, DWARFDebugLine::Sequence::orderByHighPC);
-  if (SeqPos == LastSeq || !SeqPos->containsPC(Address))
-    return false;
-
-  SequenceIter StartPos = SeqPos;
-
-  // Add the rows from the first sequence to the vector, starting with the
-  // index we just calculated
-
-  while (SeqPos != LastSeq && SeqPos->LowPC < EndAddr) {
-    const DWARFDebugLine::Sequence &CurSeq = *SeqPos;
-    // For the first sequence, we need to find which row in the sequence is the
-    // first in our range.
-    uint32_t FirstRowIndex = CurSeq.FirstRowIndex;
-    if (SeqPos == StartPos)
-      FirstRowIndex = findRowInSeq(CurSeq, Address);
-
-    // Figure out the last row in the range.
-    uint32_t LastRowIndex =
-        findRowInSeq(CurSeq, {EndAddr - 1, Address.SectionIndex});
-    if (LastRowIndex == UnknownRowIndex)
-      LastRowIndex = CurSeq.LastRowIndex - 1;
-
-    assert(FirstRowIndex != UnknownRowIndex);
-    assert(LastRowIndex != UnknownRowIndex);
-
-    for (uint32_t I = FirstRowIndex; I <= LastRowIndex; ++I) {
-      Result.push_back(I);
-    }
-
-    ++SeqPos;
-  }
-
-  return true;
-}
-
-Optional<StringRef> DWARFDebugLine::LineTable::getSourceByIndex(uint64_t FileIndex,
-                                                                FileLineInfoKind Kind) const {
-  if (Kind == FileLineInfoKind::None || !Prologue.hasFileAtIndex(FileIndex))
-    return None;
-  const FileNameEntry &Entry = Prologue.getFileNameEntry(FileIndex);
-  if (Optional<const char *> source = Entry.Source.getAsCString())
-    return StringRef(*source);
-  return None;
-}
-
-static bool isPathAbsoluteOnWindowsOrPosix(const Twine &Path) {
-  // Debug info can contain paths from any OS, not necessarily
-  // an OS we're currently running on. Moreover different compilation units can
-  // be compiled on different operating systems and linked together later.
-  return sys::path::is_absolute(Path, sys::path::Style::posix) ||
-         sys::path::is_absolute(Path, sys::path::Style::windows);
-}
-
-bool DWARFDebugLine::Prologue::getFileNameByIndex(
-    uint64_t FileIndex, StringRef CompDir, FileLineInfoKind Kind,
-    std::string &Result, sys::path::Style Style) const {
-  if (Kind == FileLineInfoKind::None || !hasFileAtIndex(FileIndex))
-    return false;
-  const FileNameEntry &Entry = getFileNameEntry(FileIndex);
-  Optional<const char *> Name = Entry.Name.getAsCString();
-  if (!Name)
-    return false;
-  StringRef FileName = *Name;
-  if (Kind != FileLineInfoKind::AbsoluteFilePath ||
-      isPathAbsoluteOnWindowsOrPosix(FileName)) {
-    Result = FileName;
-    return true;
-  }
-
-  SmallString<16> FilePath;
-  StringRef IncludeDir;
-  // Be defensive about the contents of Entry.
-  if (getVersion() >= 5) {
-    if (Entry.DirIdx < IncludeDirectories.size())
-      IncludeDir = IncludeDirectories[Entry.DirIdx].getAsCString().getValue();
-  } else {
-    if (0 < Entry.DirIdx && Entry.DirIdx <= IncludeDirectories.size())
-      IncludeDir =
-          IncludeDirectories[Entry.DirIdx - 1].getAsCString().getValue();
-
-    // We may still need to append compilation directory of compile unit.
-    // We know that FileName is not absolute, the only way to have an
-    // absolute path at this point would be if IncludeDir is absolute.
-    if (!CompDir.empty() && !isPathAbsoluteOnWindowsOrPosix(IncludeDir))
-      sys::path::append(FilePath, Style, CompDir);
-  }
-
-  // sys::path::append skips empty strings.
-  sys::path::append(FilePath, Style, IncludeDir, FileName);
-  Result = FilePath.str();
-  return true;
-}
-
-bool DWARFDebugLine::LineTable::getFileLineInfoForAddress(
-    object::SectionedAddress Address, const char *CompDir,
-    FileLineInfoKind Kind, DILineInfo &Result) const {
-  // Get the index of row we're looking for in the line table.
-  uint32_t RowIndex = lookupAddress(Address);
-  if (RowIndex == -1U)
-    return false;
-  // Take file number and line/column from the row.
-  const auto &Row = Rows[RowIndex];
-  if (!getFileNameByIndex(Row.File, CompDir, Kind, Result.FileName))
-    return false;
-  Result.Line = Row.Line;
-  Result.Column = Row.Column;
-  Result.Discriminator = Row.Discriminator;
-  Result.Source = getSourceByIndex(Row.File, Kind);
-  return true;
-}
-
-// We want to supply the Unit associated with a .debug_line[.dwo] table when
-// we dump it, if possible, but still dump the table even if there isn't a Unit.
-// Therefore, collect up handles on all the Units that point into the
-// line-table section.
-static DWARFDebugLine::SectionParser::LineToUnitMap
-buildLineToUnitMap(DWARFDebugLine::SectionParser::cu_range CUs,
-                   DWARFDebugLine::SectionParser::tu_range TUs) {
-  DWARFDebugLine::SectionParser::LineToUnitMap LineToUnit;
-  for (const auto &CU : CUs)
-    if (auto CUDIE = CU->getUnitDIE())
-      if (auto StmtOffset = toSectionOffset(CUDIE.find(DW_AT_stmt_list)))
-        LineToUnit.insert(std::make_pair(*StmtOffset, &*CU));
-  for (const auto &TU : TUs)
-    if (auto TUDIE = TU->getUnitDIE())
-      if (auto StmtOffset = toSectionOffset(TUDIE.find(DW_AT_stmt_list)))
-        LineToUnit.insert(std::make_pair(*StmtOffset, &*TU));
-  return LineToUnit;
-}
-
-DWARFDebugLine::SectionParser::SectionParser(DWARFDataExtractor &Data,
-                                             const DWARFContext &C,
-                                             cu_range CUs, tu_range TUs)
-    : DebugLineData(Data), Context(C) {
-  LineToUnit = buildLineToUnitMap(CUs, TUs);
-  if (!DebugLineData.isValidOffset(Offset))
-    Done = true;
-}
-
-bool DWARFDebugLine::Prologue::totalLengthIsValid() const {
-  return TotalLength == dwarf::DW_LENGTH_DWARF64 ||
-         TotalLength < dwarf::DW_LENGTH_lo_reserved;
-}
-
-DWARFDebugLine::LineTable DWARFDebugLine::SectionParser::parseNext(
-    function_ref<void(Error)> RecoverableErrorCallback,
-    function_ref<void(Error)> UnrecoverableErrorCallback, raw_ostream *OS) {
-  assert(DebugLineData.isValidOffset(Offset) &&
-         "parsing should have terminated");
-  DWARFUnit *U = prepareToParse(Offset);
-  uint64_t OldOffset = Offset;
-  LineTable LT;
-  if (Error Err = LT.parse(DebugLineData, &Offset, Context, U,
-                           RecoverableErrorCallback, OS))
-    UnrecoverableErrorCallback(std::move(Err));
-  moveToNextTable(OldOffset, LT.Prologue);
-  return LT;
-}
-
-void DWARFDebugLine::SectionParser::skip(
-    function_ref<void(Error)> ErrorCallback) {
-  assert(DebugLineData.isValidOffset(Offset) &&
-         "parsing should have terminated");
-  DWARFUnit *U = prepareToParse(Offset);
-  uint64_t OldOffset = Offset;
-  LineTable LT;
-  if (Error Err = LT.Prologue.parse(DebugLineData, &Offset, Context, U))
-    ErrorCallback(std::move(Err));
-  moveToNextTable(OldOffset, LT.Prologue);
-}
-
-DWARFUnit *DWARFDebugLine::SectionParser::prepareToParse(uint64_t Offset) {
-  DWARFUnit *U = nullptr;
-  auto It = LineToUnit.find(Offset);
-  if (It != LineToUnit.end())
-    U = It->second;
-  DebugLineData.setAddressSize(U ? U->getAddressByteSize() : 0);
-  return U;
-}
-
-void DWARFDebugLine::SectionParser::moveToNextTable(uint64_t OldOffset,
-                                                    const Prologue &P) {
-  // If the length field is not valid, we don't know where the next table is, so
-  // cannot continue to parse. Mark the parser as done, and leave the Offset
-  // value as it currently is. This will be the end of the bad length field.
-  if (!P.totalLengthIsValid()) {
-    Done = true;
-    return;
-  }
-
-  Offset = OldOffset + P.TotalLength + P.sizeofTotalLength();
-  if (!DebugLineData.isValidOffset(Offset)) {
-    Done = true;
-  }
-}
+//===- DWARFDebugLine.cpp -------------------------------------------------===//\r
+//\r
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.\r
+// See https://llvm.org/LICENSE.txt for license information.\r
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception\r
+//\r
+//===----------------------------------------------------------------------===//\r
+\r
+#include "llvm/DebugInfo/DWARF/DWARFDebugLine.h"\r
+#include "llvm/ADT/Optional.h"\r
+#include "llvm/ADT/SmallString.h"\r
+#include "llvm/ADT/SmallVector.h"\r
+#include "llvm/ADT/StringRef.h"\r
+#include "llvm/BinaryFormat/Dwarf.h"\r
+#include "llvm/DebugInfo/DWARF/DWARFFormValue.h"\r
+#include "llvm/DebugInfo/DWARF/DWARFRelocMap.h"\r
+#include "llvm/Support/Errc.h"\r
+#include "llvm/Support/Format.h"\r
+#include "llvm/Support/WithColor.h"\r
+#include "llvm/Support/raw_ostream.h"\r
+#include <algorithm>\r
+#include <cassert>\r
+#include <cinttypes>\r
+#include <cstdint>\r
+#include <cstdio>\r
+#include <utility>\r
+\r
+using namespace llvm;\r
+using namespace dwarf;\r
+\r
+using FileLineInfoKind = DILineInfoSpecifier::FileLineInfoKind;\r
+\r
+namespace {\r
+\r
+struct ContentDescriptor {\r
+  dwarf::LineNumberEntryFormat Type;\r
+  dwarf::Form Form;\r
+};\r
+\r
+using ContentDescriptors = SmallVector<ContentDescriptor, 4>;\r
+\r
+} // end anonymous namespace\r
+\r
+void DWARFDebugLine::ContentTypeTracker::trackContentType(\r
+    dwarf::LineNumberEntryFormat ContentType) {\r
+  switch (ContentType) {\r
+  case dwarf::DW_LNCT_timestamp:\r
+    HasModTime = true;\r
+    break;\r
+  case dwarf::DW_LNCT_size:\r
+    HasLength = true;\r
+    break;\r
+  case dwarf::DW_LNCT_MD5:\r
+    HasMD5 = true;\r
+    break;\r
+  case dwarf::DW_LNCT_LLVM_source:\r
+    HasSource = true;\r
+    break;\r
+  default:\r
+    // We only care about values we consider optional, and new values may be\r
+    // added in the vendor extension range, so we do not match exhaustively.\r
+    break;\r
+  }\r
+}\r
+\r
+DWARFDebugLine::Prologue::Prologue() { clear(); }\r
+\r
+bool DWARFDebugLine::Prologue::hasFileAtIndex(uint64_t FileIndex) const {\r
+  uint16_t DwarfVersion = getVersion();\r
+  assert(DwarfVersion != 0 &&\r
+         "line table prologue has no dwarf version information");\r
+  if (DwarfVersion >= 5)\r
+    return FileIndex < FileNames.size();\r
+  return FileIndex != 0 && FileIndex <= FileNames.size();\r
+}\r
+\r
+const llvm::DWARFDebugLine::FileNameEntry &\r
+DWARFDebugLine::Prologue::getFileNameEntry(uint64_t Index) const {\r
+  uint16_t DwarfVersion = getVersion();\r
+  assert(DwarfVersion != 0 &&\r
+         "line table prologue has no dwarf version information");\r
+  // In DWARF v5 the file names are 0-indexed.\r
+  if (DwarfVersion >= 5)\r
+    return FileNames[Index];\r
+  return FileNames[Index - 1];\r
+}\r
+\r
+void DWARFDebugLine::Prologue::clear() {\r
+  TotalLength = PrologueLength = 0;\r
+  SegSelectorSize = 0;\r
+  MinInstLength = MaxOpsPerInst = DefaultIsStmt = LineBase = LineRange = 0;\r
+  OpcodeBase = 0;\r
+  FormParams = dwarf::FormParams({0, 0, DWARF32});\r
+  ContentTypes = ContentTypeTracker();\r
+  StandardOpcodeLengths.clear();\r
+  IncludeDirectories.clear();\r
+  FileNames.clear();\r
+}\r
+\r
+void DWARFDebugLine::Prologue::dump(raw_ostream &OS,\r
+                                    DIDumpOptions DumpOptions) const {\r
+  OS << "Line table prologue:\n"\r
+     << format("    total_length: 0x%8.8" PRIx64 "\n", TotalLength)\r
+     << format("         version: %u\n", getVersion());\r
+  if (getVersion() >= 5)\r
+    OS << format("    address_size: %u\n", getAddressSize())\r
+       << format(" seg_select_size: %u\n", SegSelectorSize);\r
+  OS << format(" prologue_length: 0x%8.8" PRIx64 "\n", PrologueLength)\r
+     << format(" min_inst_length: %u\n", MinInstLength)\r
+     << format(getVersion() >= 4 ? "max_ops_per_inst: %u\n" : "", MaxOpsPerInst)\r
+     << format(" default_is_stmt: %u\n", DefaultIsStmt)\r
+     << format("       line_base: %i\n", LineBase)\r
+     << format("      line_range: %u\n", LineRange)\r
+     << format("     opcode_base: %u\n", OpcodeBase);\r
+\r
+  for (uint32_t I = 0; I != StandardOpcodeLengths.size(); ++I)\r
+    OS << format("standard_opcode_lengths[%s] = %u\n",\r
+                 LNStandardString(I + 1).data(), StandardOpcodeLengths[I]);\r
+\r
+  if (!IncludeDirectories.empty()) {\r
+    // DWARF v5 starts directory indexes at 0.\r
+    uint32_t DirBase = getVersion() >= 5 ? 0 : 1;\r
+    for (uint32_t I = 0; I != IncludeDirectories.size(); ++I) {\r
+      OS << format("include_directories[%3u] = ", I + DirBase);\r
+      IncludeDirectories[I].dump(OS, DumpOptions);\r
+      OS << '\n';\r
+    }\r
+  }\r
+\r
+  if (!FileNames.empty()) {\r
+    // DWARF v5 starts file indexes at 0.\r
+    uint32_t FileBase = getVersion() >= 5 ? 0 : 1;\r
+    for (uint32_t I = 0; I != FileNames.size(); ++I) {\r
+      const FileNameEntry &FileEntry = FileNames[I];\r
+      OS <<   format("file_names[%3u]:\n", I + FileBase);\r
+      OS <<          "           name: ";\r
+      FileEntry.Name.dump(OS, DumpOptions);\r
+      OS << '\n'\r
+         <<   format("      dir_index: %" PRIu64 "\n", FileEntry.DirIdx);\r
+      if (ContentTypes.HasMD5)\r
+        OS <<        "   md5_checksum: " << FileEntry.Checksum.digest() << '\n';\r
+      if (ContentTypes.HasModTime)\r
+        OS << format("       mod_time: 0x%8.8" PRIx64 "\n", FileEntry.ModTime);\r
+      if (ContentTypes.HasLength)\r
+        OS << format("         length: 0x%8.8" PRIx64 "\n", FileEntry.Length);\r
+      if (ContentTypes.HasSource) {\r
+        OS <<        "         source: ";\r
+        FileEntry.Source.dump(OS, DumpOptions);\r
+        OS << '\n';\r
+      }\r
+    }\r
+  }\r
+}\r
+\r
+// Parse v2-v4 directory and file tables.\r
+static void\r
+parseV2DirFileTables(const DWARFDataExtractor &DebugLineData,\r
+                     uint64_t *OffsetPtr, uint64_t EndPrologueOffset,\r
+                     DWARFDebugLine::ContentTypeTracker &ContentTypes,\r
+                     std::vector<DWARFFormValue> &IncludeDirectories,\r
+                     std::vector<DWARFDebugLine::FileNameEntry> &FileNames) {\r
+  while (*OffsetPtr < EndPrologueOffset) {\r
+    StringRef S = DebugLineData.getCStrRef(OffsetPtr);\r
+    if (S.empty())\r
+      break;\r
+    DWARFFormValue Dir =\r
+        DWARFFormValue::createFromPValue(dwarf::DW_FORM_string, S.data());\r
+    IncludeDirectories.push_back(Dir);\r
+  }\r
+\r
+  while (*OffsetPtr < EndPrologueOffset) {\r
+    StringRef Name = DebugLineData.getCStrRef(OffsetPtr);\r
+    if (Name.empty())\r
+      break;\r
+    DWARFDebugLine::FileNameEntry FileEntry;\r
+    FileEntry.Name =\r
+        DWARFFormValue::createFromPValue(dwarf::DW_FORM_string, Name.data());\r
+    FileEntry.DirIdx = DebugLineData.getULEB128(OffsetPtr);\r
+    FileEntry.ModTime = DebugLineData.getULEB128(OffsetPtr);\r
+    FileEntry.Length = DebugLineData.getULEB128(OffsetPtr);\r
+    FileNames.push_back(FileEntry);\r
+  }\r
+\r
+  ContentTypes.HasModTime = true;\r
+  ContentTypes.HasLength = true;\r
+}\r
+\r
+// Parse v5 directory/file entry content descriptions.\r
+// Returns the descriptors, or an error if we did not find a path or ran off\r
+// the end of the prologue.\r
+static llvm::Expected<ContentDescriptors>\r
+parseV5EntryFormat(const DWARFDataExtractor &DebugLineData, uint64_t *OffsetPtr,\r
+                   DWARFDebugLine::ContentTypeTracker *ContentTypes) {\r
+  ContentDescriptors Descriptors;\r
+  int FormatCount = DebugLineData.getU8(OffsetPtr);\r
+  bool HasPath = false;\r
+  for (int I = 0; I != FormatCount; ++I) {\r
+    ContentDescriptor Descriptor;\r
+    Descriptor.Type =\r
+      dwarf::LineNumberEntryFormat(DebugLineData.getULEB128(OffsetPtr));\r
+    Descriptor.Form = dwarf::Form(DebugLineData.getULEB128(OffsetPtr));\r
+    if (Descriptor.Type == dwarf::DW_LNCT_path)\r
+      HasPath = true;\r
+    if (ContentTypes)\r
+      ContentTypes->trackContentType(Descriptor.Type);\r
+    Descriptors.push_back(Descriptor);\r
+  }\r
+\r
+  if (!HasPath)\r
+    return createStringError(errc::invalid_argument,\r
+                             "failed to parse entry content descriptions"\r
+                             " because no path was found");\r
+  return Descriptors;\r
+}\r
+\r
+static Error\r
+parseV5DirFileTables(const DWARFDataExtractor &DebugLineData,\r
+                     uint64_t *OffsetPtr, const dwarf::FormParams &FormParams,\r
+                     const DWARFContext &Ctx, const DWARFUnit *U,\r
+                     DWARFDebugLine::ContentTypeTracker &ContentTypes,\r
+                     std::vector<DWARFFormValue> &IncludeDirectories,\r
+                     std::vector<DWARFDebugLine::FileNameEntry> &FileNames) {\r
+  // Get the directory entry description.\r
+  llvm::Expected<ContentDescriptors> DirDescriptors =\r
+      parseV5EntryFormat(DebugLineData, OffsetPtr, nullptr);\r
+  if (!DirDescriptors)\r
+    return DirDescriptors.takeError();\r
+\r
+  // Get the directory entries, according to the format described above.\r
+  int DirEntryCount = DebugLineData.getU8(OffsetPtr);\r
+  for (int I = 0; I != DirEntryCount; ++I) {\r
+    for (auto Descriptor : *DirDescriptors) {\r
+      DWARFFormValue Value(Descriptor.Form);\r
+      switch (Descriptor.Type) {\r
+      case DW_LNCT_path:\r
+        if (!Value.extractValue(DebugLineData, OffsetPtr, FormParams, &Ctx, U))\r
+          return createStringError(errc::invalid_argument,\r
+                                   "failed to parse directory entry because "\r
+                                   "extracting the form value failed.");\r
+        IncludeDirectories.push_back(Value);\r
+        break;\r
+      default:\r
+        if (!Value.skipValue(DebugLineData, OffsetPtr, FormParams))\r
+          return createStringError(errc::invalid_argument,\r
+                                   "failed to parse directory entry because "\r
+                                   "skipping the form value failed.");\r
+      }\r
+    }\r
+  }\r
+\r
+  // Get the file entry description.\r
+  llvm::Expected<ContentDescriptors> FileDescriptors =\r
+      parseV5EntryFormat(DebugLineData, OffsetPtr, &ContentTypes);\r
+  if (!FileDescriptors)\r
+    return FileDescriptors.takeError();\r
+\r
+  // Get the file entries, according to the format described above.\r
+  int FileEntryCount = DebugLineData.getU8(OffsetPtr);\r
+  for (int I = 0; I != FileEntryCount; ++I) {\r
+    DWARFDebugLine::FileNameEntry FileEntry;\r
+    for (auto Descriptor : *FileDescriptors) {\r
+      DWARFFormValue Value(Descriptor.Form);\r
+      if (!Value.extractValue(DebugLineData, OffsetPtr, FormParams, &Ctx, U))\r
+        return createStringError(errc::invalid_argument,\r
+                                 "failed to parse file entry because "\r
+                                 "extracting the form value failed.");\r
+      switch (Descriptor.Type) {\r
+      case DW_LNCT_path:\r
+        FileEntry.Name = Value;\r
+        break;\r
+      case DW_LNCT_LLVM_source:\r
+        FileEntry.Source = Value;\r
+        break;\r
+      case DW_LNCT_directory_index:\r
+        FileEntry.DirIdx = Value.getAsUnsignedConstant().getValue();\r
+        break;\r
+      case DW_LNCT_timestamp:\r
+        FileEntry.ModTime = Value.getAsUnsignedConstant().getValue();\r
+        break;\r
+      case DW_LNCT_size:\r
+        FileEntry.Length = Value.getAsUnsignedConstant().getValue();\r
+        break;\r
+      case DW_LNCT_MD5:\r
+        if (!Value.getAsBlock() || Value.getAsBlock().getValue().size() != 16)\r
+          return createStringError(\r
+              errc::invalid_argument,\r
+              "failed to parse file entry because the MD5 hash is invalid");\r
+        std::uninitialized_copy_n(Value.getAsBlock().getValue().begin(), 16,\r
+                                  FileEntry.Checksum.Bytes.begin());\r
+        break;\r
+      default:\r
+        break;\r
+      }\r
+    }\r
+    FileNames.push_back(FileEntry);\r
+  }\r
+  return Error::success();\r
+}\r
+\r
+Error DWARFDebugLine::Prologue::parse(const DWARFDataExtractor &DebugLineData,\r
+                                      uint64_t *OffsetPtr,\r
+                                      const DWARFContext &Ctx,\r
+                                      const DWARFUnit *U) {\r
+  const uint64_t PrologueOffset = *OffsetPtr;\r
+\r
+  clear();\r
+  TotalLength = DebugLineData.getRelocatedValue(4, OffsetPtr);\r
+  if (TotalLength == dwarf::DW_LENGTH_DWARF64) {\r
+    FormParams.Format = dwarf::DWARF64;\r
+    TotalLength = DebugLineData.getU64(OffsetPtr);\r
+  } else if (TotalLength >= dwarf::DW_LENGTH_lo_reserved) {\r
+    return createStringError(errc::invalid_argument,\r
+        "parsing line table prologue at offset 0x%8.8" PRIx64\r
+        " unsupported reserved unit length found of value 0x%8.8" PRIx64,\r
+        PrologueOffset, TotalLength);\r
+  }\r
+  FormParams.Version = DebugLineData.getU16(OffsetPtr);\r
+  if (getVersion() < 2)\r
+    return createStringError(errc::not_supported,\r
+                       "parsing line table prologue at offset 0x%8.8" PRIx64\r
+                       " found unsupported version 0x%2.2" PRIx16,\r
+                       PrologueOffset, getVersion());\r
+\r
+  if (getVersion() >= 5) {\r
+    FormParams.AddrSize = DebugLineData.getU8(OffsetPtr);\r
+    assert((DebugLineData.getAddressSize() == 0 ||\r
+            DebugLineData.getAddressSize() == getAddressSize()) &&\r
+           "Line table header and data extractor disagree");\r
+    SegSelectorSize = DebugLineData.getU8(OffsetPtr);\r
+  }\r
+\r
+  PrologueLength =\r
+      DebugLineData.getRelocatedValue(sizeofPrologueLength(), OffsetPtr);\r
+  const uint64_t EndPrologueOffset = PrologueLength + *OffsetPtr;\r
+  MinInstLength = DebugLineData.getU8(OffsetPtr);\r
+  if (getVersion() >= 4)\r
+    MaxOpsPerInst = DebugLineData.getU8(OffsetPtr);\r
+  DefaultIsStmt = DebugLineData.getU8(OffsetPtr);\r
+  LineBase = DebugLineData.getU8(OffsetPtr);\r
+  LineRange = DebugLineData.getU8(OffsetPtr);\r
+  OpcodeBase = DebugLineData.getU8(OffsetPtr);\r
+\r
+  StandardOpcodeLengths.reserve(OpcodeBase - 1);\r
+  for (uint32_t I = 1; I < OpcodeBase; ++I) {\r
+    uint8_t OpLen = DebugLineData.getU8(OffsetPtr);\r
+    StandardOpcodeLengths.push_back(OpLen);\r
+  }\r
+\r
+  if (getVersion() >= 5) {\r
+    if (Error E =\r
+            parseV5DirFileTables(DebugLineData, OffsetPtr, FormParams, Ctx, U,\r
+                                 ContentTypes, IncludeDirectories, FileNames)) {\r
+      return joinErrors(\r
+          createStringError(\r
+              errc::invalid_argument,\r
+              "parsing line table prologue at 0x%8.8" PRIx64\r
+              " found an invalid directory or file table description at"\r
+              " 0x%8.8" PRIx64,\r
+              PrologueOffset, *OffsetPtr),\r
+          std::move(E));\r
+    }\r
+  } else\r
+    parseV2DirFileTables(DebugLineData, OffsetPtr, EndPrologueOffset,\r
+                         ContentTypes, IncludeDirectories, FileNames);\r
+\r
+  if (*OffsetPtr != EndPrologueOffset)\r
+    return createStringError(errc::invalid_argument,\r
+                       "parsing line table prologue at 0x%8.8" PRIx64\r
+                       " should have ended at 0x%8.8" PRIx64\r
+                       " but it ended at 0x%8.8" PRIx64,\r
+                       PrologueOffset, EndPrologueOffset, *OffsetPtr);\r
+  return Error::success();\r
+}\r
+\r
+DWARFDebugLine::Row::Row(bool DefaultIsStmt) { reset(DefaultIsStmt); }\r
+\r
+void DWARFDebugLine::Row::postAppend() {\r
+  Discriminator = 0;\r
+  BasicBlock = false;\r
+  PrologueEnd = false;\r
+  EpilogueBegin = false;\r
+}\r
+\r
+void DWARFDebugLine::Row::reset(bool DefaultIsStmt) {\r
+  Address.Address = 0;\r
+  Address.SectionIndex = object::SectionedAddress::UndefSection;\r
+  Line = 1;\r
+  Column = 0;\r
+  File = 1;\r
+  Isa = 0;\r
+  Discriminator = 0;\r
+  IsStmt = DefaultIsStmt;\r
+  BasicBlock = false;\r
+  EndSequence = false;\r
+  PrologueEnd = false;\r
+  EpilogueBegin = false;\r
+}\r
+\r
+void DWARFDebugLine::Row::dumpTableHeader(raw_ostream &OS) {\r
+  OS << "Address            Line   Column File   ISA Discriminator Flags\n"\r
+     << "------------------ ------ ------ ------ --- ------------- "\r
+        "-------------\n";\r
+}\r
+\r
+void DWARFDebugLine::Row::dump(raw_ostream &OS) const {\r
+  OS << format("0x%16.16" PRIx64 " %6u %6u", Address.Address, Line, Column)\r
+     << format(" %6u %3u %13u ", File, Isa, Discriminator)\r
+     << (IsStmt ? " is_stmt" : "") << (BasicBlock ? " basic_block" : "")\r
+     << (PrologueEnd ? " prologue_end" : "")\r
+     << (EpilogueBegin ? " epilogue_begin" : "")\r
+     << (EndSequence ? " end_sequence" : "") << '\n';\r
+}\r
+\r
+DWARFDebugLine::Sequence::Sequence() { reset(); }\r
+\r
+void DWARFDebugLine::Sequence::reset() {\r
+  LowPC = 0;\r
+  HighPC = 0;\r
+  SectionIndex = object::SectionedAddress::UndefSection;\r
+  FirstRowIndex = 0;\r
+  LastRowIndex = 0;\r
+  Empty = true;\r
+}\r
+\r
+DWARFDebugLine::LineTable::LineTable() { clear(); }\r
+\r
+void DWARFDebugLine::LineTable::dump(raw_ostream &OS,\r
+                                     DIDumpOptions DumpOptions) const {\r
+  Prologue.dump(OS, DumpOptions);\r
+\r
+  if (!Rows.empty()) {\r
+    OS << '\n';\r
+    Row::dumpTableHeader(OS);\r
+    for (const Row &R : Rows) {\r
+      R.dump(OS);\r
+    }\r
+  }\r
+\r
+  // Terminate the table with a final blank line to clearly delineate it from\r
+  // later dumps.\r
+  OS << '\n';\r
+}\r
+\r
+void DWARFDebugLine::LineTable::clear() {\r
+  Prologue.clear();\r
+  Rows.clear();\r
+  Sequences.clear();\r
+}\r
+\r
+DWARFDebugLine::ParsingState::ParsingState(struct LineTable *LT)\r
+    : LineTable(LT) {\r
+  resetRowAndSequence();\r
+}\r
+\r
+void DWARFDebugLine::ParsingState::resetRowAndSequence() {\r
+  Row.reset(LineTable->Prologue.DefaultIsStmt);\r
+  Sequence.reset();\r
+}\r
+\r
+void DWARFDebugLine::ParsingState::appendRowToMatrix() {\r
+  unsigned RowNumber = LineTable->Rows.size();\r
+  if (Sequence.Empty) {\r
+    // Record the beginning of instruction sequence.\r
+    Sequence.Empty = false;\r
+    Sequence.LowPC = Row.Address.Address;\r
+    Sequence.FirstRowIndex = RowNumber;\r
+  }\r
+  LineTable->appendRow(Row);\r
+  if (Row.EndSequence) {\r
+    // Record the end of instruction sequence.\r
+    Sequence.HighPC = Row.Address.Address;\r
+    Sequence.LastRowIndex = RowNumber + 1;\r
+    Sequence.SectionIndex = Row.Address.SectionIndex;\r
+    if (Sequence.isValid())\r
+      LineTable->appendSequence(Sequence);\r
+    Sequence.reset();\r
+  }\r
+  Row.postAppend();\r
+}\r
+\r
+const DWARFDebugLine::LineTable *\r
+DWARFDebugLine::getLineTable(uint64_t Offset) const {\r
+  LineTableConstIter Pos = LineTableMap.find(Offset);\r
+  if (Pos != LineTableMap.end())\r
+    return &Pos->second;\r
+  return nullptr;\r
+}\r
+\r
+Expected<const DWARFDebugLine::LineTable *> DWARFDebugLine::getOrParseLineTable(\r
+    DWARFDataExtractor &DebugLineData, uint64_t Offset, const DWARFContext &Ctx,\r
+    const DWARFUnit *U, function_ref<void(Error)> RecoverableErrorCallback) {\r
+  if (!DebugLineData.isValidOffset(Offset))\r
+    return createStringError(errc::invalid_argument, "offset 0x%8.8" PRIx64\r
+                       " is not a valid debug line section offset",\r
+                       Offset);\r
+\r
+  std::pair<LineTableIter, bool> Pos =\r
+      LineTableMap.insert(LineTableMapTy::value_type(Offset, LineTable()));\r
+  LineTable *LT = &Pos.first->second;\r
+  if (Pos.second) {\r
+    if (Error Err =\r
+            LT->parse(DebugLineData, &Offset, Ctx, U, RecoverableErrorCallback))\r
+      return std::move(Err);\r
+    return LT;\r
+  }\r
+  return LT;\r
+}\r
+\r
+Error DWARFDebugLine::LineTable::parse(\r
+    DWARFDataExtractor &DebugLineData, uint64_t *OffsetPtr,\r
+    const DWARFContext &Ctx, const DWARFUnit *U,\r
+    function_ref<void(Error)> RecoverableErrorCallback, raw_ostream *OS) {\r
+  const uint64_t DebugLineOffset = *OffsetPtr;\r
+\r
+  clear();\r
+\r
+  Error PrologueErr = Prologue.parse(DebugLineData, OffsetPtr, Ctx, U);\r
+\r
+  if (OS) {\r
+    // The presence of OS signals verbose dumping.\r
+    DIDumpOptions DumpOptions;\r
+    DumpOptions.Verbose = true;\r
+    Prologue.dump(*OS, DumpOptions);\r
+  }\r
+\r
+  if (PrologueErr)\r
+    return PrologueErr;\r
+\r
+  uint64_t ProgramLength = Prologue.TotalLength + Prologue.sizeofTotalLength();\r
+  if (!DebugLineData.isValidOffsetForDataOfSize(DebugLineOffset,\r
+                                                ProgramLength)) {\r
+    assert(DebugLineData.size() > DebugLineOffset &&\r
+           "prologue parsing should handle invalid offset");\r
+    uint64_t BytesRemaining = DebugLineData.size() - DebugLineOffset;\r
+    RecoverableErrorCallback(\r
+        createStringError(errc::invalid_argument,\r
+                          "line table program with offset 0x%8.8" PRIx64\r
+                          " has length 0x%8.8" PRIx64 " but only 0x%8.8" PRIx64\r
+                          " bytes are available",\r
+                          DebugLineOffset, ProgramLength, BytesRemaining));\r
+    // Continue by capping the length at the number of remaining bytes.\r
+    ProgramLength = BytesRemaining;\r
+  }\r
+\r
+  const uint64_t EndOffset = DebugLineOffset + ProgramLength;\r
+\r
+  // See if we should tell the data extractor the address size.\r
+  if (DebugLineData.getAddressSize() == 0)\r
+    DebugLineData.setAddressSize(Prologue.getAddressSize());\r
+  else\r
+    assert(Prologue.getAddressSize() == 0 ||\r
+           Prologue.getAddressSize() == DebugLineData.getAddressSize());\r
+\r
+  ParsingState State(this);\r
+\r
+  while (*OffsetPtr < EndOffset) {\r
+    if (OS)\r
+      *OS << format("0x%08.08" PRIx64 ": ", *OffsetPtr);\r
+\r
+    uint8_t Opcode = DebugLineData.getU8(OffsetPtr);\r
+\r
+    if (OS)\r
+      *OS << format("%02.02" PRIx8 " ", Opcode);\r
+\r
+    if (Opcode == 0) {\r
+      // Extended Opcodes always start with a zero opcode followed by\r
+      // a uleb128 length so you can skip ones you don't know about\r
+      uint64_t Len = DebugLineData.getULEB128(OffsetPtr);\r
+      uint64_t ExtOffset = *OffsetPtr;\r
+\r
+      // Tolerate zero-length; assume length is correct and soldier on.\r
+      if (Len == 0) {\r
+        if (OS)\r
+          *OS << "Badly formed extended line op (length 0)\n";\r
+        continue;\r
+      }\r
+\r
+      uint8_t SubOpcode = DebugLineData.getU8(OffsetPtr);\r
+      if (OS)\r
+        *OS << LNExtendedString(SubOpcode);\r
+      switch (SubOpcode) {\r
+      case DW_LNE_end_sequence:\r
+        // Set the end_sequence register of the state machine to true and\r
+        // append a row to the matrix using the current values of the\r
+        // state-machine registers. Then reset the registers to the initial\r
+        // values specified above. Every statement program sequence must end\r
+        // with a DW_LNE_end_sequence instruction which creates a row whose\r
+        // address is that of the byte after the last target machine instruction\r
+        // of the sequence.\r
+        State.Row.EndSequence = true;\r
+        if (OS) {\r
+          *OS << "\n";\r
+          OS->indent(12);\r
+          State.Row.dump(*OS);\r
+        }\r
+        State.appendRowToMatrix();\r
+        State.resetRowAndSequence();\r
+        break;\r
+\r
+      case DW_LNE_set_address:\r
+        // Takes a single relocatable address as an operand. The size of the\r
+        // operand is the size appropriate to hold an address on the target\r
+        // machine. Set the address register to the value given by the\r
+        // relocatable address. All of the other statement program opcodes\r
+        // that affect the address register add a delta to it. This instruction\r
+        // stores a relocatable value into it instead.\r
+        //\r
+        // Make sure the extractor knows the address size.  If not, infer it\r
+        // from the size of the operand.\r
+        if (DebugLineData.getAddressSize() == 0)\r
+          DebugLineData.setAddressSize(Len - 1);\r
+        else if (DebugLineData.getAddressSize() != Len - 1) {\r
+          return createStringError(errc::invalid_argument,\r
+                             "mismatching address size at offset 0x%8.8" PRIx64\r
+                             " expected 0x%2.2" PRIx8 " found 0x%2.2" PRIx64,\r
+                             ExtOffset, DebugLineData.getAddressSize(),\r
+                             Len - 1);\r
+        }\r
+        State.Row.Address.Address = DebugLineData.getRelocatedAddress(\r
+            OffsetPtr, &State.Row.Address.SectionIndex);\r
+        if (OS)\r
+          *OS << format(" (0x%16.16" PRIx64 ")", State.Row.Address.Address);\r
+        break;\r
+\r
+      case DW_LNE_define_file:\r
+        // Takes 4 arguments. The first is a null terminated string containing\r
+        // a source file name. The second is an unsigned LEB128 number\r
+        // representing the directory index of the directory in which the file\r
+        // was found. The third is an unsigned LEB128 number representing the\r
+        // time of last modification of the file. The fourth is an unsigned\r
+        // LEB128 number representing the length in bytes of the file. The time\r
+        // and length fields may contain LEB128(0) if the information is not\r
+        // available.\r
+        //\r
+        // The directory index represents an entry in the include_directories\r
+        // section of the statement program prologue. The index is LEB128(0)\r
+        // if the file was found in the current directory of the compilation,\r
+        // LEB128(1) if it was found in the first directory in the\r
+        // include_directories section, and so on. The directory index is\r
+        // ignored for file names that represent full path names.\r
+        //\r
+        // The files are numbered, starting at 1, in the order in which they\r
+        // appear; the names in the prologue come before names defined by\r
+        // the DW_LNE_define_file instruction. These numbers are used in the\r
+        // the file register of the state machine.\r
+        {\r
+          FileNameEntry FileEntry;\r
+          const char *Name = DebugLineData.getCStr(OffsetPtr);\r
+          FileEntry.Name =\r
+              DWARFFormValue::createFromPValue(dwarf::DW_FORM_string, Name);\r
+          FileEntry.DirIdx = DebugLineData.getULEB128(OffsetPtr);\r
+          FileEntry.ModTime = DebugLineData.getULEB128(OffsetPtr);\r
+          FileEntry.Length = DebugLineData.getULEB128(OffsetPtr);\r
+          Prologue.FileNames.push_back(FileEntry);\r
+          if (OS)\r
+            *OS << " (" << Name << ", dir=" << FileEntry.DirIdx << ", mod_time="\r
+                << format("(0x%16.16" PRIx64 ")", FileEntry.ModTime)\r
+                << ", length=" << FileEntry.Length << ")";\r
+        }\r
+        break;\r
+\r
+      case DW_LNE_set_discriminator:\r
+        State.Row.Discriminator = DebugLineData.getULEB128(OffsetPtr);\r
+        if (OS)\r
+          *OS << " (" << State.Row.Discriminator << ")";\r
+        break;\r
+\r
+      default:\r
+        if (OS)\r
+          *OS << format("Unrecognized extended op 0x%02.02" PRIx8, SubOpcode)\r
+              << format(" length %" PRIx64, Len);\r
+        // Len doesn't include the zero opcode byte or the length itself, but\r
+        // it does include the sub_opcode, so we have to adjust for that.\r
+        (*OffsetPtr) += Len - 1;\r
+        break;\r
+      }\r
+      // Make sure the stated and parsed lengths are the same.\r
+      // Otherwise we have an unparseable line-number program.\r
+      if (*OffsetPtr - ExtOffset != Len)\r
+        return createStringError(errc::illegal_byte_sequence,\r
+                           "unexpected line op length at offset 0x%8.8" PRIx64\r
+                           " expected 0x%2.2" PRIx64 " found 0x%2.2" PRIx64,\r
+                           ExtOffset, Len, *OffsetPtr - ExtOffset);\r
+    } else if (Opcode < Prologue.OpcodeBase) {\r
+      if (OS)\r
+        *OS << LNStandardString(Opcode);\r
+      switch (Opcode) {\r
+      // Standard Opcodes\r
+      case DW_LNS_copy:\r
+        // Takes no arguments. Append a row to the matrix using the\r
+        // current values of the state-machine registers.\r
+        if (OS) {\r
+          *OS << "\n";\r
+          OS->indent(12);\r
+          State.Row.dump(*OS);\r
+          *OS << "\n";\r
+        }\r
+        State.appendRowToMatrix();\r
+        break;\r
+\r
+      case DW_LNS_advance_pc:\r
+        // Takes a single unsigned LEB128 operand, multiplies it by the\r
+        // min_inst_length field of the prologue, and adds the\r
+        // result to the address register of the state machine.\r
+        {\r
+          uint64_t AddrOffset =\r
+              DebugLineData.getULEB128(OffsetPtr) * Prologue.MinInstLength;\r
+          State.Row.Address.Address += AddrOffset;\r
+          if (OS)\r
+            *OS << " (" << AddrOffset << ")";\r
+        }\r
+        break;\r
+\r
+      case DW_LNS_advance_line:\r
+        // Takes a single signed LEB128 operand and adds that value to\r
+        // the line register of the state machine.\r
+        State.Row.Line += DebugLineData.getSLEB128(OffsetPtr);\r
+        if (OS)\r
+          *OS << " (" << State.Row.Line << ")";\r
+        break;\r
+\r
+      case DW_LNS_set_file:\r
+        // Takes a single unsigned LEB128 operand and stores it in the file\r
+        // register of the state machine.\r
+        State.Row.File = DebugLineData.getULEB128(OffsetPtr);\r
+        if (OS)\r
+          *OS << " (" << State.Row.File << ")";\r
+        break;\r
+\r
+      case DW_LNS_set_column:\r
+        // Takes a single unsigned LEB128 operand and stores it in the\r
+        // column register of the state machine.\r
+        State.Row.Column = DebugLineData.getULEB128(OffsetPtr);\r
+        if (OS)\r
+          *OS << " (" << State.Row.Column << ")";\r
+        break;\r
+\r
+      case DW_LNS_negate_stmt:\r
+        // Takes no arguments. Set the is_stmt register of the state\r
+        // machine to the logical negation of its current value.\r
+        State.Row.IsStmt = !State.Row.IsStmt;\r
+        break;\r
+\r
+      case DW_LNS_set_basic_block:\r
+        // Takes no arguments. Set the basic_block register of the\r
+        // state machine to true\r
+        State.Row.BasicBlock = true;\r
+        break;\r
+\r
+      case DW_LNS_const_add_pc:\r
+        // Takes no arguments. Add to the address register of the state\r
+        // machine the address increment value corresponding to special\r
+        // opcode 255. The motivation for DW_LNS_const_add_pc is this:\r
+        // when the statement program needs to advance the address by a\r
+        // small amount, it can use a single special opcode, which occupies\r
+        // a single byte. When it needs to advance the address by up to\r
+        // twice the range of the last special opcode, it can use\r
+        // DW_LNS_const_add_pc followed by a special opcode, for a total\r
+        // of two bytes. Only if it needs to advance the address by more\r
+        // than twice that range will it need to use both DW_LNS_advance_pc\r
+        // and a special opcode, requiring three or more bytes.\r
+        {\r
+          uint8_t AdjustOpcode = 255 - Prologue.OpcodeBase;\r
+          uint64_t AddrOffset =\r
+              (AdjustOpcode / Prologue.LineRange) * Prologue.MinInstLength;\r
+          State.Row.Address.Address += AddrOffset;\r
+          if (OS)\r
+            *OS\r
+                << format(" (0x%16.16" PRIx64 ")", AddrOffset);\r
+        }\r
+        break;\r
+\r
+      case DW_LNS_fixed_advance_pc:\r
+        // Takes a single uhalf operand. Add to the address register of\r
+        // the state machine the value of the (unencoded) operand. This\r
+        // is the only extended opcode that takes an argument that is not\r
+        // a variable length number. The motivation for DW_LNS_fixed_advance_pc\r
+        // is this: existing assemblers cannot emit DW_LNS_advance_pc or\r
+        // special opcodes because they cannot encode LEB128 numbers or\r
+        // judge when the computation of a special opcode overflows and\r
+        // requires the use of DW_LNS_advance_pc. Such assemblers, however,\r
+        // can use DW_LNS_fixed_advance_pc instead, sacrificing compression.\r
+        {\r
+          uint16_t PCOffset = DebugLineData.getRelocatedValue(2, OffsetPtr);\r
+          State.Row.Address.Address += PCOffset;\r
+          if (OS)\r
+            *OS\r
+                << format(" (0x%4.4" PRIx16 ")", PCOffset);\r
+        }\r
+        break;\r
+\r
+      case DW_LNS_set_prologue_end:\r
+        // Takes no arguments. Set the prologue_end register of the\r
+        // state machine to true\r
+        State.Row.PrologueEnd = true;\r
+        break;\r
+\r
+      case DW_LNS_set_epilogue_begin:\r
+        // Takes no arguments. Set the basic_block register of the\r
+        // state machine to true\r
+        State.Row.EpilogueBegin = true;\r
+        break;\r
+\r
+      case DW_LNS_set_isa:\r
+        // Takes a single unsigned LEB128 operand and stores it in the\r
+        // column register of the state machine.\r
+        State.Row.Isa = DebugLineData.getULEB128(OffsetPtr);\r
+        if (OS)\r
+          *OS << " (" << (uint64_t)State.Row.Isa << ")";\r
+        break;\r
+\r
+      default:\r
+        // Handle any unknown standard opcodes here. We know the lengths\r
+        // of such opcodes because they are specified in the prologue\r
+        // as a multiple of LEB128 operands for each opcode.\r
+        {\r
+          assert(Opcode - 1U < Prologue.StandardOpcodeLengths.size());\r
+          uint8_t OpcodeLength = Prologue.StandardOpcodeLengths[Opcode - 1];\r
+          for (uint8_t I = 0; I < OpcodeLength; ++I) {\r
+            uint64_t Value = DebugLineData.getULEB128(OffsetPtr);\r
+            if (OS)\r
+              *OS << format("Skipping ULEB128 value: 0x%16.16" PRIx64 ")\n",\r
+                            Value);\r
+          }\r
+        }\r
+        break;\r
+      }\r
+    } else {\r
+      // Special Opcodes\r
+\r
+      // A special opcode value is chosen based on the amount that needs\r
+      // to be added to the line and address registers. The maximum line\r
+      // increment for a special opcode is the value of the line_base\r
+      // field in the header, plus the value of the line_range field,\r
+      // minus 1 (line base + line range - 1). If the desired line\r
+      // increment is greater than the maximum line increment, a standard\r
+      // opcode must be used instead of a special opcode. The "address\r
+      // advance" is calculated by dividing the desired address increment\r
+      // by the minimum_instruction_length field from the header. The\r
+      // special opcode is then calculated using the following formula:\r
+      //\r
+      //  opcode = (desired line increment - line_base) +\r
+      //           (line_range * address advance) + opcode_base\r
+      //\r
+      // If the resulting opcode is greater than 255, a standard opcode\r
+      // must be used instead.\r
+      //\r
+      // To decode a special opcode, subtract the opcode_base from the\r
+      // opcode itself to give the adjusted opcode. The amount to\r
+      // increment the address register is the result of the adjusted\r
+      // opcode divided by the line_range multiplied by the\r
+      // minimum_instruction_length field from the header. That is:\r
+      //\r
+      //  address increment = (adjusted opcode / line_range) *\r
+      //                      minimum_instruction_length\r
+      //\r
+      // The amount to increment the line register is the line_base plus\r
+      // the result of the adjusted opcode modulo the line_range. That is:\r
+      //\r
+      // line increment = line_base + (adjusted opcode % line_range)\r
+\r
+      uint8_t AdjustOpcode = Opcode - Prologue.OpcodeBase;\r
+      uint64_t AddrOffset =\r
+          (AdjustOpcode / Prologue.LineRange) * Prologue.MinInstLength;\r
+      int32_t LineOffset =\r
+          Prologue.LineBase + (AdjustOpcode % Prologue.LineRange);\r
+      State.Row.Line += LineOffset;\r
+      State.Row.Address.Address += AddrOffset;\r
+\r
+      if (OS) {\r
+        *OS << "address += " << AddrOffset << ",  line += " << LineOffset\r
+            << "\n";\r
+        OS->indent(12);\r
+        State.Row.dump(*OS);\r
+      }\r
+\r
+      State.appendRowToMatrix();\r
+    }\r
+    if(OS)\r
+      *OS << "\n";\r
+  }\r
+\r
+  if (!State.Sequence.Empty)\r
+    RecoverableErrorCallback(createStringError(\r
+        errc::illegal_byte_sequence,\r
+        "last sequence in debug line table at offset 0x%8.8" PRIx64\r
+        " is not terminated",\r
+        DebugLineOffset));\r
+\r
+  // Sort all sequences so that address lookup will work faster.\r
+  if (!Sequences.empty()) {\r
+    llvm::sort(Sequences, Sequence::orderByHighPC);\r
+    // Note: actually, instruction address ranges of sequences should not\r
+    // overlap (in shared objects and executables). If they do, the address\r
+    // lookup would still work, though, but result would be ambiguous.\r
+    // We don't report warning in this case. For example,\r
+    // sometimes .so compiled from multiple object files contains a few\r
+    // rudimentary sequences for address ranges [0x0, 0xsomething).\r
+  }\r
+\r
+  return Error::success();\r
+}\r
+\r
+uint32_t DWARFDebugLine::LineTable::findRowInSeq(\r
+    const DWARFDebugLine::Sequence &Seq,\r
+    object::SectionedAddress Address) const {\r
+  if (!Seq.containsPC(Address))\r
+    return UnknownRowIndex;\r
+  assert(Seq.SectionIndex == Address.SectionIndex);\r
+  // In some cases, e.g. first instruction in a function, the compiler generates\r
+  // two entries, both with the same address. We want the last one.\r
+  //\r
+  // In general we want a non-empty range: the last row whose address is less\r
+  // than or equal to Address. This can be computed as upper_bound - 1.\r
+  DWARFDebugLine::Row Row;\r
+  Row.Address = Address;\r
+  RowIter FirstRow = Rows.begin() + Seq.FirstRowIndex;\r
+  RowIter LastRow = Rows.begin() + Seq.LastRowIndex;\r
+  assert(FirstRow->Address.Address <= Row.Address.Address &&\r
+         Row.Address.Address < LastRow[-1].Address.Address);\r
+  RowIter RowPos = std::upper_bound(FirstRow + 1, LastRow - 1, Row,\r
+                                    DWARFDebugLine::Row::orderByAddress) -\r
+                   1;\r
+  assert(Seq.SectionIndex == RowPos->Address.SectionIndex);\r
+  return RowPos - Rows.begin();\r
+}\r
+\r
+uint32_t DWARFDebugLine::LineTable::lookupAddress(\r
+    object::SectionedAddress Address) const {\r
+\r
+  // Search for relocatable addresses\r
+  uint32_t Result = lookupAddressImpl(Address);\r
+\r
+  if (Result != UnknownRowIndex ||\r
+      Address.SectionIndex == object::SectionedAddress::UndefSection)\r
+    return Result;\r
+\r
+  // Search for absolute addresses\r
+  Address.SectionIndex = object::SectionedAddress::UndefSection;\r
+  return lookupAddressImpl(Address);\r
+}\r
+\r
+uint32_t DWARFDebugLine::LineTable::lookupAddressImpl(\r
+    object::SectionedAddress Address) const {\r
+  // First, find an instruction sequence containing the given address.\r
+  DWARFDebugLine::Sequence Sequence;\r
+  Sequence.SectionIndex = Address.SectionIndex;\r
+  Sequence.HighPC = Address.Address;\r
+  SequenceIter It = llvm::upper_bound(Sequences, Sequence,\r
+                                      DWARFDebugLine::Sequence::orderByHighPC);\r
+  if (It == Sequences.end() || It->SectionIndex != Address.SectionIndex)\r
+    return UnknownRowIndex;\r
+  return findRowInSeq(*It, Address);\r
+}\r
+\r
+bool DWARFDebugLine::LineTable::lookupAddressRange(\r
+    object::SectionedAddress Address, uint64_t Size,\r
+    std::vector<uint32_t> &Result) const {\r
+\r
+  // Search for relocatable addresses\r
+  if (lookupAddressRangeImpl(Address, Size, Result))\r
+    return true;\r
+\r
+  if (Address.SectionIndex == object::SectionedAddress::UndefSection)\r
+    return false;\r
+\r
+  // Search for absolute addresses\r
+  Address.SectionIndex = object::SectionedAddress::UndefSection;\r
+  return lookupAddressRangeImpl(Address, Size, Result);\r
+}\r
+\r
+bool DWARFDebugLine::LineTable::lookupAddressRangeImpl(\r
+    object::SectionedAddress Address, uint64_t Size,\r
+    std::vector<uint32_t> &Result) const {\r
+  if (Sequences.empty())\r
+    return false;\r
+  uint64_t EndAddr = Address.Address + Size;\r
+  // First, find an instruction sequence containing the given address.\r
+  DWARFDebugLine::Sequence Sequence;\r
+  Sequence.SectionIndex = Address.SectionIndex;\r
+  Sequence.HighPC = Address.Address;\r
+  SequenceIter LastSeq = Sequences.end();\r
+  SequenceIter SeqPos = llvm::upper_bound(\r
+      Sequences, Sequence, DWARFDebugLine::Sequence::orderByHighPC);\r
+  if (SeqPos == LastSeq || !SeqPos->containsPC(Address))\r
+    return false;\r
+\r
+  SequenceIter StartPos = SeqPos;\r
+\r
+  // Add the rows from the first sequence to the vector, starting with the\r
+  // index we just calculated\r
+\r
+  while (SeqPos != LastSeq && SeqPos->LowPC < EndAddr) {\r
+    const DWARFDebugLine::Sequence &CurSeq = *SeqPos;\r
+    // For the first sequence, we need to find which row in the sequence is the\r
+    // first in our range.\r
+    uint32_t FirstRowIndex = CurSeq.FirstRowIndex;\r
+    if (SeqPos == StartPos)\r
+      FirstRowIndex = findRowInSeq(CurSeq, Address);\r
+\r
+    // Figure out the last row in the range.\r
+    uint32_t LastRowIndex =\r
+        findRowInSeq(CurSeq, {EndAddr - 1, Address.SectionIndex});\r
+    if (LastRowIndex == UnknownRowIndex)\r
+      LastRowIndex = CurSeq.LastRowIndex - 1;\r
+\r
+    assert(FirstRowIndex != UnknownRowIndex);\r
+    assert(LastRowIndex != UnknownRowIndex);\r
+\r
+    for (uint32_t I = FirstRowIndex; I <= LastRowIndex; ++I) {\r
+      Result.push_back(I);\r
+    }\r
+\r
+    ++SeqPos;\r
+  }\r
+\r
+  return true;\r
+}\r
+\r
+Optional<StringRef> DWARFDebugLine::LineTable::getSourceByIndex(uint64_t FileIndex,\r
+                                                                FileLineInfoKind Kind) const {\r
+  if (Kind == FileLineInfoKind::None || !Prologue.hasFileAtIndex(FileIndex))\r
+    return None;\r
+  const FileNameEntry &Entry = Prologue.getFileNameEntry(FileIndex);\r
+  if (Optional<const char *> source = Entry.Source.getAsCString())\r
+    return StringRef(*source);\r
+  return None;\r
+}\r
+\r
+static bool isPathAbsoluteOnWindowsOrPosix(const Twine &Path) {\r
+  // Debug info can contain paths from any OS, not necessarily\r
+  // an OS we're currently running on. Moreover different compilation units can\r
+  // be compiled on different operating systems and linked together later.\r
+  return sys::path::is_absolute(Path, sys::path::Style::posix) ||\r
+         sys::path::is_absolute(Path, sys::path::Style::windows);\r
+}\r
+\r
+bool DWARFDebugLine::Prologue::getFileNameByIndex(\r
+    uint64_t FileIndex, StringRef CompDir, FileLineInfoKind Kind,\r
+    std::string &Result, sys::path::Style Style) const {\r
+  if (Kind == FileLineInfoKind::None || !hasFileAtIndex(FileIndex))\r
+    return false;\r
+  const FileNameEntry &Entry = getFileNameEntry(FileIndex);\r
+  Optional<const char *> Name = Entry.Name.getAsCString();\r
+  if (!Name)\r
+    return false;\r
+  StringRef FileName = *Name;\r
+  if (Kind != FileLineInfoKind::AbsoluteFilePath ||\r
+      isPathAbsoluteOnWindowsOrPosix(FileName)) {\r
+    Result = FileName;\r
+    return true;\r
+  }\r
+\r
+  SmallString<16> FilePath;\r
+  StringRef IncludeDir;\r
+  // Be defensive about the contents of Entry.\r
+  if (getVersion() >= 5) {\r
+    if (Entry.DirIdx < IncludeDirectories.size())\r
+      IncludeDir = IncludeDirectories[Entry.DirIdx].getAsCString().getValue();\r
+  } else {\r
+    if (0 < Entry.DirIdx && Entry.DirIdx <= IncludeDirectories.size())\r
+      IncludeDir =\r
+          IncludeDirectories[Entry.DirIdx - 1].getAsCString().getValue();\r
+\r
+    // We may still need to append compilation directory of compile unit.\r
+    // We know that FileName is not absolute, the only way to have an\r
+    // absolute path at this point would be if IncludeDir is absolute.\r
+    if (!CompDir.empty() && !isPathAbsoluteOnWindowsOrPosix(IncludeDir))\r
+      sys::path::append(FilePath, Style, CompDir);\r
+  }\r
+\r
+  // sys::path::append skips empty strings.\r
+  sys::path::append(FilePath, Style, IncludeDir, FileName);\r
+  Result = FilePath.str();\r
+  return true;\r
+}\r
+\r
+bool DWARFDebugLine::LineTable::getFileLineInfoForAddress(\r
+    object::SectionedAddress Address, const char *CompDir,\r
+    FileLineInfoKind Kind, DILineInfo &Result) const {\r
+  // Get the index of row we're looking for in the line table.\r
+  uint32_t RowIndex = lookupAddress(Address);\r
+  if (RowIndex == -1U)\r
+    return false;\r
+  // Take file number and line/column from the row.\r
+  const auto &Row = Rows[RowIndex];\r
+  if (!getFileNameByIndex(Row.File, CompDir, Kind, Result.FileName))\r
+    return false;\r
+  Result.Line = Row.Line;\r
+  Result.Column = Row.Column;\r
+  Result.Discriminator = Row.Discriminator;\r
+  Result.Source = getSourceByIndex(Row.File, Kind);\r
+  return true;\r
+}\r
+\r
+// We want to supply the Unit associated with a .debug_line[.dwo] table when\r
+// we dump it, if possible, but still dump the table even if there isn't a Unit.\r
+// Therefore, collect up handles on all the Units that point into the\r
+// line-table section.\r
+static DWARFDebugLine::SectionParser::LineToUnitMap\r
+buildLineToUnitMap(DWARFDebugLine::SectionParser::cu_range CUs,\r
+                   DWARFDebugLine::SectionParser::tu_range TUs) {\r
+  DWARFDebugLine::SectionParser::LineToUnitMap LineToUnit;\r
+  for (const auto &CU : CUs)\r
+    if (auto CUDIE = CU->getUnitDIE())\r
+      if (auto StmtOffset = toSectionOffset(CUDIE.find(DW_AT_stmt_list)))\r
+        LineToUnit.insert(std::make_pair(*StmtOffset, &*CU));\r
+  for (const auto &TU : TUs)\r
+    if (auto TUDIE = TU->getUnitDIE())\r
+      if (auto StmtOffset = toSectionOffset(TUDIE.find(DW_AT_stmt_list)))\r
+        LineToUnit.insert(std::make_pair(*StmtOffset, &*TU));\r
+  return LineToUnit;\r
+}\r
+\r
+DWARFDebugLine::SectionParser::SectionParser(DWARFDataExtractor &Data,\r
+                                             const DWARFContext &C,\r
+                                             cu_range CUs, tu_range TUs)\r
+    : DebugLineData(Data), Context(C) {\r
+  LineToUnit = buildLineToUnitMap(CUs, TUs);\r
+  if (!DebugLineData.isValidOffset(Offset))\r
+    Done = true;\r
+}\r
+\r
+bool DWARFDebugLine::Prologue::totalLengthIsValid() const {\r
+  return TotalLength == dwarf::DW_LENGTH_DWARF64 ||\r
+         TotalLength < dwarf::DW_LENGTH_lo_reserved;\r
+}\r
+\r
+DWARFDebugLine::LineTable DWARFDebugLine::SectionParser::parseNext(\r
+    function_ref<void(Error)> RecoverableErrorCallback,\r
+    function_ref<void(Error)> UnrecoverableErrorCallback, raw_ostream *OS) {\r
+  assert(DebugLineData.isValidOffset(Offset) &&\r
+         "parsing should have terminated");\r
+  DWARFUnit *U = prepareToParse(Offset);\r
+  uint64_t OldOffset = Offset;\r
+  LineTable LT;\r
+  if (Error Err = LT.parse(DebugLineData, &Offset, Context, U,\r
+                           RecoverableErrorCallback, OS))\r
+    UnrecoverableErrorCallback(std::move(Err));\r
+  moveToNextTable(OldOffset, LT.Prologue);\r
+  return LT;\r
+}\r
+\r
+void DWARFDebugLine::SectionParser::skip(\r
+    function_ref<void(Error)> ErrorCallback) {\r
+  assert(DebugLineData.isValidOffset(Offset) &&\r
+         "parsing should have terminated");\r
+  DWARFUnit *U = prepareToParse(Offset);\r
+  uint64_t OldOffset = Offset;\r
+  LineTable LT;\r
+  if (Error Err = LT.Prologue.parse(DebugLineData, &Offset, Context, U))\r
+    ErrorCallback(std::move(Err));\r
+  moveToNextTable(OldOffset, LT.Prologue);\r
+}\r
+\r
+DWARFUnit *DWARFDebugLine::SectionParser::prepareToParse(uint64_t Offset) {\r
+  DWARFUnit *U = nullptr;\r
+  auto It = LineToUnit.find(Offset);\r
+  if (It != LineToUnit.end())\r
+    U = It->second;\r
+  DebugLineData.setAddressSize(U ? U->getAddressByteSize() : 0);\r
+  return U;\r
+}\r
+\r
+void DWARFDebugLine::SectionParser::moveToNextTable(uint64_t OldOffset,\r
+                                                    const Prologue &P) {\r
+  // If the length field is not valid, we don't know where the next table is, so\r
+  // cannot continue to parse. Mark the parser as done, and leave the Offset\r
+  // value as it currently is. This will be the end of the bad length field.\r
+  if (!P.totalLengthIsValid()) {\r
+    Done = true;\r
+    return;\r
+  }\r
+\r
+  Offset = OldOffset + P.TotalLength + P.sizeofTotalLength();\r
+  if (!DebugLineData.isValidOffset(Offset)) {\r
+    Done = true;\r
+  }\r
+}\r