<div dir="ltr">Can you upload a diff (with context) to phabricator and add lldb-commits as a subscriber and myself / Greg as reviewers?</div><br><div class="gmail_quote"><div dir="ltr">On Mon, Oct 17, 2016 at 4:59 PM Eugene Birukov via lldb-dev <<a href="mailto:lldb-dev@lists.llvm.org">lldb-dev@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">




<div dir="ltr" class="gmail_msg">
<div id="m_7052815235107701521divtagdefaultwrapper" style="font-size:12pt;color:#000000;font-family:Calibri,Arial,Helvetica,sans-serif" class="gmail_msg">
<p class="gmail_msg">Here is what I am running now:</p>
<p class="gmail_msg"><br class="gmail_msg">
</p>
<p class="gmail_msg"></p>
<div class="gmail_msg"><span style="font-family:"Courier New",monospace;font-size:9pt" class="gmail_msg">diff --git a/source/Host/common/File.cpp b/source/Host/common/File.cpp</span></div>
<div class="gmail_msg"><span style="font-family:"Courier New",monospace;font-size:9pt" class="gmail_msg">index 89587a9..a4ac25e 100644</span></div>
<div class="gmail_msg"><span style="font-family:"Courier New",monospace;font-size:9pt" class="gmail_msg">--- a/source/Host/common/File.cpp</span></div>
<div class="gmail_msg"><span style="font-family:"Courier New",monospace;font-size:9pt" class="gmail_msg">+++ b/source/Host/common/File.cpp</span></div>
<div class="gmail_msg"><span style="font-family:"Courier New",monospace;font-size:9pt" class="gmail_msg">@@ -771,21 +771,34 @@ File::Read (void *buf, size_t &num_bytes, off_t &offset)</span></div></div></div><div dir="ltr" class="gmail_msg"><div id="m_7052815235107701521divtagdefaultwrapper" style="font-size:12pt;color:#000000;font-family:Calibri,Arial,Helvetica,sans-serif" class="gmail_msg">
<div class="gmail_msg"><span style="font-family:"Courier New",monospace;font-size:9pt" class="gmail_msg">     int fd = GetDescriptor();</span></div>
<div class="gmail_msg"><span style="font-family:"Courier New",monospace;font-size:9pt" class="gmail_msg">     if (fd != kInvalidDescriptor)</span></div>
<div class="gmail_msg"><span style="font-family:"Courier New",monospace;font-size:9pt" class="gmail_msg">     {</span></div>
</div></div><div dir="ltr" class="gmail_msg"><div id="m_7052815235107701521divtagdefaultwrapper" style="font-size:12pt;color:#000000;font-family:Calibri,Arial,Helvetica,sans-serif" class="gmail_msg"><div class="gmail_msg"><span style="font-family:"Courier New",monospace;font-size:9pt" class="gmail_msg">-        ssize_t bytes_read = -1;</span></div>
<div class="gmail_msg"><span style="font-family:"Courier New",monospace;font-size:9pt" class="gmail_msg">-        do</span></div>
<div class="gmail_msg"><span style="font-family:"Courier New",monospace;font-size:9pt" class="gmail_msg">+        size_t bytes_left = num_bytes;</span></div>
<div class="gmail_msg"><span style="font-family:"Courier New",monospace;font-size:9pt" class="gmail_msg">+        num_bytes = 0;</span></div>
<div class="gmail_msg"><span style="font-family:"Courier New",monospace;font-size:9pt" class="gmail_msg">+        char *pos = (char*)buf;</span></div>
<div class="gmail_msg"><span style="font-family:"Courier New",monospace;font-size:9pt" class="gmail_msg">+        while (bytes_left > 0)</span></div>
<div class="gmail_msg"><span style="font-family:"Courier New",monospace;font-size:9pt" class="gmail_msg">         {</span></div>
<div class="gmail_msg"><span style="font-family:"Courier New",monospace;font-size:9pt" class="gmail_msg">-            bytes_read = ::pread (fd, buf, num_bytes, offset);</span></div>
<div class="gmail_msg"><span style="font-family:"Courier New",monospace;font-size:9pt" class="gmail_msg">-        } while (bytes_read < 0 && errno == EINTR);</span></div>
<div class="gmail_msg"><span style="font-family:"Courier New",monospace;font-size:9pt" class="gmail_msg">+            ssize_t bytes_read = -1;</span></div>
<div class="gmail_msg"><span style="font-family:"Courier New",monospace;font-size:9pt" class="gmail_msg">+            do</span></div>
<div class="gmail_msg"><span style="font-family:"Courier New",monospace;font-size:9pt" class="gmail_msg">+            {</span></div>
<div class="gmail_msg"><span style="font-family:"Courier New",monospace;font-size:9pt" class="gmail_msg">+                bytes_read = ::pread (fd, pos, bytes_left, offset);</span></div>
<div class="gmail_msg"><span style="font-family:"Courier New",monospace;font-size:9pt" class="gmail_msg">+            } while (bytes_read < 0 && errno == EINTR);</span></div>
<div class="gmail_msg"><br class="gmail_msg">
</div>
<div class="gmail_msg"><span style="font-family:"Courier New",monospace;font-size:9pt" class="gmail_msg">-        if (bytes_read < 0)</span></div>
<div class="gmail_msg"><span style="font-family:"Courier New",monospace;font-size:9pt" class="gmail_msg">-        {</span></div>
<div class="gmail_msg"><span style="font-family:"Courier New",monospace;font-size:9pt" class="gmail_msg">-            num_bytes = 0;</span></div>
<div class="gmail_msg"><span style="font-family:"Courier New",monospace;font-size:9pt" class="gmail_msg">-            error.SetErrorToErrno();</span></div>
<div class="gmail_msg"><span style="font-family:"Courier New",monospace;font-size:9pt" class="gmail_msg">-        }</span></div>
<div class="gmail_msg"><span style="font-family:"Courier New",monospace;font-size:9pt" class="gmail_msg">-        else</span></div>
<div class="gmail_msg"><span style="font-family:"Courier New",monospace;font-size:9pt" class="gmail_msg">-        {</span></div>
<div class="gmail_msg"><span style="font-family:"Courier New",monospace;font-size:9pt" class="gmail_msg">-            offset += bytes_read;</span></div>
<div class="gmail_msg"><span style="font-family:"Courier New",monospace;font-size:9pt" class="gmail_msg">-            num_bytes = bytes_read;</span></div>
<div class="gmail_msg"><span style="font-family:"Courier New",monospace;font-size:9pt" class="gmail_msg">+            if (bytes_read < 0)</span></div>
<div class="gmail_msg"><span style="font-family:"Courier New",monospace;font-size:9pt" class="gmail_msg">+            {</span></div>
<div class="gmail_msg"><span style="font-family:"Courier New",monospace;font-size:9pt" class="gmail_msg">+                num_bytes = 0;</span></div>
<div class="gmail_msg"><span style="font-family:"Courier New",monospace;font-size:9pt" class="gmail_msg">+                error.SetErrorToErrno();</span></div>
<div class="gmail_msg"><span style="font-family:"Courier New",monospace;font-size:9pt" class="gmail_msg">+                break;</span></div>
<div class="gmail_msg"><span style="font-family:"Courier New",monospace;font-size:9pt" class="gmail_msg">+            }</span></div>
<div class="gmail_msg"><span style="font-family:"Courier New",monospace;font-size:9pt" class="gmail_msg">+            else if (bytes_read == 0)</span></div>
<div class="gmail_msg"><span style="font-family:"Courier New",monospace;font-size:9pt" class="gmail_msg">+            {</span></div>
<div class="gmail_msg"><span style="font-family:"Courier New",monospace;font-size:9pt" class="gmail_msg">+                break;</span></div>
<div class="gmail_msg"><span style="font-family:"Courier New",monospace;font-size:9pt" class="gmail_msg">+            }</span></div>
<div class="gmail_msg"><span style="font-family:"Courier New",monospace;font-size:9pt" class="gmail_msg">+            else</span></div>
<div class="gmail_msg"><span style="font-family:"Courier New",monospace;font-size:9pt" class="gmail_msg">+            {</span></div>
<div class="gmail_msg"><span style="font-family:"Courier New",monospace;font-size:9pt" class="gmail_msg">+                offset += bytes_read;</span></div>
<div class="gmail_msg"><span style="font-family:"Courier New",monospace;font-size:9pt" class="gmail_msg">+                num_bytes += bytes_read;</span></div>
<div class="gmail_msg"><span style="font-family:"Courier New",monospace;font-size:9pt" class="gmail_msg">+                bytes_left -= bytes_read;</span></div>
<div class="gmail_msg"><span style="font-family:"Courier New",monospace;font-size:9pt" class="gmail_msg">+                pos += bytes_read;</span></div>
<div class="gmail_msg"><span style="font-family:"Courier New",monospace;font-size:9pt" class="gmail_msg">+            }</span></div>
<div class="gmail_msg"><span style="font-family:"Courier New",monospace;font-size:9pt" class="gmail_msg">         }</span></div>
<div class="gmail_msg"><span style="font-family:"Courier New",monospace;font-size:9pt" class="gmail_msg">     }</span></div>
<div class="gmail_msg"><span style="font-family:"Courier New",monospace;font-size:9pt" class="gmail_msg">     else</span></div>
<div class="gmail_msg"><br class="gmail_msg">
</div>
<br class="gmail_msg">
<p class="gmail_msg"></p>
<p class="gmail_msg"><br class="gmail_msg">
</p>
<div id="m_7052815235107701521Signature" class="gmail_msg">
<p class="gmail_msg">Sent from <a href="http://aka.ms/weboutlook" id="m_7052815235107701521LPNoLP" class="gmail_msg" target="_blank">Outlook</a><br class="gmail_msg">
</p>
</div>
<br class="gmail_msg">
<br class="gmail_msg">
<div style="color:rgb(0,0,0)" class="gmail_msg">
<div class="gmail_msg">
<hr style="display:inline-block;width:98%" class="gmail_msg">
<div id="m_7052815235107701521x_divRplyFwdMsg" dir="ltr" class="gmail_msg"><font face="Calibri, sans-serif" color="#000000" style="font-size:11pt" class="gmail_msg"><b class="gmail_msg">From:</b> Greg Clayton <<a href="mailto:gclayton@apple.com" class="gmail_msg" target="_blank">gclayton@apple.com</a>><br class="gmail_msg">
<b class="gmail_msg">Sent:</b> Monday, October 17, 2016 12:39 PM<br class="gmail_msg">
<b class="gmail_msg">To:</b> Eugene Birukov<br class="gmail_msg">
<b class="gmail_msg">Cc:</b> LLDB<br class="gmail_msg">
<b class="gmail_msg">Subject:</b> Re: [lldb-dev] File::Read does not read everything</font>
<div class="gmail_msg"> </div>
</div>
</div></div></div></div><div dir="ltr" class="gmail_msg"><div id="m_7052815235107701521divtagdefaultwrapper" style="font-size:12pt;color:#000000;font-family:Calibri,Arial,Helvetica,sans-serif" class="gmail_msg"><div style="color:rgb(0,0,0)" class="gmail_msg">
<font size="2" class="gmail_msg"><span style="font-size:10pt" class="gmail_msg">
<div class="m_7052815235107701521PlainText gmail_msg">It is probably best to make the code loop as long as "bytes_reads > 0" and we haven't read "num_bytes" yet. The darwin kernel has a INT32_MAX read size which gets set to MAX_READ_SIZE, but we need to do that because if you try to read
 more than that it reads nothing. So MAX_READ_SIZE is more for the case where the read will outright fail if given a byte size that is too large. Feel free to submit a patch that can keep calling pread correctly in a loop as long as bytes_read > 0.<br class="gmail_msg">
<br class="gmail_msg">
Greg<br class="gmail_msg">
<br class="gmail_msg">
> On Oct 17, 2016, at 12:20 PM, Eugene Birukov via lldb-dev <<a href="mailto:lldb-dev@lists.llvm.org" class="gmail_msg" target="_blank">lldb-dev@lists.llvm.org</a>> wrote:<br class="gmail_msg">
> <br class="gmail_msg">
> Hello,<br class="gmail_msg">
> <br class="gmail_msg">
> I am using LLDB 3.9 on Linux Ubuntu. I am loading a 5GiB core which is located on Windows file share mounted on Linux via mount.cifs. I see that we successfully allocated memory and are trying to fill it in one read. Unfortunately pread returns 2GiB and we
 never check for short read here.<br class="gmail_msg">
> <br class="gmail_msg">
> I think we could combine this code with previous block "#if defined (MAX_READ_SIZE)" if we simply check for short read here (bytes_read too small) and loop until all the buffer is filled.<br class="gmail_msg">
> <br class="gmail_msg">
> Thanks,<br class="gmail_msg">
> Eugene<br class="gmail_msg">
> <br class="gmail_msg">
> #ifndef _WIN32<br class="gmail_msg">
>     int fd = GetDescriptor();<br class="gmail_msg">
>     if (fd != kInvalidDescriptor)<br class="gmail_msg">
>     {<br class="gmail_msg">
>         ssize_t bytes_read = -1;<br class="gmail_msg">
>         do<br class="gmail_msg">
>         {<br class="gmail_msg">
>             bytes_read = ::pread (fd, buf, num_bytes, offset);<br class="gmail_msg">
>         } while (bytes_read < 0 && errno == EINTR);<br class="gmail_msg">
> <br class="gmail_msg">
>         if (bytes_read < 0)<br class="gmail_msg">
>         {<br class="gmail_msg">
>             num_bytes = 0;<br class="gmail_msg">
>             error.SetErrorToErrno();<br class="gmail_msg">
>         }<br class="gmail_msg">
>         else<br class="gmail_msg">
>         {<br class="gmail_msg">
>             offset += bytes_read;<br class="gmail_msg">
>             num_bytes = bytes_read;<br class="gmail_msg">
>         }<br class="gmail_msg">
>     }<br class="gmail_msg">
> <br class="gmail_msg">
> Sent from Outlook<br class="gmail_msg">
> _______________________________________________<br class="gmail_msg">
> lldb-dev mailing list<br class="gmail_msg">
> <a href="mailto:lldb-dev@lists.llvm.org" class="gmail_msg" target="_blank">lldb-dev@lists.llvm.org</a><br class="gmail_msg">
> <a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-dev" class="gmail_msg" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-dev</a><br class="gmail_msg">
<br class="gmail_msg">
</div>
</span></font></div></div></div>

_______________________________________________<br class="gmail_msg">
lldb-dev mailing list<br class="gmail_msg">
<a href="mailto:lldb-dev@lists.llvm.org" class="gmail_msg" target="_blank">lldb-dev@lists.llvm.org</a><br class="gmail_msg">
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-dev" rel="noreferrer" class="gmail_msg" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-dev</a><br class="gmail_msg">
</blockquote></div>