Subject: [PATCH] Don't truncate backtraces

From: Robert Vollmert <[email-masked]>
Date: Mon, 15 Jul 2019 22:29:19 +0200

* module/system/repl/debug.scm (print-frame): Print full object if
width keyword is #f.
* libguile/backtrace.c (display_backtrace_body): Call print-frames
with #:width #f.
---

This change was prompted by recent discussion on the Guix lists:
  https://lists.gnu.org/archive/html/guix-devel/2019-07/msg00207.html
In Guix, the truncation of stack traces frequently obscures
important information due to the long filenames.

Apologies if this misses some obvious things, I'm not particularly
at home in the Guile sources. Let me know, happy to adapt!

Cheers
Robert

 libguile/backtrace.c         |  6 ++++--
 module/system/repl/debug.scm | 13 +++++++++----
 2 files changed, 13 insertions(+), 6 deletions(-)

diff --git a/libguile/backtrace.c b/libguile/backtrace.c
index 4a19d4b8a..4d0b4ab94 100644
--- a/libguile/backtrace.c
+++ b/libguile/backtrace.c
@@ -77,6 +77,7 @@ boot_print_exception (SCM port, SCM frame, SCM key, SCM args)
 static SCM print_exception_var;
 static SCM print_frame_var;
 static SCM kw_count;
+static SCM kw_width;
 static SCM print_frames_var;
 static SCM frame_to_stack_vector_var;
 
@@ -99,6 +100,7 @@ static void
 init_print_frames_var_and_frame_to_stack_vector_var (void)
 {
   kw_count = scm_from_latin1_keyword ("count");
+  kw_width = scm_from_latin1_keyword ("width");
   print_frames_var =
     scm_c_public_variable ("system repl debug", "print-frames");
   frame_to_stack_vector_var =
@@ -236,8 +238,8 @@ display_backtrace_body (struct display_backtrace_args *a)
                        scm_stack_ref (a->stack, a->first));
 
   /* FIXME: highlight_objects */
-  scm_call_4 (scm_variable_ref (print_frames_var), frames, a->port,
-              kw_count, a->depth);
+  scm_call_6 (scm_variable_ref (print_frames_var), frames, a->port,
+              kw_count, a->depth, kw_width, SCM_BOOL_F);
   
   return SCM_UNSPECIFIED;
 }
diff --git a/module/system/repl/debug.scm b/module/system/repl/debug.scm
index 383d37921..7422bf980 100644
--- a/module/system/repl/debug.scm
+++ b/module/system/repl/debug.scm
@@ -135,10 +135,15 @@
          (col (and=> source source:column)))
     (if (and file (not (equal? file (source:pretty-file last-source))))
         (format port "~&In ~a:~&" file))
-    (format port "~9@a~:[~*~3_~;~3d~] ~v:@y~%"
-            (if line (format #f "~a:~a" line col) "")
-            index index width
-            (frame-call-representation frame #:top-frame? (zero? index)))
+    (if width
+      (format port "~9@a~:[~*~3_~;~3d~] ~v:@y~%"
+              (if line (format #f "~a:~a" line col) "")
+              index index width
+              (frame-call-representation frame #:top-frame? (zero? index)))
+      (format port "~9@a~:[~*~3_~;~3d~] ~a~%"
+              (if line (format #f "~a:~a" line col) "")
+              index index
+              (frame-call-representation frame #:top-frame? (zero? index))))
     (if full?
         (print-locals frame #:width width
                       #:per-line-prefix "     "))))
-- 
2.20.1 (Apple Git-117)