From: Kostya Kortchinsky Date: Mon, 13 Apr 2020 14:25:35 +0000 (-0700) Subject: [scudo][standalone] Split logs on Android X-Git-Tag: llvmorg-12-init~9074 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=15754acc5985188509f5eefaefa308393759b822;p=platform%2Fupstream%2Fllvm.git [scudo][standalone] Split logs on Android Summary: The function used to log on Android will cut the message past a certain amount of characters, which mostly materializes when dumping the size class map on OOM. This change splits the log message at newline boundaries. Reviewers: pcc, cferris, hctim, eugenis Subscribers: #sanitizers, llvm-commits Tags: #sanitizers Differential Revision: https://reviews.llvm.org/D78018 --- diff --git a/compiler-rt/lib/scudo/standalone/linux.cpp b/compiler-rt/lib/scudo/standalone/linux.cpp index 040e1f0..0ab9683 100644 --- a/compiler-rt/lib/scudo/standalone/linux.cpp +++ b/compiler-rt/lib/scudo/standalone/linux.cpp @@ -171,6 +171,23 @@ extern "C" WEAK int async_safe_write_log(int pri, const char *tag, void outputRaw(const char *Buffer) { if (&async_safe_write_log) { constexpr s32 AndroidLogInfo = 4; + constexpr uptr MaxLength = 1024U; + char LocalBuffer[MaxLength]; + while (strlen(Buffer) > MaxLength) { + uptr P; + for (P = MaxLength - 1; P > 0; P--) { + if (Buffer[P] == '\n') { + memcpy(LocalBuffer, Buffer, P); + LocalBuffer[P] = '\0'; + async_safe_write_log(AndroidLogInfo, "scudo", LocalBuffer); + Buffer = &Buffer[P + 1]; + break; + } + } + // If no newline was found, just log the buffer. + if (P == 0) + break; + } async_safe_write_log(AndroidLogInfo, "scudo", Buffer); } else { write(2, Buffer, strlen(Buffer));