]> granicus.if.org Git - nethack/commitdiff
panictrace_libc
authorPatR <rankin@nethack.org>
Mon, 2 Mar 2020 23:05:06 +0000 (15:05 -0800)
committerPatR <rankin@nethack.org>
Mon, 2 Mar 2020 23:05:06 +0000 (15:05 -0800)
Try to make the tracebacks generated via PANICTRACE's libc method
be more readable.  There tends to be a lot of blank space in the
middle of lines, depending on the length of the program's or
libraries' file names, which can make lines wrap and the whole
thing sometimes be harder to make out.  Narrow it by squeezing out
some spaces from each line before writing to reduce the chance of
line wrapping.  That isn't guaranteed to make things ledgible but
seems to help quite a bit.  Also, force the line number inserted
by nethack to be two digits so when spanning from line 9 to line 10
it doesn't cause the field positions to shift by a column.  (Using
'#panic' doesn't have enough stack frames to illustrate that.)

I think the original libc formatting was designed for the address
column to hold a 32-bit value ('0x' prefix and 8 hex digits), and
eventually extending that to handle 64 bits ('0x' prefix and 16 hex
digits) made things wider than intended.  But the gradual increase
in the length of function names we use is also a factor.

src/end.c

index a0643732368523f2f5b053c67bbf483b2f668d0c..884ce05e883eca70c247d64d2e209f7f2f3f10f8 100644 (file)
--- a/src/end.c
+++ b/src/end.c
@@ -1,4 +1,4 @@
-/* NetHack 3.6 end.c   $NHDT-Date: 1583023462 2020/03/01 00:44:22 $  $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.207 $ */
+/* NetHack 3.6 end.c   $NHDT-Date: 1583190253 2020/03/02 23:04:13 $  $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.208 $ */
 /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
 /*-Copyright (c) Robert Patrick Rankin, 2012. */
 /* NetHack may be freely redistributed.  See license for details. */
@@ -195,13 +195,17 @@ NH_panictrace_libc()
 #ifdef PANICTRACE_LIBC
     void *bt[20];
     size_t count, x;
-    char **info;
+    char **info, buf[BUFSZ];
 
     raw_print("Generating more information you may report:\n");
     count = backtrace(bt, SIZE(bt));
     info = backtrace_symbols(bt, count);
     for (x = 0; x < count; x++) {
-        raw_printf("[%lu] %s", (unsigned long) x, info[x]);
+        copynchars(buf, info[x], (int) sizeof buf - 1);
+        /* try to remove up to 16 blank spaces by removing 8 twice */
+        (void) strsubst(buf, "        ", "");
+        (void) strsubst(buf, "        ", "");
+        raw_printf("[%02lu] %s", (unsigned long) x, buf);
     }
     /* free(info);   -- Don't risk it. */
     return TRUE;