~pali/llvm/compiler-rt-trunk

« back to all changes in this revision

Viewing changes to lib/sanitizer_common/sanitizer_fuchsia.cc

  • Committer: jakehehrlich
  • Date: 2018-05-23 22:27:12 UTC
  • Revision ID: svn-v4:91177308-0d34-0410-b5e6-96231b3b80d8:compiler-rt/trunk:333136
[fuchsia] Add line buffering in RawWrite

This change causes RawWrite to buffer upto 128 bytes or until
a line is reached. This helps group calls into more readable
lines.

Show diffs side-by-side

added added

removed removed

Lines of Context:
407
407
}
408
408
 
409
409
void RawWrite(const char *buffer) {
410
 
  __sanitizer_log_write(buffer, internal_strlen(buffer));
 
410
  constexpr size_t size = 128;
 
411
  static _Thread_local char line[size];
 
412
  static _Thread_local size_t lastLineEnd = 0;
 
413
  static _Thread_local size_t cur = 0;
 
414
 
 
415
  while (*buffer) {
 
416
    if (cur >= size) {
 
417
      if (lastLineEnd == 0)
 
418
        lastLineEnd = size;
 
419
      __sanitizer_log_write(line, lastLineEnd);
 
420
      internal_memmove(line, line + lastLineEnd, cur - lastLineEnd);
 
421
      cur = cur - lastLineEnd;
 
422
      lastLineEnd = 0;
 
423
    }
 
424
    if (*buffer == '\n')
 
425
      lastLineEnd = cur + 1;
 
426
    line[cur++] = *buffer++;
 
427
  }
 
428
  // Flush all complete lines before returning.
 
429
  if (lastLineEnd != 0) {
 
430
    __sanitizer_log_write(line, lastLineEnd);
 
431
    internal_memmove(line, line + lastLineEnd, cur - lastLineEnd);
 
432
    cur = cur - lastLineEnd;
 
433
    lastLineEnd = 0;
 
434
  }
411
435
}
412
436
 
413
437
void CatastrophicErrorWrite(const char *buffer, uptr length) {