<div dir="ltr">Also I'm not sure we closed out some of the discussions in review:<br><br>I still find it a bit odd/surprising taht this prints a header for the pre-standard DWARFv4 debug_addr section printing, when that section doesn't have a header.<br><br>Also the [] around the list of addresses (and the "Addrs:" prefix) seem a bit weird compared to the way other lists are dumped in llvm-dwarfdump (don't generally have wrappers or headers beyond the contribution header, potentially (if there is one)) <br><br>For example debug_ranges (OK, admittedly its curretn output could have some improvements) just prints pairs and then "<End of list>" - rather than separate chunks, because debug_ranges (old/v4 version) doesn't have separators between chunks of the list. Printing debug_addr (pre-v5) in a similar way, maybe with some improvements, would probably be nice.<br><br>Also, what's the verbose output mean? I don't quite understand the two addresses printed on each line ("X => Y") - could you explain it?<br><br><div class="gmail_quote"><div dir="ltr">On Tue, Jul 31, 2018 at 3:19 PM Victor Leschuk via llvm-commits <<a href="mailto:llvm-commits@lists.llvm.org">llvm-commits@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: vleschuk<br>
Date: Tue Jul 31 15:19:19 2018<br>
New Revision: 338447<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=338447&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project?rev=338447&view=rev</a><br>
Log:<br>
[DWARF] Support for .debug_addr (consumer)<br>
<br>
  This patch implements basic support for parsing<br>
  and dumping DWARFv5 .debug_addr section.<br>
<br>
<br>
Added:<br>
    llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFDebugAddr.h<br>
    llvm/trunk/lib/DebugInfo/DWARF/DWARFDebugAddr.cpp<br>
    llvm/trunk/test/tools/llvm-dwarfdump/X86/debug_addr.s<br>
    llvm/trunk/test/tools/llvm-dwarfdump/X86/debug_addr_64bit_address.s<br>
    llvm/trunk/test/tools/llvm-dwarfdump/X86/debug_addr_absent.s<br>
    llvm/trunk/test/tools/llvm-dwarfdump/X86/debug_addr_address_size_mismatch.s<br>
    llvm/trunk/test/tools/llvm-dwarfdump/X86/debug_addr_address_size_not_multiple.s<br>
    llvm/trunk/test/tools/llvm-dwarfdump/X86/debug_addr_dwarf4.s<br>
    llvm/trunk/test/tools/llvm-dwarfdump/X86/debug_addr_dwarf64.s<br>
    llvm/trunk/test/tools/llvm-dwarfdump/X86/debug_addr_empty.s<br>
    llvm/trunk/test/tools/llvm-dwarfdump/X86/debug_addr_invalid_addr_size.s<br>
    llvm/trunk/test/tools/llvm-dwarfdump/X86/debug_addr_segment_selector.s<br>
    llvm/trunk/test/tools/llvm-dwarfdump/X86/debug_addr_small_length_field.s<br>
    llvm/trunk/test/tools/llvm-dwarfdump/X86/debug_addr_too_small_for_length_field.s<br>
    llvm/trunk/test/tools/llvm-dwarfdump/X86/debug_addr_too_small_for_section.s<br>
    llvm/trunk/test/tools/llvm-dwarfdump/X86/debug_addr_unsupported_version.s<br>
    llvm/trunk/test/tools/llvm-dwarfdump/X86/debug_addr_version_mismatch.s<br>
Modified:<br>
    llvm/trunk/include/llvm/BinaryFormat/Dwarf.def<br>
    llvm/trunk/include/llvm/DebugInfo/DIContext.h<br>
    llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFContext.h<br>
    llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFDataExtractor.h<br>
    llvm/trunk/lib/DebugInfo/DWARF/CMakeLists.txt<br>
    llvm/trunk/lib/DebugInfo/DWARF/DWARFContext.cpp<br>
<br>
Modified: llvm/trunk/include/llvm/BinaryFormat/Dwarf.def<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/BinaryFormat/Dwarf.def?rev=338447&r1=338446&r2=338447&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/BinaryFormat/Dwarf.def?rev=338447&r1=338446&r2=338447&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/include/llvm/BinaryFormat/Dwarf.def (original)<br>
+++ llvm/trunk/include/llvm/BinaryFormat/Dwarf.def Tue Jul 31 15:19:19 2018<br>
@@ -856,6 +856,7 @@ HANDLE_DW_UT(0x06, split_type)<br>
 // TODO: Add Mach-O and COFF names.<br>
 // Official DWARF sections.<br>
 HANDLE_DWARF_SECTION(DebugAbbrev, ".debug_abbrev", "debug-abbrev")<br>
+HANDLE_DWARF_SECTION(DebugAddr, ".debug_addr", "debug-addr")<br>
 HANDLE_DWARF_SECTION(DebugAranges, ".debug_aranges", "debug-aranges")<br>
 HANDLE_DWARF_SECTION(DebugInfo, ".debug_info", "debug-info")<br>
 HANDLE_DWARF_SECTION(DebugTypes, ".debug_types", "debug-types")<br>
<br>
Modified: llvm/trunk/include/llvm/DebugInfo/DIContext.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/DebugInfo/DIContext.h?rev=338447&r1=338446&r2=338447&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/DebugInfo/DIContext.h?rev=338447&r1=338446&r2=338447&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/include/llvm/DebugInfo/DIContext.h (original)<br>
+++ llvm/trunk/include/llvm/DebugInfo/DIContext.h Tue Jul 31 15:19:19 2018<br>
@@ -154,6 +154,8 @@ enum DIDumpType : unsigned {<br>
 struct DIDumpOptions {<br>
   unsigned DumpType = DIDT_All;<br>
   unsigned RecurseDepth = -1U;<br>
+  uint16_t Version = 0; // DWARF version to assume when extracting.<br>
+  uint8_t AddrSize = 4; // Address byte size to assume when extracting.<br>
   bool ShowAddresses = true;<br>
   bool ShowChildren = false;<br>
   bool ShowParents = false;<br>
<br>
Modified: llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFContext.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFContext.h?rev=338447&r1=338446&r2=338447&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFContext.h?rev=338447&r1=338446&r2=338447&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFContext.h (original)<br>
+++ llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFContext.h Tue Jul 31 15:19:19 2018<br>
@@ -323,6 +323,10 @@ public:<br>
   /// have initialized the relevant target descriptions.<br>
   Error loadRegisterInfo(const object::ObjectFile &Obj);<br>
<br>
+  /// Get address size from CUs.<br>
+  /// TODO: refactor compile_units() to make this const.<br>
+  uint8_t getCUAddrSize();<br>
+<br>
 private:<br>
   /// Return the compile unit which contains instruction with provided<br>
   /// address.<br>
<br>
Modified: llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFDataExtractor.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFDataExtractor.h?rev=338447&r1=338446&r2=338447&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFDataExtractor.h?rev=338447&r1=338446&r2=338447&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFDataExtractor.h (original)<br>
+++ llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFDataExtractor.h Tue Jul 31 15:19:19 2018<br>
@@ -51,6 +51,8 @@ public:<br>
   /// reflect the absolute address of this pointer.<br>
   Optional<uint64_t> getEncodedPointer(uint32_t *Offset, uint8_t Encoding,<br>
                                        uint64_t AbsPosOffset = 0) const;<br>
+<br>
+  size_t size() const { return Section == nullptr ? 0 : Section->Data.size(); }<br>
 };<br>
<br>
 } // end namespace llvm<br>
<br>
Added: llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFDebugAddr.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFDebugAddr.h?rev=338447&view=auto" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFDebugAddr.h?rev=338447&view=auto</a><br>
==============================================================================<br>
--- llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFDebugAddr.h (added)<br>
+++ llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFDebugAddr.h Tue Jul 31 15:19:19 2018<br>
@@ -0,0 +1,98 @@<br>
+//===- DWARFDebugAddr.h -------------------------------------*- C++ -*-===//<br>
+//<br>
+//                     The LLVM Compiler Infrastructure<br>
+//<br>
+// This file is distributed under the University of Illinois Open Source<br>
+// License. See LICENSE.TXT for details.<br>
+//<br>
+//===------------------------------------------------------------------===//<br>
+<br>
+#ifndef LLVM_DEBUGINFO_DWARFDEBUGADDR_H<br>
+#define LLVM_DEBUGINFO_DWARFDEBUGADDR_H<br>
+<br>
+#include "llvm/BinaryFormat/Dwarf.h"<br>
+#include "llvm/DebugInfo/DIContext.h"<br>
+#include "llvm/DebugInfo/DWARF/DWARFDataExtractor.h"<br>
+#include "llvm/Support/Errc.h"<br>
+#include "llvm/Support/Error.h"<br>
+#include <cstdint><br>
+#include <map><br>
+#include <vector><br>
+<br>
+namespace llvm {<br>
+<br>
+class Error;<br>
+class raw_ostream;<br>
+<br>
+/// A class representing an address table as specified in DWARF v5.<br>
+/// The table consists of a header followed by an array of address values from<br>
+/// .debug_addr section.<br>
+class DWARFDebugAddrTable {<br>
+public:<br>
+  struct Header {<br>
+    /// The total length of the entries for this table, not including the length<br>
+    /// field itself.<br>
+    uint32_t Length = 0;<br>
+    /// The DWARF version number.<br>
+    uint16_t Version = 5;<br>
+    /// The size in bytes of an address on the target architecture. For<br>
+    /// segmented addressing, this is the size of the offset portion of the<br>
+    /// address.<br>
+    uint8_t AddrSize;<br>
+    /// The size in bytes of a segment selector on the target architecture.<br>
+    /// If the target system uses a flat address space, this value is 0.<br>
+    uint8_t SegSize = 0;<br>
+  };<br>
+<br>
+private:<br>
+  dwarf::DwarfFormat Format;<br>
+  uint32_t HeaderOffset;<br>
+  Header HeaderData;<br>
+  uint32_t DataSize = 0;<br>
+  std::vector<uint64_t> Addrs;<br>
+<br>
+public:<br>
+  void clear();<br>
+<br>
+  /// Extract an entire table, including all addresses.<br>
+  Error extract(DWARFDataExtractor Data, uint32_t *OffsetPtr,<br>
+                uint16_t Version, uint8_t AddrSize,<br>
+                std::function<void(Error)> WarnCallback);<br>
+<br>
+  uint32_t getHeaderOffset() const { return HeaderOffset; }<br>
+  uint8_t getAddrSize() const { return HeaderData.AddrSize; }<br>
+  void dump(raw_ostream &OS, DIDumpOptions DumpOpts = {}) const;<br>
+<br>
+  /// Return the address based on a given index.<br>
+  Expected<uint64_t> getAddrEntry(uint32_t Index) const;<br>
+<br>
+  /// Return the size of the table header including the length<br>
+  /// but not including the addresses.<br>
+  uint8_t getHeaderSize() const {<br>
+    switch (Format) {<br>
+    case dwarf::DwarfFormat::DWARF32:<br>
+      return 8; // 4 + 2 + 1 + 1<br>
+    case dwarf::DwarfFormat::DWARF64:<br>
+      return 16; // 12 + 2 + 1 + 1<br>
+    }<br>
+    llvm_unreachable("Invalid DWARF format (expected DWARF32 or DWARF64)");<br>
+  }<br>
+<br>
+  /// Returns the length of this table, including the length field, or 0 if the<br>
+  /// length has not been determined (e.g. because the table has not yet been<br>
+  /// parsed, or there was a problem in parsing).<br>
+  uint32_t getLength() const;<br>
+<br>
+  /// Verify that the given length is valid for this table.<br>
+  bool hasValidLength() const { return getLength() != 0; }<br>
+<br>
+  /// Invalidate Length field to stop further processing.<br>
+  void invalidateLength() { HeaderData.Length = 0; }<br>
+<br>
+  /// Returns the length of the array of addresses.<br>
+  uint32_t getDataSize() const;<br>
+};<br>
+<br>
+} // end namespace llvm<br>
+<br>
+#endif // LLVM_DEBUGINFO_DWARFDEBUGADDR_H<br>
<br>
Modified: llvm/trunk/lib/DebugInfo/DWARF/CMakeLists.txt<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/DWARF/CMakeLists.txt?rev=338447&r1=338446&r2=338447&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/DWARF/CMakeLists.txt?rev=338447&r1=338446&r2=338447&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/lib/DebugInfo/DWARF/CMakeLists.txt (original)<br>
+++ llvm/trunk/lib/DebugInfo/DWARF/CMakeLists.txt Tue Jul 31 15:19:19 2018<br>
@@ -6,6 +6,7 @@ add_llvm_library(LLVMDebugInfoDWARF<br>
   DWARFContext.cpp<br>
   DWARFDataExtractor.cpp<br>
   DWARFDebugAbbrev.cpp<br>
+  DWARFDebugAddr.cpp<br>
   DWARFDebugArangeSet.cpp<br>
   DWARFDebugAranges.cpp<br>
   DWARFDebugFrame.cpp<br>
<br>
Modified: llvm/trunk/lib/DebugInfo/DWARF/DWARFContext.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/DWARF/DWARFContext.cpp?rev=338447&r1=338446&r2=338447&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/DWARF/DWARFContext.cpp?rev=338447&r1=338446&r2=338447&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/lib/DebugInfo/DWARF/DWARFContext.cpp (original)<br>
+++ llvm/trunk/lib/DebugInfo/DWARF/DWARFContext.cpp Tue Jul 31 15:19:19 2018<br>
@@ -17,6 +17,7 @@<br>
 #include "llvm/DebugInfo/DWARF/DWARFAcceleratorTable.h"<br>
 #include "llvm/DebugInfo/DWARF/DWARFCompileUnit.h"<br>
 #include "llvm/DebugInfo/DWARF/DWARFDebugAbbrev.h"<br>
+#include "llvm/DebugInfo/DWARF/DWARFDebugAddr.h"<br>
 #include "llvm/DebugInfo/DWARF/DWARFDebugArangeSet.h"<br>
 #include "llvm/DebugInfo/DWARF/DWARFDebugAranges.h"<br>
 #include "llvm/DebugInfo/DWARF/DWARFDebugFrame.h"<br>
@@ -249,6 +250,36 @@ static void dumpStringOffsetsSection(<br>
   }<br>
 }<br>
<br>
+// Dump the .debug_addr section.<br>
+static void dumpAddrSection(raw_ostream &OS, DWARFDataExtractor &AddrData,<br>
+                            DIDumpOptions DumpOpts, uint16_t Version,<br>
+                            uint8_t AddrSize) {<br>
+  // TODO: Make this more general: add callback types to Error.h, create<br>
+  // implementation and make all DWARF classes use them.<br>
+  static auto WarnCallback = [](Error Warn) {<br>
+    handleAllErrors(std::move(Warn), [](ErrorInfoBase &Info) {<br>
+      WithColor::warning() << Info.message() << '\n';<br>
+    });<br>
+  };<br>
+  uint32_t Offset = 0;<br>
+  while (AddrData.isValidOffset(Offset)) {<br>
+    DWARFDebugAddrTable AddrTable;<br>
+    uint32_t TableOffset = Offset;<br>
+    if (Error Err = AddrTable.extract(AddrData, &Offset, Version,<br>
+                                      AddrSize, WarnCallback)) {<br>
+      WithColor::error() << toString(std::move(Err)) << '\n';<br>
+      // Keep going after an error, if we can, assuming that the length field<br>
+      // could be read. If it couldn't, stop reading the section.<br>
+      if (!AddrTable.hasValidLength())<br>
+        break;<br>
+      uint64_t Length = AddrTable.getLength();<br>
+      Offset = TableOffset + Length;<br>
+    } else {<br>
+      AddrTable.dump(OS, DumpOpts);<br>
+    }<br>
+  }<br>
+}<br>
+<br>
 // Dump the .debug_rnglists or .debug_rnglists.dwo section (DWARF v5).<br>
 static void dumpRnglistsSection(raw_ostream &OS,<br>
                                 DWARFDataExtractor &rnglistData,<br>
@@ -455,18 +486,16 @@ void DWARFContext::dump(<br>
     }<br>
   }<br>
<br>
+  if (shouldDump(Explicit, ".debug_addr", DIDT_ID_DebugAddr,<br>
+                 DObj->getAddrSection().Data)) {<br>
+    DWARFDataExtractor AddrData(*DObj, DObj->getAddrSection(),<br>
+                                   isLittleEndian(), 0);<br>
+    dumpAddrSection(OS, AddrData, DumpOpts, getMaxVersion(), getCUAddrSize());<br>
+  }<br>
+<br>
   if (shouldDump(Explicit, ".debug_ranges", DIDT_ID_DebugRanges,<br>
                  DObj->getRangeSection().Data)) {<br>
-    // In fact, different compile units may have different address byte<br>
-    // sizes, but for simplicity we just use the address byte size of the<br>
-    // last compile unit (there is no easy and fast way to associate address<br>
-    // range list and the compile unit it describes).<br>
-    // FIXME: savedAddressByteSize seems sketchy.<br>
-    uint8_t savedAddressByteSize = 0;<br>
-    for (const auto &CU : compile_units()) {<br>
-      savedAddressByteSize = CU->getAddressByteSize();<br>
-      break;<br>
-    }<br>
+    uint8_t savedAddressByteSize = getCUAddrSize();<br>
     DWARFDataExtractor rangesData(*DObj, DObj->getRangeSection(),<br>
                                   isLittleEndian(), savedAddressByteSize);<br>
     uint32_t offset = 0;<br>
@@ -1584,3 +1613,17 @@ Error DWARFContext::loadRegisterInfo(con<br>
   RegInfo.reset(TheTarget->createMCRegInfo(TT.str()));<br>
   return Error::success();<br>
 }<br>
+<br>
+uint8_t DWARFContext::getCUAddrSize() {<br>
+  // In theory, different compile units may have different address byte<br>
+  // sizes, but for simplicity we just use the address byte size of the<br>
+  // last compile unit. In practice the address size field is repeated across<br>
+  // various DWARF headers (at least in version 5) to make it easier to dump<br>
+  // them independently, not to enable varying the address size.<br>
+  uint8_t Addr = 0;<br>
+  for (const auto &CU : compile_units()) {<br>
+    Addr = CU->getAddressByteSize();<br>
+    break;<br>
+  }<br>
+  return Addr;<br>
+}<br>
<br>
Added: llvm/trunk/lib/DebugInfo/DWARF/DWARFDebugAddr.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/DWARF/DWARFDebugAddr.cpp?rev=338447&view=auto" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/DWARF/DWARFDebugAddr.cpp?rev=338447&view=auto</a><br>
==============================================================================<br>
--- llvm/trunk/lib/DebugInfo/DWARF/DWARFDebugAddr.cpp (added)<br>
+++ llvm/trunk/lib/DebugInfo/DWARF/DWARFDebugAddr.cpp Tue Jul 31 15:19:19 2018<br>
@@ -0,0 +1,198 @@<br>
+//===- DWARFDebugAddr.cpp -------------------------------------------------===//<br>
+//<br>
+//                     The LLVM Compiler Infrastructure<br>
+//<br>
+// This file is distributed under the University of Illinois Open Source<br>
+// License. See LICENSE.TXT for details.<br>
+//<br>
+//===----------------------------------------------------------------------===//<br>
+<br>
+#include "llvm/DebugInfo/DWARF/DWARFDebugAddr.h"<br>
+#include "llvm/BinaryFormat/Dwarf.h"<br>
+#include "llvm/DebugInfo/DWARF/DWARFUnit.h"<br>
+<br>
+using namespace llvm;<br>
+<br>
+void DWARFDebugAddrTable::clear() {<br>
+  HeaderData = {};<br>
+  Addrs.clear();<br>
+  invalidateLength();<br>
+}<br>
+<br>
+Error DWARFDebugAddrTable::extract(DWARFDataExtractor Data,<br>
+                                   uint32_t *OffsetPtr,<br>
+                                   uint16_t Version,<br>
+                                   uint8_t AddrSize,<br>
+                                   std::function<void(Error)> WarnCallback) {<br>
+  clear();<br>
+  HeaderOffset = *OffsetPtr;<br>
+  // Read and verify the length field.<br>
+  if (!Data.isValidOffsetForDataOfSize(*OffsetPtr, sizeof(uint32_t)))<br>
+    return createStringError(errc::invalid_argument,<br>
+                       "section is not large enough to contain a "<br>
+                       ".debug_addr table length at offset 0x%"<br>
+                       PRIx32, *OffsetPtr);<br>
+  uint16_t UnitVersion;<br>
+  if (Version == 0) {<br>
+    WarnCallback(createStringError(errc::invalid_argument,<br>
+                       "DWARF version is not defined in CU,"<br>
+                       " assuming version 5"));<br>
+    UnitVersion = 5;<br>
+  } else {<br>
+    UnitVersion = Version;<br>
+  }<br>
+  // TODO: Add support for DWARF64.<br>
+  Format = dwarf::DwarfFormat::DWARF32;<br>
+  if (UnitVersion >= 5) {<br>
+    HeaderData.Length = Data.getU32(OffsetPtr);<br>
+    if (HeaderData.Length == 0xffffffffu) {<br>
+      invalidateLength();<br>
+      return createStringError(errc::not_supported,<br>
+          "DWARF64 is not supported in .debug_addr at offset 0x%" PRIx32,<br>
+          HeaderOffset);<br>
+    }<br>
+    if (HeaderData.Length + sizeof(uint32_t) < sizeof(Header)) {<br>
+      uint32_t TmpLength = getLength();<br>
+      invalidateLength();<br>
+      return createStringError(errc::invalid_argument,<br>
+                         ".debug_addr table at offset 0x%" PRIx32<br>
+                         " has too small length (0x%" PRIx32<br>
+                         ") to contain a complete header",<br>
+                         HeaderOffset, TmpLength);<br>
+    }<br>
+    uint32_t End = HeaderOffset + getLength();<br>
+    if (!Data.isValidOffsetForDataOfSize(HeaderOffset, End - HeaderOffset)) {<br>
+      uint32_t TmpLength = getLength();<br>
+      invalidateLength();<br>
+      return createStringError(errc::invalid_argument,<br>
+          "section is not large enough to contain a .debug_addr table "<br>
+          "of length 0x%" PRIx32 " at offset 0x%" PRIx32,<br>
+          TmpLength, HeaderOffset);<br>
+    }<br>
+<br>
+    HeaderData.Version = Data.getU16(OffsetPtr);<br>
+    HeaderData.AddrSize = Data.getU8(OffsetPtr);<br>
+    HeaderData.SegSize = Data.getU8(OffsetPtr);<br>
+    DataSize = getDataSize();<br>
+  } else {<br>
+    HeaderData.Version = UnitVersion;<br>
+    HeaderData.AddrSize = AddrSize;<br>
+    // TODO: Support for non-zero SegSize.<br>
+    HeaderData.SegSize = 0;<br>
+    DataSize = Data.size();<br>
+  }<br>
+<br>
+  // Perform basic validation of the remaining header fields.<br>
+<br>
+  // We support DWARF version 5 for now as well as pre-DWARF5<br>
+  // implementations of .debug_addr table, which doesn't contain a header<br>
+  // and consists only of a series of addresses.<br>
+  if (HeaderData.Version > 5) {<br>
+    return createStringError(errc::not_supported, "version %" PRIu16<br>
+        " of .debug_addr section at offset 0x%" PRIx32 " is not supported",<br>
+        HeaderData.Version, HeaderOffset);<br>
+  }<br>
+  // FIXME: For now we just treat version mismatch as an error,<br>
+  // however the correct way to associate a .debug_addr table<br>
+  // with a .debug_info table is to look at the DW_AT_addr_base<br>
+  // attribute in the info table.<br>
+  if (HeaderData.Version != UnitVersion)<br>
+    return createStringError(errc::invalid_argument,<br>
+                       ".debug_addr table at offset 0x%" PRIx32<br>
+                       " has version %" PRIu16<br>
+                       " which is different from the version suggested"<br>
+                       " by the DWARF unit header: %" PRIu16,<br>
+                       HeaderOffset, HeaderData.Version, UnitVersion);<br>
+  if (HeaderData.AddrSize != 4 && HeaderData.AddrSize != 8)<br>
+    return createStringError(errc::not_supported,<br>
+                       ".debug_addr table at offset 0x%" PRIx32<br>
+                       " has unsupported address size %" PRIu8,<br>
+                       HeaderOffset, HeaderData.AddrSize);<br>
+  if (HeaderData.AddrSize != AddrSize && AddrSize != 0)<br>
+    return createStringError(errc::invalid_argument,<br>
+                       ".debug_addr table at offset 0x%" PRIx32<br>
+                       " has address size %" PRIu8<br>
+                       " which is different from CU address size %" PRIu8,<br>
+                       HeaderOffset, HeaderData.AddrSize, AddrSize);<br>
+<br>
+  // TODO: add support for non-zero segment selector size.<br>
+  if (HeaderData.SegSize != 0)<br>
+    return createStringError(errc::not_supported,<br>
+                       ".debug_addr table at offset 0x%" PRIx32<br>
+                       " has unsupported segment selector size %" PRIu8,<br>
+                       HeaderOffset, HeaderData.SegSize);<br>
+  if (DataSize % HeaderData.AddrSize != 0) {<br>
+    invalidateLength();<br>
+    return createStringError(errc::invalid_argument,<br>
+                       ".debug_addr table at offset 0x%" PRIx32<br>
+                       " contains data of size %" PRIu32<br>
+                       " which is not a multiple of addr size %" PRIu8,<br>
+                       HeaderOffset, DataSize, HeaderData.AddrSize);<br>
+  }<br>
+  Data.setAddressSize(HeaderData.AddrSize);<br>
+  uint32_t AddrCount = DataSize / HeaderData.AddrSize;<br>
+  for (uint32_t I = 0; I < AddrCount; ++I)<br>
+    if (HeaderData.AddrSize == 4)<br>
+      Addrs.push_back(Data.getU32(OffsetPtr));<br>
+    else<br>
+      Addrs.push_back(Data.getU64(OffsetPtr));<br>
+  return Error::success();<br>
+}<br>
+<br>
+void DWARFDebugAddrTable::dump(raw_ostream &OS, DIDumpOptions DumpOpts) const {<br>
+  if (DumpOpts.Verbose)<br>
+    OS << format("0x%8.8" PRIx32 ": ", HeaderOffset);<br>
+  OS << format("Addr Section: length = 0x%8.8" PRIx32<br>
+               ", version = 0x%4.4" PRIx16 ", "<br>
+               "addr_size = 0x%2.2" PRIx8 ", seg_size = 0x%2.2" PRIx8 "\n",<br>
+               HeaderData.Length, HeaderData.Version, HeaderData.AddrSize,<br>
+               HeaderData.SegSize);<br>
+<br>
+  static const char *Fmt32 = "0x%8.8" PRIx32;<br>
+  static const char *Fmt64 = "0x%16.16" PRIx64;<br>
+  std::string AddrFmt = "\n";<br>
+  std::string AddrFmtVerbose = " => ";<br>
+  if (HeaderData.AddrSize == 4) {<br>
+    AddrFmt.append(Fmt32);<br>
+    AddrFmtVerbose.append(Fmt32);<br>
+  }<br>
+  else {<br>
+    AddrFmt.append(Fmt64);<br>
+    AddrFmtVerbose.append(Fmt64);<br>
+  }<br>
+<br>
+  if (Addrs.size() > 0) {<br>
+    OS << "Addrs: [";<br>
+    for (uint64_t Addr : Addrs) {<br>
+      OS << format(AddrFmt.c_str(), Addr);<br>
+      if (DumpOpts.Verbose)<br>
+        OS << format(AddrFmtVerbose.c_str(),<br>
+                     Addr + HeaderOffset + sizeof(HeaderData));<br>
+    }<br>
+    OS << "\n]\n";<br>
+  }<br>
+}<br>
+<br>
+Expected<uint64_t> DWARFDebugAddrTable::getAddrEntry(uint32_t Index) const {<br>
+  if (Index < Addrs.size())<br>
+    return Addrs[Index];<br>
+  return createStringError(errc::invalid_argument,<br>
+                           "Index %" PRIu32 " is out of range of the "<br>
+                           ".debug_addr table at offset 0x%" PRIx32,<br>
+                           Index, HeaderOffset);<br>
+}<br>
+<br>
+uint32_t DWARFDebugAddrTable::getLength() const {<br>
+  if (HeaderData.Length == 0)<br>
+    return 0;<br>
+  // TODO: DWARF64 support.<br>
+  return HeaderData.Length + sizeof(uint32_t);<br>
+}<br>
+<br>
+uint32_t DWARFDebugAddrTable::getDataSize() const {<br>
+  if (DataSize != 0)<br>
+    return DataSize;<br>
+  if (getLength() == 0)<br>
+    return 0;<br>
+  return getLength() - getHeaderSize();<br>
+}<br>
<br>
Added: llvm/trunk/test/tools/llvm-dwarfdump/X86/debug_addr.s<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-dwarfdump/X86/debug_addr.s?rev=338447&view=auto" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-dwarfdump/X86/debug_addr.s?rev=338447&view=auto</a><br>
==============================================================================<br>
--- llvm/trunk/test/tools/llvm-dwarfdump/X86/debug_addr.s (added)<br>
+++ llvm/trunk/test/tools/llvm-dwarfdump/X86/debug_addr.s Tue Jul 31 15:19:19 2018<br>
@@ -0,0 +1,38 @@<br>
+# RUN: llvm-mc %s -filetype obj -triple i386-pc-linux -o %t.o<br>
+# RUN: llvm-dwarfdump -debug-addr %t.o | FileCheck %s<br>
+<br>
+# CHECK:          .debug_addr contents<br>
+<br>
+# CHECK-NEXT:     length = 0x0000000c, version = 0x0005, addr_size = 0x04, seg_size = 0x00<br>
+# CHECK-NEXT:     Addrs: [<br>
+# CHECK-NEXT:     0x00000000<br>
+# CHECK-NEXT:     0x00000001<br>
+# CHECK-NEXT:     ]<br>
+# CHECK-NEXT:     length = 0x00000004, version = 0x0005, addr_size = 0x04, seg_size = 0x00<br>
+# CHECK-NOT:      {{.}}<br>
+<br>
+       .section        .debug_abbrev,"",@progbits<br>
+       .byte   1                       # Abbreviation Code<br>
+       .section        .debug_info,"",@progbits<br>
+.Lcu_begin0:<br>
+       .long 8                       # Length of Unit<br>
+       .short  5                     # DWARF version number<br>
+  .byte 1                       # DWARF unit type<br>
+       .byte   4                       # Address Size (in bytes)<br>
+       .long   .debug_abbrev           # Offset Into Abbrev. Section<br>
+<br>
+  .section  .debug_addr,"",@progbits<br>
+.Ldebug_addr0:<br>
+  .long 12 # unit_length = .short + .byte + .byte + .long + .long<br>
+  .short 5 # version<br>
+  .byte 4  # address_size<br>
+  .byte 0  # segment_selector_size<br>
+  .long 0x00000000<br>
+  .long 0x00000001<br>
+<br>
+  .section  .debug_addr,"",@progbits<br>
+.Ldebug_addr1:<br>
+  .long 4  # unit_length = .short + .byte + .byte<br>
+  .short 5 # version<br>
+  .byte 4  # address_size<br>
+  .byte 0  # segment_selector_size<br>
<br>
Added: llvm/trunk/test/tools/llvm-dwarfdump/X86/debug_addr_64bit_address.s<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-dwarfdump/X86/debug_addr_64bit_address.s?rev=338447&view=auto" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-dwarfdump/X86/debug_addr_64bit_address.s?rev=338447&view=auto</a><br>
==============================================================================<br>
--- llvm/trunk/test/tools/llvm-dwarfdump/X86/debug_addr_64bit_address.s (added)<br>
+++ llvm/trunk/test/tools/llvm-dwarfdump/X86/debug_addr_64bit_address.s Tue Jul 31 15:19:19 2018<br>
@@ -0,0 +1,29 @@<br>
+# RUN: llvm-mc %s -filetype obj -triple x86_64-pc-linux -o %t.o<br>
+# RUN: llvm-dwarfdump -debug-addr %t.o | FileCheck %s<br>
+<br>
+# CHECK:          .debug_addr contents<br>
+# CHECK-NEXT:     length = 0x00000014, version = 0x0005, addr_size = 0x08, seg_size = 0x00<br>
+# CHECK-NEXT:     Addrs: [<br>
+# CHECK-NEXT:     0x0000000100000000<br>
+# CHECK-NEXT:     0x0000000100000001<br>
+# CHECK-NEXT:     ]<br>
+# CHECK-NOT:      {{.}}<br>
+<br>
+       .section        .debug_abbrev,"",@progbits<br>
+       .byte   1                       # Abbreviation Code<br>
+       .section        .debug_info,"",@progbits<br>
+.Lcu_begin0:<br>
+       .long 8                       # Length of Unit<br>
+       .short  5                     # DWARF version number<br>
+  .byte 1                       # DWARF unit type<br>
+       .byte   8                       # Address Size (in bytes)<br>
+       .long   .debug_abbrev           # Offset Into Abbrev. Section<br>
+<br>
+  .section  .debug_addr,"",@progbits<br>
+.Ldebug_addr0:<br>
+  .long 20 # unit_length = .short + .byte + .byte + .quad + .quad<br>
+  .short 5 # version<br>
+  .byte 8  # address_size<br>
+  .byte 0  # segment_selector_size<br>
+  .quad 0x0000000100000000<br>
+  .quad 0x0000000100000001<br>
<br>
Added: llvm/trunk/test/tools/llvm-dwarfdump/X86/debug_addr_absent.s<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-dwarfdump/X86/debug_addr_absent.s?rev=338447&view=auto" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-dwarfdump/X86/debug_addr_absent.s?rev=338447&view=auto</a><br>
==============================================================================<br>
--- llvm/trunk/test/tools/llvm-dwarfdump/X86/debug_addr_absent.s (added)<br>
+++ llvm/trunk/test/tools/llvm-dwarfdump/X86/debug_addr_absent.s Tue Jul 31 15:19:19 2018<br>
@@ -0,0 +1,4 @@<br>
+# RUN: llvm-mc %s -filetype obj -triple i386-pc-linux -o - | \<br>
+# RUN: llvm-dwarfdump -debug-addr - 2>&1 | FileCheck %s<br>
+# CHECK: .debug_addr contents:<br>
+# CHECK-NOT: {{.}}<br>
<br>
Added: llvm/trunk/test/tools/llvm-dwarfdump/X86/debug_addr_address_size_mismatch.s<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-dwarfdump/X86/debug_addr_address_size_mismatch.s?rev=338447&view=auto" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-dwarfdump/X86/debug_addr_address_size_mismatch.s?rev=338447&view=auto</a><br>
==============================================================================<br>
--- llvm/trunk/test/tools/llvm-dwarfdump/X86/debug_addr_address_size_mismatch.s (added)<br>
+++ llvm/trunk/test/tools/llvm-dwarfdump/X86/debug_addr_address_size_mismatch.s Tue Jul 31 15:19:19 2018<br>
@@ -0,0 +1,42 @@<br>
+# RUN: llvm-mc %s -filetype obj -triple i386-pc-linux -o - | \<br>
+# RUN: llvm-dwarfdump -debug-addr - 2> %t.err | FileCheck %s<br>
+# RUN: FileCheck %s -input-file %t.err -check-prefix=ERR<br>
+<br>
+# ERR: .debug_addr table at offset 0x0 has address size 8 which is different from CU address size 4<br>
+# ERR-NOT: {{.}}<br>
+<br>
+# CHECK: .debug_addr contents<br>
+# CHECK-NEXT:     length = 0x0000000c, version = 0x0005, addr_size = 0x04, seg_size = 0x00<br>
+# CHECK-NEXT:     Addrs: [<br>
+# CHECK-NEXT:     0x00000000<br>
+# CHECK-NEXT:     0x00000001<br>
+# CHECK-NEXT:     ]<br>
+# CHECK-NOT:      {{.}}<br>
+<br>
+       .section        .debug_abbrev,"",@progbits<br>
+       .byte   1                       # Abbreviation Code<br>
+       .section        .debug_info,"",@progbits<br>
+.Lcu_begin0:<br>
+       .long 8                       # Length of Unit<br>
+       .short  5                     # DWARF version number<br>
+  .byte 1                       # DWARF unit type<br>
+       .byte   4                       # Address Size (in bytes)<br>
+       .long   .debug_abbrev           # Offset Into Abbrev. Section<br>
+<br>
+       .section        .debug_addr,"",@progbits<br>
+.Ldebug_addr0:<br>
+  .long 12 # unit_length = .short + .byte + .byte + .long + .long<br>
+  .short 5 # version<br>
+  .byte 8  # address_size<br>
+  .byte 0  # segment_selector_size<br>
+  .long 0x00000000<br>
+  .long 0x00000001<br>
+<br>
+       .section        .debug_addr,"",@progbits<br>
+.Ldebug_addr1:<br>
+  .long 12 # unit_length = .short + .byte + .byte + .long + .long<br>
+  .short 5 # version<br>
+  .byte 4  # address_size<br>
+  .byte 0  # segment_selector_size<br>
+  .long 0x00000000<br>
+  .long 0x00000001<br>
<br>
Added: llvm/trunk/test/tools/llvm-dwarfdump/X86/debug_addr_address_size_not_multiple.s<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-dwarfdump/X86/debug_addr_address_size_not_multiple.s?rev=338447&view=auto" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-dwarfdump/X86/debug_addr_address_size_not_multiple.s?rev=338447&view=auto</a><br>
==============================================================================<br>
--- llvm/trunk/test/tools/llvm-dwarfdump/X86/debug_addr_address_size_not_multiple.s (added)<br>
+++ llvm/trunk/test/tools/llvm-dwarfdump/X86/debug_addr_address_size_not_multiple.s Tue Jul 31 15:19:19 2018<br>
@@ -0,0 +1,18 @@<br>
+# RUN: llvm-mc %s -filetype obj -triple i386-pc-linux -o - | \<br>
+# RUN: llvm-dwarfdump -debug-addr - 2> %t.err | FileCheck %s<br>
+# RUN: FileCheck %s -input-file %t.err -check-prefix=ERR<br>
+<br>
+# CHECK: .debug_addr contents:<br>
+# CHECK-NOT: {{.}}<br>
+# ERR: .debug_addr table at offset 0x0 contains data of size 7 which is not a multiple of addr size 4<br>
+# ERR-NOT: {{.}}<br>
+<br>
+# data size is not multiple of address_size<br>
+  .section  .debug_addr,"",@progbits<br>
+.Ldebug_addr0:<br>
+  .long 11 # unit_length = .short + .byte + .byte + .long + .long - 1<br>
+  .short 5 # version<br>
+  .byte 4  # address_size<br>
+  .byte 0  # segment_selector_size<br>
+  .long 0x00000000<br>
+  .long 0x00000001<br>
<br>
Added: llvm/trunk/test/tools/llvm-dwarfdump/X86/debug_addr_dwarf4.s<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-dwarfdump/X86/debug_addr_dwarf4.s?rev=338447&view=auto" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-dwarfdump/X86/debug_addr_dwarf4.s?rev=338447&view=auto</a><br>
==============================================================================<br>
--- llvm/trunk/test/tools/llvm-dwarfdump/X86/debug_addr_dwarf4.s (added)<br>
+++ llvm/trunk/test/tools/llvm-dwarfdump/X86/debug_addr_dwarf4.s Tue Jul 31 15:19:19 2018<br>
@@ -0,0 +1,20 @@<br>
+# RUN: llvm-mc %s -filetype obj -triple i386-pc-linux -o %t.o<br>
+# RUN: llvm-dwarfdump --debug-addr %t.o | FileCheck %s<br>
+<br>
+# CHECK: .debug_addr contents<br>
+# CHECK-NEXT:     length = 0x00000000, version = 0x0004, addr_size = 0x04, seg_size = 0x00<br>
+# CHECK-NEXT:     Addrs: [<br>
+# CHECK-NEXT:     0x00000000<br>
+# CHECK-NEXT:     0x00000001<br>
+<br>
+       .section        .debug_abbrev,"",@progbits<br>
+       .byte   1                       # Abbreviation Code<br>
+       .section        .debug_info,"",@progbits<br>
+.Lcu_begin0:<br>
+       .long 7                       # Length of Unit<br>
+       .short  4                     # DWARF version number<br>
+       .long   .debug_abbrev           # Offset Into Abbrev. Section<br>
+       .byte   4                       # Address Size (in bytes)<br>
+       .section        .debug_addr,"",@progbits<br>
+  .long 0x00000000<br>
+  .long 0x00000001<br>
<br>
Added: llvm/trunk/test/tools/llvm-dwarfdump/X86/debug_addr_dwarf64.s<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-dwarfdump/X86/debug_addr_dwarf64.s?rev=338447&view=auto" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-dwarfdump/X86/debug_addr_dwarf64.s?rev=338447&view=auto</a><br>
==============================================================================<br>
--- llvm/trunk/test/tools/llvm-dwarfdump/X86/debug_addr_dwarf64.s (added)<br>
+++ llvm/trunk/test/tools/llvm-dwarfdump/X86/debug_addr_dwarf64.s Tue Jul 31 15:19:19 2018<br>
@@ -0,0 +1,19 @@<br>
+# RUN: llvm-mc %s -filetype obj -triple i386-pc-linux -o - | \<br>
+# RUN: llvm-dwarfdump -debug-addr - 2> %t.err | FileCheck %s<br>
+# RUN: FileCheck %s -input-file %t.err -check-prefix=ERR<br>
+<br>
+# CHECK: .debug_addr contents:<br>
+# CHECK-NOT: {{.}}<br>
+# ERR: DWARF64 is not supported in .debug_addr at offset 0x0<br>
+# ERR-NOT: {{.}}<br>
+<br>
+# DWARF64 table<br>
+  .section  .debug_addr,"",@progbits<br>
+.Ldebug_addr0:<br>
+  .long 0xffffffff # unit_length DWARF64 mark<br>
+  .quad 12         # unit_length<br>
+  .short 5         # version<br>
+  .byte 3          # address_size<br>
+  .byte 0          # segment_selector_size<br>
+  .long 0x00000000<br>
+  .long 0x00000001<br>
<br>
Added: llvm/trunk/test/tools/llvm-dwarfdump/X86/debug_addr_empty.s<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-dwarfdump/X86/debug_addr_empty.s?rev=338447&view=auto" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-dwarfdump/X86/debug_addr_empty.s?rev=338447&view=auto</a><br>
==============================================================================<br>
--- llvm/trunk/test/tools/llvm-dwarfdump/X86/debug_addr_empty.s (added)<br>
+++ llvm/trunk/test/tools/llvm-dwarfdump/X86/debug_addr_empty.s Tue Jul 31 15:19:19 2018<br>
@@ -0,0 +1,7 @@<br>
+# RUN: llvm-mc %s -filetype obj -triple i386-pc-linux -o - | \<br>
+# RUN: llvm-dwarfdump -debug-addr - | FileCheck %s<br>
+# CHECK: .debug_addr contents:<br>
+# CHECK-NOT: Addr<br>
+# CHECK-NOT: error:<br>
+<br>
+.section .debug_addr,"",@progbits<br>
<br>
Added: llvm/trunk/test/tools/llvm-dwarfdump/X86/debug_addr_invalid_addr_size.s<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-dwarfdump/X86/debug_addr_invalid_addr_size.s?rev=338447&view=auto" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-dwarfdump/X86/debug_addr_invalid_addr_size.s?rev=338447&view=auto</a><br>
==============================================================================<br>
--- llvm/trunk/test/tools/llvm-dwarfdump/X86/debug_addr_invalid_addr_size.s (added)<br>
+++ llvm/trunk/test/tools/llvm-dwarfdump/X86/debug_addr_invalid_addr_size.s Tue Jul 31 15:19:19 2018<br>
@@ -0,0 +1,18 @@<br>
+# RUN: llvm-mc %s -filetype obj -triple i386-pc-linux -o - | \<br>
+# RUN: llvm-dwarfdump -debug-addr - 2> %t.err | FileCheck %s<br>
+# RUN: FileCheck %s -input-file %t.err -check-prefix=ERR<br>
+<br>
+# CHECK: .debug_addr contents:<br>
+# CHECK-NOT: {{.}}<br>
+# ERR: unsupported address size 3<br>
+# ERR-NOT: {{.}}<br>
+<br>
+# invalid addr size<br>
+  .section  .debug_addr,"",@progbits<br>
+.Ldebug_addr0:<br>
+  .long 12 # unit_length = .short + .byte + .byte + .long + .long<br>
+  .short 5 # version<br>
+  .byte 3  # address_size<br>
+  .byte 0  # segment_selector_size<br>
+  .long 0x00000000<br>
+  .long 0x00000001<br>
<br>
Added: llvm/trunk/test/tools/llvm-dwarfdump/X86/debug_addr_segment_selector.s<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-dwarfdump/X86/debug_addr_segment_selector.s?rev=338447&view=auto" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-dwarfdump/X86/debug_addr_segment_selector.s?rev=338447&view=auto</a><br>
==============================================================================<br>
--- llvm/trunk/test/tools/llvm-dwarfdump/X86/debug_addr_segment_selector.s (added)<br>
+++ llvm/trunk/test/tools/llvm-dwarfdump/X86/debug_addr_segment_selector.s Tue Jul 31 15:19:19 2018<br>
@@ -0,0 +1,17 @@<br>
+# RUN: llvm-mc %s -filetype obj -triple i386-pc-linux -o - | \<br>
+# RUN: llvm-dwarfdump -debug-addr - 2> %t.err | FileCheck %s<br>
+# RUN: FileCheck %s -input-file %t.err -check-prefix=ERR<br>
+<br>
+# CHECK: .debug_addr contents:<br>
+# CHECK-NOT: {{.}}<br>
+# ERR: .debug_addr table at offset 0x0 has unsupported segment selector size 1<br>
+# ERR-NOT: {{.}}<br>
+<br>
+# non-zero segment_selector_size<br>
+# TODO: make this valid<br>
+  .section  .debug_addr,"",@progbits<br>
+.Ldebug_addr0:<br>
+  .long 4  # unit_length = .short + .byte + .byte<br>
+  .short 5 # version<br>
+  .byte 4  # address_size<br>
+  .byte 1  # segment_selector_size<br>
<br>
Added: llvm/trunk/test/tools/llvm-dwarfdump/X86/debug_addr_small_length_field.s<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-dwarfdump/X86/debug_addr_small_length_field.s?rev=338447&view=auto" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-dwarfdump/X86/debug_addr_small_length_field.s?rev=338447&view=auto</a><br>
==============================================================================<br>
--- llvm/trunk/test/tools/llvm-dwarfdump/X86/debug_addr_small_length_field.s (added)<br>
+++ llvm/trunk/test/tools/llvm-dwarfdump/X86/debug_addr_small_length_field.s Tue Jul 31 15:19:19 2018<br>
@@ -0,0 +1,18 @@<br>
+# RUN: llvm-mc %s -filetype obj -triple i386-pc-linux -o - | \<br>
+# RUN: llvm-dwarfdump -debug-addr - 2> %t.err | FileCheck %s<br>
+# RUN: FileCheck %s -input-file %t.err -check-prefix=ERR<br>
+<br>
+# CHECK: .debug_addr contents:<br>
+# CHECK-NOT: {{.}}<br>
+# ERR: .debug_addr table at offset 0x0 has too small length (0x5) to contain a complete header<br>
+# ERR-NOT: {{.}}<br>
+<br>
+# too small length value<br>
+  .section  .debug_addr,"",@progbits<br>
+.Ldebug_addr0:<br>
+  .long 1  # unit_length<br>
+  .short 5 # version<br>
+  .byte 4  # address_size<br>
+  .byte 0  # segment_selector_size<br>
+  .long 0x00000000<br>
+  .long 0x00000001<br>
<br>
Added: llvm/trunk/test/tools/llvm-dwarfdump/X86/debug_addr_too_small_for_length_field.s<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-dwarfdump/X86/debug_addr_too_small_for_length_field.s?rev=338447&view=auto" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-dwarfdump/X86/debug_addr_too_small_for_length_field.s?rev=338447&view=auto</a><br>
==============================================================================<br>
--- llvm/trunk/test/tools/llvm-dwarfdump/X86/debug_addr_too_small_for_length_field.s (added)<br>
+++ llvm/trunk/test/tools/llvm-dwarfdump/X86/debug_addr_too_small_for_length_field.s Tue Jul 31 15:19:19 2018<br>
@@ -0,0 +1,13 @@<br>
+# RUN: llvm-mc %s -filetype obj -triple i386-pc-linux -o - | \<br>
+# RUN: llvm-dwarfdump -debug-addr - 2> %t.err | FileCheck %s<br>
+# RUN: FileCheck %s -input-file %t.err -check-prefix=ERR<br>
+<br>
+# CHECK: .debug_addr contents:<br>
+# CHECK-NOT: {{.}}<br>
+# ERR: section is not large enough to contain a .debug_addr table length at offset 0x0<br>
+# ERR-NOT: {{.}}<br>
+<br>
+# too small section to contain length field<br>
+  .section  .debug_addr,"",@progbits<br>
+.Ldebug_addr0:<br>
+  .short 1 # unit_length<br>
<br>
Added: llvm/trunk/test/tools/llvm-dwarfdump/X86/debug_addr_too_small_for_section.s<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-dwarfdump/X86/debug_addr_too_small_for_section.s?rev=338447&view=auto" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-dwarfdump/X86/debug_addr_too_small_for_section.s?rev=338447&view=auto</a><br>
==============================================================================<br>
--- llvm/trunk/test/tools/llvm-dwarfdump/X86/debug_addr_too_small_for_section.s (added)<br>
+++ llvm/trunk/test/tools/llvm-dwarfdump/X86/debug_addr_too_small_for_section.s Tue Jul 31 15:19:19 2018<br>
@@ -0,0 +1,16 @@<br>
+# RUN: llvm-mc %s -filetype obj -triple i386-pc-linux -o - | \<br>
+# RUN: llvm-dwarfdump -debug-addr - 2> %t.err | FileCheck %s<br>
+# RUN: FileCheck %s -input-file %t.err -check-prefix=ERR<br>
+<br>
+# CHECK: .debug_addr contents:<br>
+# CHECK-NOT: {{.}}<br>
+# ERR: section is not large enough to contain a .debug_addr table of length 0x10 at offset 0x0<br>
+# ERR-NOT: {{.}}<br>
+<br>
+# too small section to contain section of given length<br>
+  .section  .debug_addr,"",@progbits<br>
+.Ldebug_addr0:<br>
+  .long 12 # unit_length<br>
+  .short 5 # version<br>
+  .byte 4  # address_size<br>
+  .byte 0  # segment_selector_size<br>
<br>
Added: llvm/trunk/test/tools/llvm-dwarfdump/X86/debug_addr_unsupported_version.s<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-dwarfdump/X86/debug_addr_unsupported_version.s?rev=338447&view=auto" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-dwarfdump/X86/debug_addr_unsupported_version.s?rev=338447&view=auto</a><br>
==============================================================================<br>
--- llvm/trunk/test/tools/llvm-dwarfdump/X86/debug_addr_unsupported_version.s (added)<br>
+++ llvm/trunk/test/tools/llvm-dwarfdump/X86/debug_addr_unsupported_version.s Tue Jul 31 15:19:19 2018<br>
@@ -0,0 +1,42 @@<br>
+# RUN: llvm-mc %s -filetype obj -triple i386-pc-linux -o - | \<br>
+# RUN: llvm-dwarfdump -debug-addr - 2> %t.err | FileCheck %s<br>
+# RUN: FileCheck %s -input-file %t.err -check-prefix=ERR<br>
+<br>
+# ERR: version 6 of .debug_addr section at offset 0x0 is not supported<br>
+# ERR-NOT: {{.}}<br>
+<br>
+# CHECK: .debug_addr contents<br>
+# CHECK-NEXT:     length = 0x0000000c, version = 0x0005, addr_size = 0x04, seg_size = 0x00<br>
+# CHECK-NEXT:     Addrs: [<br>
+# CHECK-NEXT:     0x00000002<br>
+# CHECK-NEXT:     0x00000003<br>
+# CHECK-NEXT:     ]<br>
+# CHECK-NOT:      {{.}}<br>
+<br>
+       .section        .debug_abbrev,"",@progbits<br>
+       .byte   1                       # Abbreviation Code<br>
+       .section        .debug_info,"",@progbits<br>
+.Lcu_begin0:<br>
+       .long 8                       # Length of Unit<br>
+       .short  5                     # DWARF version number<br>
+  .byte 1                       # DWARF unit type<br>
+       .byte   4                       # Address Size (in bytes)<br>
+       .long   .debug_abbrev           # Offset Into Abbrev. Section<br>
+<br>
+       .section        .debug_addr,"",@progbits<br>
+.Ldebug_addr0:<br>
+  .long 12 # unit_length = .short + .byte + .byte + .long + .long<br>
+  .short 6 # version<br>
+  .byte 4  # address_size<br>
+  .byte 0  # segment_selector_size<br>
+  .long 0x00000000<br>
+  .long 0x00000001<br>
+<br>
+       .section        .debug_addr,"",@progbits<br>
+.Ldebug_addr1:<br>
+  .long 12 # unit_length = .short + .byte + .byte + .long + .long<br>
+  .short 5 # version<br>
+  .byte 4  # address_size<br>
+  .byte 0  # segment_selector_size<br>
+  .long 0x00000002<br>
+  .long 0x00000003<br>
<br>
Added: llvm/trunk/test/tools/llvm-dwarfdump/X86/debug_addr_version_mismatch.s<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-dwarfdump/X86/debug_addr_version_mismatch.s?rev=338447&view=auto" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-dwarfdump/X86/debug_addr_version_mismatch.s?rev=338447&view=auto</a><br>
==============================================================================<br>
--- llvm/trunk/test/tools/llvm-dwarfdump/X86/debug_addr_version_mismatch.s (added)<br>
+++ llvm/trunk/test/tools/llvm-dwarfdump/X86/debug_addr_version_mismatch.s Tue Jul 31 15:19:19 2018<br>
@@ -0,0 +1,42 @@<br>
+# RUN: llvm-mc %s -filetype obj -triple i386-pc-linux -o - | \<br>
+# RUN: llvm-dwarfdump -debug-addr - 2> %t.err | FileCheck %s<br>
+# RUN: FileCheck %s -input-file %t.err -check-prefix=ERR<br>
+<br>
+# ERR: .debug_addr table at offset 0x0 has version 4 which is different from the version suggested by the DWARF unit header: 5<br>
+# ERR-NOT: {{.}}<br>
+<br>
+# CHECK: .debug_addr contents<br>
+# CHECK-NEXT:     length = 0x0000000c, version = 0x0005, addr_size = 0x04, seg_size = 0x00<br>
+# CHECK-NEXT:     Addrs: [<br>
+# CHECK-NEXT:     0x00000000<br>
+# CHECK-NEXT:     0x00000001<br>
+# CHECK-NEXT:     ]<br>
+# CHECK-NOT:      {{.}}<br>
+<br>
+       .section        .debug_abbrev,"",@progbits<br>
+       .byte   1                       # Abbreviation Code<br>
+       .section        .debug_info,"",@progbits<br>
+.Lcu_begin0:<br>
+       .long 8                       # Length of Unit<br>
+       .short  5                     # DWARF version number<br>
+  .byte 1                       # DWARF unit type<br>
+       .byte   4                       # Address Size (in bytes)<br>
+       .long   .debug_abbrev           # Offset Into Abbrev. Section<br>
+<br>
+       .section        .debug_addr,"",@progbits<br>
+.Ldebug_addr0:<br>
+  .long 12 # unit_length = .short + .byte + .byte + .long + .long<br>
+  .short 4 # version<br>
+  .byte 4  # address_size<br>
+  .byte 0  # segment_selector_size<br>
+  .long 0x00000000<br>
+  .long 0x00000001<br>
+<br>
+       .section        .debug_addr,"",@progbits<br>
+.Ldebug_addr1:<br>
+  .long 12 # unit_length = .short + .byte + .byte + .long + .long<br>
+  .short 5 # version<br>
+  .byte 4  # address_size<br>
+  .byte 0  # segment_selector_size<br>
+  .long 0x00000000<br>
+  .long 0x00000001<br>
<br>
<br>
_______________________________________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@lists.llvm.org" target="_blank">llvm-commits@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits</a><br>
</blockquote></div></div>