Add log summary to tombstones

When the tombstones are uploaded to APR, they're truncated at 64KB.
This causes the log data, which is at the end, to be lost if the
process has more than about 12 threads (which many do).

This change adds the last few lines of the log right below the
report for the crashing thread, where we should be guaranteed to
keep it.

Also, clean up trailing newlines on log messages (which end up in
the tombstone), and don't print a "------- log" banner if there
aren't any messages in that log file (e.g. slog).

Also also, don't try to show_nearby_maps unless this is the crashing
thread.

Bug 5471955

Change-Id: Iaa4fd2fafbaeda2f20bb95f202177d7744a91f9d
diff --git a/debuggerd/arm/machine.c b/debuggerd/arm/machine.c
index fb0d6ba..d5efb79 100644
--- a/debuggerd/arm/machine.c
+++ b/debuggerd/arm/machine.c
@@ -56,6 +56,8 @@
 /*
  * If this isn't clearly a null pointer dereference, dump the
  * /proc/maps entries near the fault address.
+ *
+ * This only makes sense to do on the thread that crashed.
  */
 static void show_nearby_maps(int tfd, int pid, mapinfo *map)
 {
@@ -63,7 +65,8 @@
 
     memset(&si, 0, sizeof(si));
     if (ptrace(PTRACE_GETSIGINFO, pid, 0, &si)) {
-        _LOG(tfd, false, "cannot get siginfo: %s\n", strerror(errno));
+        _LOG(tfd, false, "cannot get siginfo for %d: %s\n",
+            pid, strerror(errno));
         return;
     }
     if (!signal_has_address(si.si_signo))
@@ -237,7 +240,9 @@
         }
     }
 
-    show_nearby_maps(tfd, pid, map);
+    if (at_fault) {
+        show_nearby_maps(tfd, pid, map);
+    }
 
     unsigned int p, end;
     unsigned int sp = r.ARM_sp;