<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="Generator" content="Microsoft Word 14 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:Tahoma;
        panose-1:2 11 6 4 3 5 4 4 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Times New Roman","serif";}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
span.EmailStyle17
        {mso-style-type:personal-reply;
        font-family:"Calibri","sans-serif";
        color:#1F497D;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-family:"Calibri","sans-serif";}
@page WordSection1
        {size:8.5in 11.0in;
        margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
        {page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang="EN-US" link="blue" vlink="purple">
<div class="WordSection1">
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">r302756.<o:p></o:p></span></p>
<p class="MsoNormal"><a name="_MailEndCompose"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D"><o:p> </o:p></span></a></p>
<div style="border:none;border-left:solid blue 1.5pt;padding:0in 0in 0in 4.0pt">
<div>
<div style="border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0in 0in 0in">
<p class="MsoNormal"><b><span style="font-size:10.0pt;font-family:"Tahoma","sans-serif"">From:</span></b><span style="font-size:10.0pt;font-family:"Tahoma","sans-serif""> David Blaikie [mailto:dblaikie@gmail.com]
<br>
<b>Sent:</b> Monday, May 08, 2017 11:26 AM<br>
<b>To:</b> Robinson, Paul; llvm-commits@lists.llvm.org<br>
<b>Subject:</b> Re: [llvm] r301940 - Make DWARFDebugLine use StringRef for directory/file tables. NFC<o:p></o:p></span></p>
</div>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<p class="MsoNormal" style="margin-bottom:12.0pt"><o:p> </o:p></p>
<div>
<div>
<p class="MsoNormal">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:<o:p></o:p></p>
</div>
<blockquote style="border:none;border-left:solid #CCCCCC 1.0pt;padding:0in 0in 0in 6.0pt;margin-left:4.8pt;margin-right:0in">
<p class="MsoNormal">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" 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" 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" 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();<o:p></o:p></p>
</blockquote>
<div>
<p class="MsoNormal" style="margin-bottom:12.0pt"><br>
This is redundant ^ - probably best to write it as "StringRef Name;" ?<o:p></o:p></p>
</div>
<blockquote style="border:none;border-left:solid #CCCCCC 1.0pt;padding:0in 0in 0in 6.0pt;margin-left:4.8pt;margin-right:0in">
<p class="MsoNormal">     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" 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" 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" 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" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits</a><o:p></o:p></p>
</blockquote>
</div>
</div>
</div>
</div>
</body>
</html>