logcat: add hidden --debug flag and cleanup

Allow us to debug corrupted log messages. Fix liblog to propagate
errors correctly and repair a gtest that failed.

Test: liblog-unit-tests --gtest_filter=liblog.__android_log_bswrite_and_print___max
      logcat -b events --debug -t 50
Bug: 32903864
Change-Id: Ib4eb9f466777cd23b8b54728d36354590d07869a
diff --git a/liblog/logprint.c b/liblog/logprint.c
index 4ff7e01..da80e36 100644
--- a/liblog/logprint.c
+++ b/liblog/logprint.c
@@ -1055,6 +1055,7 @@
         outRemaining--;
         /* pretend we ate all the data to prevent log stutter */
         inCount = 0;
+        if (result > 0) result = 0;
     }
 
     /* eat the silly terminating '\n' */
@@ -1078,7 +1079,7 @@
 
     entry->message = messageBuf;
 
-    return 0;
+    return result;
 }
 
 /*
diff --git a/liblog/tests/liblog_test.cpp b/liblog/tests/liblog_test.cpp
index 9c09523..70c7a48 100644
--- a/liblog/tests/liblog_test.cpp
+++ b/liblog/tests/liblog_test.cpp
@@ -328,6 +328,9 @@
             EXPECT_TRUE(NULL != logformat);
             AndroidLogEntry entry;
             char msgBuf[1024];
+            if (length != total) {
+                fprintf(stderr, "Expect \"Binary log entry conversion failed\"\n");
+            }
             int processBinaryLogBuffer = android_log_processBinaryLogBuffer(
                 &log_msg.entry_v1, &entry, NULL, msgBuf, sizeof(msgBuf));
             EXPECT_EQ((length == total) ? 0 : -1, processBinaryLogBuffer);