<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css" style="display:none;"><!-- P {margin-top:0;margin-bottom:0;} --></style>
</head>
<body dir="ltr">
<div id="divtagdefaultwrapper" style="font-size:12pt;color:#000000;font-family:Calibri,Arial,Helvetica,sans-serif;">
<p>Here is what I am running now:</p>
<p><br>
</p>
<p></p>
<div><span style="font-family: "Courier New", monospace; font-size: 9pt;">diff --git a/source/Host/common/File.cpp b/source/Host/common/File.cpp</span></div>
<div><span style="font-family: "Courier New", monospace; font-size: 9pt;">index 89587a9..a4ac25e 100644</span></div>
<div><span style="font-family: "Courier New", monospace; font-size: 9pt;">--- a/source/Host/common/File.cpp</span></div>
<div><span style="font-family: "Courier New", monospace; font-size: 9pt;">+++ b/source/Host/common/File.cpp</span></div>
<div><span style="font-family: "Courier New", monospace; font-size: 9pt;">@@ -771,21 +771,34 @@ File::Read (void *buf, size_t &num_bytes, off_t &offset)</span></div>
<div><span style="font-family: "Courier New", monospace; font-size: 9pt;"> int fd = GetDescriptor();</span></div>
<div><span style="font-family: "Courier New", monospace; font-size: 9pt;"> if (fd != kInvalidDescriptor)</span></div>
<div><span style="font-family: "Courier New", monospace; font-size: 9pt;"> {</span></div>
<div><span style="font-family: "Courier New", monospace; font-size: 9pt;">- ssize_t bytes_read = -1;</span></div>
<div><span style="font-family: "Courier New", monospace; font-size: 9pt;">- do</span></div>
<div><span style="font-family: "Courier New", monospace; font-size: 9pt;">+ size_t bytes_left = num_bytes;</span></div>
<div><span style="font-family: "Courier New", monospace; font-size: 9pt;">+ num_bytes = 0;</span></div>
<div><span style="font-family: "Courier New", monospace; font-size: 9pt;">+ char *pos = (char*)buf;</span></div>
<div><span style="font-family: "Courier New", monospace; font-size: 9pt;">+ while (bytes_left > 0)</span></div>
<div><span style="font-family: "Courier New", monospace; font-size: 9pt;"> {</span></div>
<div><span style="font-family: "Courier New", monospace; font-size: 9pt;">- bytes_read = ::pread (fd, buf, num_bytes, offset);</span></div>
<div><span style="font-family: "Courier New", monospace; font-size: 9pt;">- } while (bytes_read < 0 && errno == EINTR);</span></div>
<div><span style="font-family: "Courier New", monospace; font-size: 9pt;">+ ssize_t bytes_read = -1;</span></div>
<div><span style="font-family: "Courier New", monospace; font-size: 9pt;">+ do</span></div>
<div><span style="font-family: "Courier New", monospace; font-size: 9pt;">+ {</span></div>
<div><span style="font-family: "Courier New", monospace; font-size: 9pt;">+ bytes_read = ::pread (fd, pos, bytes_left, offset);</span></div>
<div><span style="font-family: "Courier New", monospace; font-size: 9pt;">+ } while (bytes_read < 0 && errno == EINTR);</span></div>
<div><br>
</div>
<div><span style="font-family: "Courier New", monospace; font-size: 9pt;">- if (bytes_read < 0)</span></div>
<div><span style="font-family: "Courier New", monospace; font-size: 9pt;">- {</span></div>
<div><span style="font-family: "Courier New", monospace; font-size: 9pt;">- num_bytes = 0;</span></div>
<div><span style="font-family: "Courier New", monospace; font-size: 9pt;">- error.SetErrorToErrno();</span></div>
<div><span style="font-family: "Courier New", monospace; font-size: 9pt;">- }</span></div>
<div><span style="font-family: "Courier New", monospace; font-size: 9pt;">- else</span></div>
<div><span style="font-family: "Courier New", monospace; font-size: 9pt;">- {</span></div>
<div><span style="font-family: "Courier New", monospace; font-size: 9pt;">- offset += bytes_read;</span></div>
<div><span style="font-family: "Courier New", monospace; font-size: 9pt;">- num_bytes = bytes_read;</span></div>
<div><span style="font-family: "Courier New", monospace; font-size: 9pt;">+ if (bytes_read < 0)</span></div>
<div><span style="font-family: "Courier New", monospace; font-size: 9pt;">+ {</span></div>
<div><span style="font-family: "Courier New", monospace; font-size: 9pt;">+ num_bytes = 0;</span></div>
<div><span style="font-family: "Courier New", monospace; font-size: 9pt;">+ error.SetErrorToErrno();</span></div>
<div><span style="font-family: "Courier New", monospace; font-size: 9pt;">+ break;</span></div>
<div><span style="font-family: "Courier New", monospace; font-size: 9pt;">+ }</span></div>
<div><span style="font-family: "Courier New", monospace; font-size: 9pt;">+ else if (bytes_read == 0)</span></div>
<div><span style="font-family: "Courier New", monospace; font-size: 9pt;">+ {</span></div>
<div><span style="font-family: "Courier New", monospace; font-size: 9pt;">+ break;</span></div>
<div><span style="font-family: "Courier New", monospace; font-size: 9pt;">+ }</span></div>
<div><span style="font-family: "Courier New", monospace; font-size: 9pt;">+ else</span></div>
<div><span style="font-family: "Courier New", monospace; font-size: 9pt;">+ {</span></div>
<div><span style="font-family: "Courier New", monospace; font-size: 9pt;">+ offset += bytes_read;</span></div>
<div><span style="font-family: "Courier New", monospace; font-size: 9pt;">+ num_bytes += bytes_read;</span></div>
<div><span style="font-family: "Courier New", monospace; font-size: 9pt;">+ bytes_left -= bytes_read;</span></div>
<div><span style="font-family: "Courier New", monospace; font-size: 9pt;">+ pos += bytes_read;</span></div>
<div><span style="font-family: "Courier New", monospace; font-size: 9pt;">+ }</span></div>
<div><span style="font-family: "Courier New", monospace; font-size: 9pt;"> }</span></div>
<div><span style="font-family: "Courier New", monospace; font-size: 9pt;"> }</span></div>
<div><span style="font-family: "Courier New", monospace; font-size: 9pt;"> else</span></div>
<div><br>
</div>
<br>
<p></p>
<p><br>
</p>
<div id="Signature">
<p>Sent from <a href="http://aka.ms/weboutlook" id="LPNoLP">Outlook</a><br>
</p>
</div>
<br>
<br>
<div style="color: rgb(0, 0, 0);">
<div>
<hr tabindex="-1" style="display:inline-block; width:98%">
<div id="x_divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" color="#000000" style="font-size:11pt"><b>From:</b> Greg Clayton <gclayton@apple.com><br>
<b>Sent:</b> Monday, October 17, 2016 12:39 PM<br>
<b>To:</b> Eugene Birukov<br>
<b>Cc:</b> LLDB<br>
<b>Subject:</b> Re: [lldb-dev] File::Read does not read everything</font>
<div> </div>
</div>
</div>
<font size="2"><span style="font-size:10pt;">
<div class="PlainText">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>
<br>
Greg<br>
<br>
> On Oct 17, 2016, at 12:20 PM, Eugene Birukov via lldb-dev <lldb-dev@lists.llvm.org> wrote:<br>
> <br>
> Hello,<br>
> <br>
> 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>
> <br>
> 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>
> <br>
> Thanks,<br>
> Eugene<br>
> <br>
> #ifndef _WIN32<br>
> int fd = GetDescriptor();<br>
> if (fd != kInvalidDescriptor)<br>
> {<br>
> ssize_t bytes_read = -1;<br>
> do<br>
> {<br>
> bytes_read = ::pread (fd, buf, num_bytes, offset);<br>
> } while (bytes_read < 0 && errno == EINTR);<br>
> <br>
> if (bytes_read < 0)<br>
> {<br>
> num_bytes = 0;<br>
> error.SetErrorToErrno();<br>
> }<br>
> else<br>
> {<br>
> offset += bytes_read;<br>
> num_bytes = bytes_read;<br>
> }<br>
> }<br>
> <br>
> Sent from Outlook<br>
> _______________________________________________<br>
> lldb-dev mailing list<br>
> lldb-dev@lists.llvm.org<br>
> <a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-dev">http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-dev</a><br>
<br>
</div>
</span></font></div>
</div>
</body>
</html>