[scudo][standalone] Split logs on Android
authorKostya Kortchinsky <kostyak@google.com>
Mon, 13 Apr 2020 14:25:35 +0000 (07:25 -0700)
committerKostya Kortchinsky <kostyak@google.com>
Tue, 14 Apr 2020 18:29:57 +0000 (11:29 -0700)
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

compiler-rt/lib/scudo/standalone/linux.cpp

index 040e1f0..0ab9683 100644 (file)
@@ -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));