SCP: Assure that debug output is aways completely written via fwrite
Previously, the status returned by fwrite() while writing debug output was ignored and all debug output was presumed to be correctly written. This change tolerates incomplete writes performed by the C runtime and retries the remaining writes as long as the retries take. This change completely presumes that the C runtime fwrite() returns correct information when the data has not been completely written. That of course will likely depend on the OS level write function returning correct informatoin from the write() system call that fwrite() depends on. Timing concerns while emitting debug output have always been a problem since even composing any debug output is likely to be much more work than basic instruction execution off the current single instruction. Clock calibration probably will be fundamentally unreliable. As discussed in #957
This commit is contained in:
parent
267f2548a6
commit
ba5e18e963
1 changed files with 14 additions and 2 deletions
16
scp.c
16
scp.c
|
@ -13258,16 +13258,28 @@ size_t debug_line_bufsize = 0;
|
|||
size_t debug_line_offset = 0;
|
||||
size_t debug_line_count = 0;
|
||||
|
||||
static void _debug_fwrite_all (const char *buf, size_t len, FILE *f)
|
||||
{
|
||||
size_t len_written;
|
||||
|
||||
while (len > 0) {
|
||||
len_written = fwrite (buf, 1, len, f);
|
||||
len -= len_written;
|
||||
buf += len_written;
|
||||
errno = 0;
|
||||
}
|
||||
}
|
||||
|
||||
static void _debug_fwrite (const char *buf, size_t len)
|
||||
{
|
||||
size_t move_size;
|
||||
|
||||
if (sim_deb_buffer == NULL) {
|
||||
fwrite (buf, 1, len, sim_deb); /* output now. */
|
||||
_debug_fwrite_all (buf, len, sim_deb); /* output now. */
|
||||
return;
|
||||
}
|
||||
if ((sim_deb == stdout) && (!sim_is_running))
|
||||
fwrite (buf, 1, len, stdout); /* output now. */
|
||||
_debug_fwrite_all (buf, len, stdout); /* output now. */
|
||||
while (len > 0) {
|
||||
if (sim_debug_buffer_offset + len <= sim_deb_buffer_size)
|
||||
move_size = len;
|
||||
|
|
Loading…
Add table
Reference in a new issue