<div dir="ltr"><br><br><div class="gmail_quote"><div dir="ltr">On Tue, May 2, 2017 at 10:50 AM Paul Robinson 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: probinson<br>
Date: Tue May  2 12:37:32 2017<br>
New Revision: 301940<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=301940&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project?rev=301940&view=rev</a><br>
Log:<br>
Make DWARFDebugLine use StringRef for directory/file tables. NFC<br>
<br>
Differential Revision: <a href="http://reviews.llvm.org/D32728" rel="noreferrer" target="_blank">http://reviews.llvm.org/D32728</a><br>
<br>
Modified:<br>
    llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFDebugLine.h<br>
    llvm/trunk/include/llvm/Support/DataExtractor.h<br>
    llvm/trunk/lib/DebugInfo/DWARF/DWARFDebugLine.cpp<br>
    llvm/trunk/lib/Support/DataExtractor.cpp<br>
<br>
Modified: llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFDebugLine.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFDebugLine.h?rev=301940&r1=301939&r2=301940&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFDebugLine.h?rev=301940&r1=301939&r2=301940&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFDebugLine.h (original)<br>
+++ llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFDebugLine.h Tue May  2 12:37:32 2017<br>
@@ -30,7 +30,7 @@ public:<br>
   struct FileNameEntry {<br>
     FileNameEntry() = default;<br>
<br>
-    const char *Name = nullptr;<br>
+    StringRef Name = StringRef();<br></blockquote><div><br>This is redundant ^ - probably best to write it as "StringRef Name;" ?<br><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
     uint64_t DirIdx = 0;<br>
     uint64_t ModTime = 0;<br>
     uint64_t Length = 0;<br>
@@ -63,7 +63,7 @@ public:<br>
     /// The number assigned to the first special opcode.<br>
     uint8_t OpcodeBase;<br>
     std::vector<uint8_t> StandardOpcodeLengths;<br>
-    std::vector<const char *> IncludeDirectories;<br>
+    std::vector<StringRef> IncludeDirectories;<br>
     std::vector<FileNameEntry> FileNames;<br>
<br>
     bool IsDWARF64;<br>
<br>
Modified: llvm/trunk/include/llvm/Support/DataExtractor.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/DataExtractor.h?rev=301940&r1=301939&r2=301940&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/DataExtractor.h?rev=301940&r1=301939&r2=301940&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/include/llvm/Support/DataExtractor.h (original)<br>
+++ llvm/trunk/include/llvm/Support/DataExtractor.h Tue May  2 12:37:32 2017<br>
@@ -58,6 +58,28 @@ public:<br>
   ///     NULL will be returned.<br>
   const char *getCStr(uint32_t *offset_ptr) const;<br>
<br>
+  /// Extract a C string from \a *OffsetPtr.<br>
+  ///<br>
+  /// Returns a StringRef for the C String from the data at the offset<br>
+  /// pointed to by \a OffsetPtr. A variable length NULL terminated C<br>
+  /// string will be extracted and the \a OffsetPtr will be<br>
+  /// updated with the offset of the byte that follows the NULL<br>
+  /// terminator byte.<br>
+  ///<br>
+  /// \param[in,out] OffsetPtr<br>
+  ///     A pointer to an offset within the data that will be advanced<br>
+  ///     by the appropriate number of bytes if the value is extracted<br>
+  ///     correctly. If the offset is out of bounds or there are not<br>
+  ///     enough bytes to extract this value, the offset will be left<br>
+  ///     unmodified.<br>
+  ///<br>
+  /// \return<br>
+  ///     A StringRef for the C string value in the data. If the offset<br>
+  ///     pointed to by \a OffsetPtr is out of bounds, or if the<br>
+  ///     offset plus the length of the C string is out of bounds,<br>
+  ///     a default-initialized StringRef will be returned.<br>
+  StringRef getCStrRef(uint32_t *OffsetPtr) const;<br>
+<br>
   /// Extract an unsigned integer of size \a byte_size from \a<br>
   /// *offset_ptr.<br>
   ///<br>
<br>
Modified: llvm/trunk/lib/DebugInfo/DWARF/DWARFDebugLine.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/DWARF/DWARFDebugLine.cpp?rev=301940&r1=301939&r2=301940&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/DWARF/DWARFDebugLine.cpp?rev=301940&r1=301939&r2=301940&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/lib/DebugInfo/DWARF/DWARFDebugLine.cpp (original)<br>
+++ llvm/trunk/lib/DebugInfo/DWARF/DWARFDebugLine.cpp Tue May  2 12:37:32 2017<br>
@@ -107,25 +107,22 @@ bool DWARFDebugLine::Prologue::parse(Dat<br>
   }<br>
<br>
   while (*OffsetPtr < EndPrologueOffset) {<br>
-    const char *S = DebugLineData.getCStr(OffsetPtr);<br>
-    if (S && S[0])<br>
-      IncludeDirectories.push_back(S);<br>
-    else<br>
+    StringRef S = DebugLineData.getCStrRef(OffsetPtr);<br>
+    if (S.empty())<br>
       break;<br>
+    IncludeDirectories.push_back(S);<br>
   }<br>
<br>
   while (*OffsetPtr < EndPrologueOffset) {<br>
-    const char *Name = DebugLineData.getCStr(OffsetPtr);<br>
-    if (Name && Name[0]) {<br>
-      FileNameEntry FileEntry;<br>
-      FileEntry.Name = Name;<br>
-      FileEntry.DirIdx = DebugLineData.getULEB128(OffsetPtr);<br>
-      FileEntry.ModTime = DebugLineData.getULEB128(OffsetPtr);<br>
-      FileEntry.Length = DebugLineData.getULEB128(OffsetPtr);<br>
-      FileNames.push_back(FileEntry);<br>
-    } else {<br>
+    StringRef Name = DebugLineData.getCStrRef(OffsetPtr);<br>
+    if (Name.empty())<br>
       break;<br>
-    }<br>
+    FileNameEntry FileEntry;<br>
+    FileEntry.Name = Name;<br>
+    FileEntry.DirIdx = DebugLineData.getULEB128(OffsetPtr);<br>
+    FileEntry.ModTime = DebugLineData.getULEB128(OffsetPtr);<br>
+    FileEntry.Length = DebugLineData.getULEB128(OffsetPtr);<br>
+    FileNames.push_back(FileEntry);<br>
   }<br>
<br>
   if (*OffsetPtr != EndPrologueOffset) {<br>
@@ -637,7 +634,7 @@ bool DWARFDebugLine::LineTable::getFileN<br>
   if (Kind == FileLineInfoKind::None || !hasFileAtIndex(FileIndex))<br>
     return false;<br>
   const FileNameEntry &Entry = Prologue.FileNames[FileIndex - 1];<br>
-  const char *FileName = Entry.Name;<br>
+  StringRef FileName = Entry.Name;<br>
   if (Kind != FileLineInfoKind::AbsoluteFilePath ||<br>
       sys::path::is_absolute(FileName)) {<br>
     Result = FileName;<br>
@@ -646,7 +643,7 @@ bool DWARFDebugLine::LineTable::getFileN<br>
<br>
   SmallString<16> FilePath;<br>
   uint64_t IncludeDirIndex = Entry.DirIdx;<br>
-  const char *IncludeDir = "";<br>
+  StringRef IncludeDir;<br>
   // Be defensive about the contents of Entry.<br>
   if (IncludeDirIndex > 0 &&<br>
       IncludeDirIndex <= Prologue.IncludeDirectories.size())<br>
<br>
Modified: llvm/trunk/lib/Support/DataExtractor.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/DataExtractor.cpp?rev=301940&r1=301939&r2=301940&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/DataExtractor.cpp?rev=301940&r1=301939&r2=301940&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/lib/Support/DataExtractor.cpp (original)<br>
+++ llvm/trunk/lib/Support/DataExtractor.cpp Tue May  2 12:37:32 2017<br>
@@ -128,6 +128,16 @@ const char *DataExtractor::getCStr(uint3<br>
   return nullptr;<br>
 }<br>
<br>
+StringRef DataExtractor::getCStrRef(uint32_t *OffsetPtr) const {<br>
+  uint32_t Start = *OffsetPtr;<br>
+  StringRef::size_type Pos = Data.find('\0', Start);<br>
+  if (Pos != StringRef::npos) {<br>
+    *OffsetPtr = Pos + 1;<br>
+    return StringRef(Data.data() + Start, Pos - Start);<br>
+  }<br>
+  return StringRef();<br>
+}<br>
+<br>
 uint64_t DataExtractor::getULEB128(uint32_t *offset_ptr) const {<br>
   uint64_t result = 0;<br>
   if (Data.empty())<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>