<div class="gmail_extra"><div class="gmail_quote">On Mon, Aug 27, 2012 at 12:17 AM, Alexey Samsonov <span dir="ltr"><<a href="mailto:samsonov@google.com" target="_blank" class="cremed">samsonov@google.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: samsonov<br>
Date: Mon Aug 27 02:17:47 2012<br>
New Revision: 162657<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=162657&view=rev" target="_blank" class="cremed">http://llvm.org/viewvc/llvm-project?rev=162657&view=rev</a><br>
Log:<br>
Add basic support for .debug_ranges section to LLVM's DebugInfo library.<br>
This section (introduced in DWARF-3) is used to define instruction address<br>
ranges for functions that are not contiguous and can't be described<br>
by low_pc/high_pc attributes (this is the usual case for inlined subroutines).<br>
The patch is the first step to support fetching complete inlining info from DWARF.<br>
<br>
Reviewed by Benjamin Kramer.<br>
<br>
Added:<br>
    llvm/trunk/lib/DebugInfo/DWARFDebugRangeList.cpp<br>
    llvm/trunk/lib/DebugInfo/DWARFDebugRangeList.h<br></blockquote><div><br></div><div>Can you update the CMake build for the new file?</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

Modified:<br>
    llvm/trunk/include/llvm/DebugInfo/DIContext.h<br>
    llvm/trunk/lib/DebugInfo/DIContext.cpp<br>
    llvm/trunk/lib/DebugInfo/DWARFContext.cpp<br>
    llvm/trunk/lib/DebugInfo/DWARFContext.h<br>
    llvm/trunk/test/DebugInfo/dwarfdump-test.test<br>
    llvm/trunk/tools/llvm-dwarfdump/llvm-dwarfdump.cpp<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=162657&r1=162656&r2=162657&view=diff" target="_blank" class="cremed">http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/DebugInfo/DIContext.h?rev=162657&r1=162656&r2=162657&view=diff</a><br>

==============================================================================<br>
--- llvm/trunk/include/llvm/DebugInfo/DIContext.h (original)<br>
+++ llvm/trunk/include/llvm/DebugInfo/DIContext.h Mon Aug 27 02:17:47 2012<br>
@@ -81,7 +81,8 @@<br>
                                     StringRef abbrevSection,<br>
                                     StringRef aRangeSection = StringRef(),<br>
                                     StringRef lineSection = StringRef(),<br>
-                                    StringRef stringSection = StringRef());<br>
+                                    StringRef stringSection = StringRef(),<br>
+                                    StringRef rangeSection = StringRef());<br>
<br>
   virtual void dump(raw_ostream &OS) = 0;<br>
<br>
<br>
Modified: llvm/trunk/lib/DebugInfo/DIContext.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/DIContext.cpp?rev=162657&r1=162656&r2=162657&view=diff" target="_blank" class="cremed">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/DIContext.cpp?rev=162657&r1=162656&r2=162657&view=diff</a><br>

==============================================================================<br>
--- llvm/trunk/lib/DebugInfo/DIContext.cpp (original)<br>
+++ llvm/trunk/lib/DebugInfo/DIContext.cpp Mon Aug 27 02:17:47 2012<br>
@@ -18,7 +18,9 @@<br>
                                       StringRef abbrevSection,<br>
                                       StringRef aRangeSection,<br>
                                       StringRef lineSection,<br>
-                                      StringRef stringSection) {<br>
+                                      StringRef stringSection,<br>
+                                      StringRef rangeSection) {<br>
   return new DWARFContextInMemory(isLittleEndian, infoSection, abbrevSection,<br>
-                                  aRangeSection, lineSection, stringSection);<br>
+                                  aRangeSection, lineSection, stringSection,<br>
+                                  rangeSection);<br>
 }<br>
<br>
Modified: llvm/trunk/lib/DebugInfo/DWARFContext.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/DWARFContext.cpp?rev=162657&r1=162656&r2=162657&view=diff" target="_blank" class="cremed">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/DWARFContext.cpp?rev=162657&r1=162656&r2=162657&view=diff</a><br>

==============================================================================<br>
--- llvm/trunk/lib/DebugInfo/DWARFContext.cpp (original)<br>
+++ llvm/trunk/lib/DebugInfo/DWARFContext.cpp Mon Aug 27 02:17:47 2012<br>
@@ -32,15 +32,17 @@<br>
   while (set.extract(arangesData, &offset))<br>
     set.dump(OS);<br>
<br>
+  uint8_t savedAddressByteSize = 0;<br>
   OS << "\n.debug_lines contents:\n";<br>
   for (unsigned i = 0, e = getNumCompileUnits(); i != e; ++i) {<br>
     DWARFCompileUnit *cu = getCompileUnitAtIndex(i);<br>
+    savedAddressByteSize = cu->getAddressByteSize();<br>
     unsigned stmtOffset =<br>
       cu->getCompileUnitDIE()->getAttributeValueAsUnsigned(cu, DW_AT_stmt_list,<br>
                                                            -1U);<br>
     if (stmtOffset != -1U) {<br>
       DataExtractor lineData(getLineSection(), isLittleEndian(),<br>
-                             cu->getAddressByteSize());<br>
+                             savedAddressByteSize);<br>
       DWARFDebugLine::DumpingState state(OS);<br>
       DWARFDebugLine::parseStatementTable(lineData, &stmtOffset, state);<br>
     }<br>
@@ -54,6 +56,18 @@<br>
     OS << format("0x%8.8x: \"%s\"\n", lastOffset, s);<br>
     lastOffset = offset;<br>
   }<br>
+<br>
+  OS << "\n.debug_ranges contents:\n";<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 last<br>
+  // compile unit (there is no easy and fast way to associate address range<br>
+  // list and the compile unit it describes).<br>
+  DataExtractor rangesData(getRangeSection(), isLittleEndian(),<br>
+                           savedAddressByteSize);<br>
+  offset = 0;<br>
+  DWARFDebugRangeList rangeList;<br>
+  while (rangeList.extract(rangesData, &offset))<br>
+    rangeList.dump(OS);<br>
 }<br>
<br>
 const DWARFDebugAbbrev *DWARFContext::getDebugAbbrev() {<br>
<br>
Modified: llvm/trunk/lib/DebugInfo/DWARFContext.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/DWARFContext.h?rev=162657&r1=162656&r2=162657&view=diff" target="_blank" class="cremed">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/DWARFContext.h?rev=162657&r1=162656&r2=162657&view=diff</a><br>

==============================================================================<br>
--- llvm/trunk/lib/DebugInfo/DWARFContext.h (original)<br>
+++ llvm/trunk/lib/DebugInfo/DWARFContext.h Mon Aug 27 02:17:47 2012<br>
@@ -13,6 +13,7 @@<br>
 #include "DWARFCompileUnit.h"<br>
 #include "DWARFDebugAranges.h"<br>
 #include "DWARFDebugLine.h"<br>
+#include "DWARFDebugRangeList.h"<br>
 #include "llvm/DebugInfo/DIContext.h"<br>
 #include "llvm/ADT/OwningPtr.h"<br>
 #include "llvm/ADT/SmallVector.h"<br>
@@ -76,6 +77,7 @@<br>
   virtual StringRef getARangeSection() = 0;<br>
   virtual StringRef getLineSection() = 0;<br>
   virtual StringRef getStringSection() = 0;<br>
+  virtual StringRef getRangeSection() = 0;<br>
<br>
   static bool isSupportedVersion(unsigned version) {<br>
     return version == 2 || version == 3;<br>
@@ -93,19 +95,22 @@<br>
   StringRef ARangeSection;<br>
   StringRef LineSection;<br>
   StringRef StringSection;<br>
+  StringRef RangeSection;<br>
 public:<br>
   DWARFContextInMemory(bool isLittleEndian,<br>
                        StringRef infoSection,<br>
                        StringRef abbrevSection,<br>
                        StringRef aRangeSection,<br>
                        StringRef lineSection,<br>
-                       StringRef stringSection)<br>
+                       StringRef stringSection,<br>
+                       StringRef rangeSection)<br>
     : DWARFContext(isLittleEndian),<br>
       InfoSection(infoSection),<br>
       AbbrevSection(abbrevSection),<br>
       ARangeSection(aRangeSection),<br>
       LineSection(lineSection),<br>
-      StringSection(stringSection)<br>
+      StringSection(stringSection),<br>
+      RangeSection(rangeSection)<br>
     {}<br>
<br>
   virtual StringRef getInfoSection() { return InfoSection; }<br>
@@ -113,6 +118,7 @@<br>
   virtual StringRef getARangeSection() { return ARangeSection; }<br>
   virtual StringRef getLineSection() { return LineSection; }<br>
   virtual StringRef getStringSection() { return StringSection; }<br>
+  virtual StringRef getRangeSection() { return RangeSection; }<br>
 };<br>
<br>
 }<br>
<br>
Added: llvm/trunk/lib/DebugInfo/DWARFDebugRangeList.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/DWARFDebugRangeList.cpp?rev=162657&view=auto" target="_blank" class="cremed">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/DWARFDebugRangeList.cpp?rev=162657&view=auto</a><br>

==============================================================================<br>
--- llvm/trunk/lib/DebugInfo/DWARFDebugRangeList.cpp (added)<br>
+++ llvm/trunk/lib/DebugInfo/DWARFDebugRangeList.cpp Mon Aug 27 02:17:47 2012<br>
@@ -0,0 +1,58 @@<br>
+//===-- DWARFDebugRangesList.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 "DWARFDebugRangeList.h"<br>
+#include "llvm/Support/Format.h"<br>
+#include "llvm/Support/raw_ostream.h"<br>
+<br>
+using namespace llvm;<br>
+<br>
+void DWARFDebugRangeList::clear() {<br>
+  Offset = -1U;<br>
+  AddressSize = 0;<br>
+  Entries.clear();<br>
+}<br>
+<br>
+bool DWARFDebugRangeList::extract(DataExtractor data, uint32_t *offset_ptr) {<br>
+  clear();<br>
+  if (!data.isValidOffset(*offset_ptr))<br>
+    return false;<br>
+  AddressSize = data.getAddressSize();<br>
+  if (AddressSize != 4 && AddressSize != 8)<br>
+    return false;<br>
+  Offset = *offset_ptr;<br>
+  while (true) {<br>
+    RangeListEntry entry;<br>
+    uint32_t prev_offset = *offset_ptr;<br>
+    entry.StartAddress = data.getAddress(offset_ptr);<br>
+    entry.EndAddress = data.getAddress(offset_ptr);<br>
+    // Check that both values were extracted correctly.<br>
+    if (*offset_ptr != prev_offset + 2 * AddressSize) {<br>
+      clear();<br>
+      return false;<br>
+    }<br>
+    // The end of any given range list is marked by an end of list entry,<br>
+    // which consists of a 0 for the beginning address offset<br>
+    // and a 0 for the ending address offset.<br>
+    if (entry.StartAddress == 0 && entry.EndAddress == 0)<br>
+      break;<br>
+    Entries.push_back(entry);<br>
+  }<br>
+  return true;<br>
+}<br>
+<br>
+void DWARFDebugRangeList::dump(raw_ostream &OS) const {<br>
+  for (int i = 0, n = Entries.size(); i != n; ++i) {<br>
+    const char *format_str = (AddressSize == 4) ? "%08x %08x %08x\n"<br>
+                                                : "%08x %016x %016x\n";<br>
+    OS << format(format_str, Offset, Entries[i].StartAddress,<br>
+                                     Entries[i].EndAddress);<br>
+  }<br>
+  OS << format("%08x <End of list>\n", Offset);<br>
+}<br>
<br>
Added: llvm/trunk/lib/DebugInfo/DWARFDebugRangeList.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/DWARFDebugRangeList.h?rev=162657&view=auto" target="_blank" class="cremed">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/DWARFDebugRangeList.h?rev=162657&view=auto</a><br>

==============================================================================<br>
--- llvm/trunk/lib/DebugInfo/DWARFDebugRangeList.h (added)<br>
+++ llvm/trunk/lib/DebugInfo/DWARFDebugRangeList.h Mon Aug 27 02:17:47 2012<br>
@@ -0,0 +1,51 @@<br>
+//===-- DWARFDebugRangeList.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_DWARFDEBUGRANGELIST_H<br>
+#define LLVM_DEBUGINFO_DWARFDEBUGRANGELIST_H<br>
+<br>
+#include "llvm/Support/DataExtractor.h"<br>
+#include <vector><br>
+<br>
+namespace llvm {<br>
+<br>
+class raw_ostream;<br>
+<br>
+class DWARFDebugRangeList {<br>
+public:<br>
+  struct RangeListEntry {<br>
+    // A beginning address offset. This address offset has the size of an<br>
+    // address and is relative to the applicable base address of the<br>
+    // compilation unit referencing this range list. It marks the beginning<br>
+    // of an address range.<br>
+    uint64_t StartAddress;<br>
+    // An ending address offset. This address offset again has the size of<br>
+    // an address and is relative to the applicable base address of the<br>
+    // compilation unit referencing this range list. It marks the first<br>
+    // address past the end of the address range. The ending address must<br>
+    // be greater than or equal to the beginning address.<br>
+    uint64_t EndAddress;<br>
+  };<br>
+<br>
+private:<br>
+  // Offset in .debug_ranges section.<br>
+  uint32_t Offset;<br>
+  uint8_t AddressSize;<br>
+  std::vector<RangeListEntry> Entries;<br>
+<br>
+public:<br>
+  DWARFDebugRangeList() { clear(); }<br>
+  void clear();<br>
+  void dump(raw_ostream &OS) const;<br>
+  bool extract(DataExtractor data, uint32_t *offset_ptr);<br>
+};<br>
+<br>
+}  // namespace llvm<br>
+<br>
+#endif  // LLVM_DEBUGINFO_DWARFDEBUGRANGELIST_H<br>
<br>
Modified: llvm/trunk/test/DebugInfo/dwarfdump-test.test<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/test/DebugInfo/dwarfdump-test.test?rev=162657&r1=162656&r2=162657&view=diff" target="_blank" class="cremed">http://llvm.org/viewvc/llvm-project/llvm/trunk/test/DebugInfo/dwarfdump-test.test?rev=162657&r1=162656&r2=162657&view=diff</a><br>

==============================================================================<br>
--- llvm/trunk/test/DebugInfo/dwarfdump-test.test (original)<br>
+++ llvm/trunk/test/DebugInfo/dwarfdump-test.test Mon Aug 27 02:17:47 2012<br>
@@ -17,6 +17,8 @@<br>
 RUN: llvm-dwarfdump %p/Inputs/dwarfdump-test4.elf-x86-64 \<br>
 RUN:   --address=0x55c --functions \<br>
 RUN:   | FileCheck %s -check-prefix MANY_SEQ_IN_LINE_TABLE<br>
+RUN: llvm-dwarfdump %p/Inputs/dwarfdump-test4.elf-x86-64 \<br>
+RUN:   | FileCheck %s -check-prefix DEBUG_RANGES<br>
<br>
 MAIN: main<br>
 MAIN-NEXT: /tmp/dbginfo{{[/\\]}}dwarfdump-test.cc:16:10<br>
@@ -44,3 +46,11 @@<br>
<br>
 MANY_SEQ_IN_LINE_TABLE: _Z1cv<br>
 MANY_SEQ_IN_LINE_TABLE-NEXT: /tmp/dbginfo/sequences{{[/\\]}}c.cc:2:0<br>
+<br>
+DEBUG_RANGES:      .debug_ranges contents:<br>
+DEBUG_RANGES-NEXT: 00000000 000000000000055c 0000000000000567<br>
+DEBUG_RANGES-NEXT: 00000000 0000000000000567 000000000000056d<br>
+DEBUG_RANGES-NEXT: 00000000 <End of list><br>
+DEBUG_RANGES-NEXT: 00000030 0000000000000570 000000000000057b<br>
+DEBUG_RANGES-NEXT: 00000030 0000000000000567 000000000000056d<br>
+DEBUG_RANGES-NEXT: 00000030 <End of list><br>
<br>
Modified: llvm/trunk/tools/llvm-dwarfdump/llvm-dwarfdump.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-dwarfdump/llvm-dwarfdump.cpp?rev=162657&r1=162656&r2=162657&view=diff" target="_blank" class="cremed">http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-dwarfdump/llvm-dwarfdump.cpp?rev=162657&r1=162656&r2=162657&view=diff</a><br>

==============================================================================<br>
--- llvm/trunk/tools/llvm-dwarfdump/llvm-dwarfdump.cpp (original)<br>
+++ llvm/trunk/tools/llvm-dwarfdump/llvm-dwarfdump.cpp Mon Aug 27 02:17:47 2012<br>
@@ -59,6 +59,7 @@<br>
   StringRef DebugLineSection;<br>
   StringRef DebugArangesSection;<br>
   StringRef DebugStringSection;<br>
+  StringRef DebugRangesSection;<br>
<br>
   error_code ec;<br>
   for (section_iterator i = Obj->begin_sections(),<br>
@@ -82,6 +83,8 @@<br>
       DebugArangesSection = data;<br>
     else if (name == "debug_str")<br>
       DebugStringSection = data;<br>
+    else if (name == "debug_ranges")<br>
+      DebugRangesSection = data;<br>
   }<br>
<br>
   OwningPtr<DIContext> dictx(DIContext::getDWARFContext(/*FIXME*/true,<br>
@@ -89,7 +92,8 @@<br>
                                                         DebugAbbrevSection,<br>
                                                         DebugArangesSection,<br>
                                                         DebugLineSection,<br>
-                                                        DebugStringSection));<br>
+                                                        DebugStringSection,<br>
+                                                        DebugRangesSection));<br>
   if (Address == -1ULL) {<br>
     outs() << Filename<br>
            << ":\tfile format " << Obj->getFileFormatName() << "\n\n";<br>
<br>
<br>
_______________________________________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@cs.uiuc.edu" class="cremed">llvm-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits" target="_blank" class="cremed">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</a><br>
</blockquote></div><br></div>