[PATCH] D59320: [HWASan] Use less Printf() calls in register dump.

Mitch Phillips via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Mar 13 13:24:40 PDT 2019


hctim created this revision.
hctim added reviewers: eugenis, pcc.
Herald added subscribers: llvm-commits, Sanitizers, kubamracek.
Herald added projects: Sanitizers, LLVM.

Explicitly print 4 registers/line in each iteration during register
dump. Reduces logcat spam as we get a single logcat message per call to
Printf(), even if the output isn't newline-terminated. This brings the
output format in logcat closer to that of the normal textual dump.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D59320

Files:
  compiler-rt/lib/hwasan/hwasan_report.cpp


Index: compiler-rt/lib/hwasan/hwasan_report.cpp
===================================================================
--- compiler-rt/lib/hwasan/hwasan_report.cpp
+++ compiler-rt/lib/hwasan/hwasan_report.cpp
@@ -442,20 +442,30 @@
 static const char *kDoubleSpace = "  ";
 static const char *kSingleSpace = " ";
 void ReportRegisters(uptr *frame, uptr pc) {
-  Printf("Registers where the failure occurred (pc %p):", pc);
-
-  for (unsigned i = 0; i <= 30; i++) {
-    if (i % 4 == 0)
-      Printf("\n  ");
+  Printf("Registers where the failure occurred (pc %p):\n", pc);
 
+  // We explicitly print a single line (4 registers/line) each iteration to
+  // reduce the amount of logcat error messages printed. Each Printf() will
+  // result in a new logcat line, irrespective of whether a newline is present,
+  // and so we wish to reduce the number of Printf() calls we have to make.
+  for (unsigned i = 0; i <= 24; i += 4) {
     // Note - manually inserting a double or single space here based on the
     // number of digits in the register name, as our sanitizer Printf does not
     // support padding where the content is left aligned (i.e. the format
     // specifier "%-2d" will CHECK fail).
-    Printf("  x%d%s%016llx", i, (i < 10) ? kDoubleSpace : kSingleSpace,
-           frame[i]);
+    Printf("    x%d%s%016llx"
+           "  x%d%s%016llx"
+           "  x%d%s%016llx"
+           "  x%d%s%016llx\n",
+           i + 0, (i + 0 < 10) ? kDoubleSpace : kSingleSpace, frame[i + 0],
+           i + 1, (i + 1 < 10) ? kDoubleSpace : kSingleSpace, frame[i + 1],
+           i + 2, (i + 2 < 10) ? kDoubleSpace : kSingleSpace, frame[i + 2],
+           i + 3, (i + 3 < 10) ? kDoubleSpace : kSingleSpace, frame[i + 3]);
   }
-  Printf("\n");
+  Printf("    x%d %016llx"
+         "  x%d %016llx"
+         "  x%d %016llx\n",
+         28, frame[28], 29, frame[29], 30, frame[30]);
 }
 
 }  // namespace __hwasan


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D59320.190486.patch
Type: text/x-patch
Size: 1921 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190313/6fb520cd/attachment.bin>


More information about the llvm-commits mailing list