guile-cvs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

guile/guile-core/libguile backtrace.c


From: Marius Vollmer
Subject: guile/guile-core/libguile backtrace.c
Date: Thu, 24 May 2001 17:19:36 -0700

CVSROOT:        /cvs
Module name:    guile
Changes by:     Marius Vollmer <address@hidden> 01/05/24 17:19:36

Modified files:
        guile-core/libguile: backtrace.c 

Log message:
        Include "libguile/filesys.h".
        (sym_base, display_backtrace_get_file_line,
        display_backtrace_file, display_backtrace_file_and_line): New.
        (display_frame): Call display_backtrace_file_and_line if that is
        requested.
        (display_backtrace_body): Call scm_display_backtrace_file if
        requested.

CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/guile/guile-core/libguile/backtrace.c.diff?cvsroot=OldCVS&tr1=1.64&tr2=1.65&r1=text&r2=text

Patches:
Index: guile/guile-core/libguile/backtrace.c
diff -u guile/guile-core/libguile/backtrace.c:1.64 
guile/guile-core/libguile/backtrace.c:1.65
--- guile/guile-core/libguile/backtrace.c:1.64  Wed May 23 17:50:43 2001
+++ guile/guile-core/libguile/backtrace.c       Thu May 24 17:19:36 2001
@@ -66,6 +66,7 @@
 
 #include "libguile/validate.h"
 #include "libguile/backtrace.h"
+#include "libguile/filesys.h"
 
 /* {Error reporting and backtraces}
  * (A first approximation.)
@@ -436,7 +437,89 @@
 }
 #undef FUNC_NAME
 
+SCM_SYMBOL (sym_base, "base");
+
+static void
+display_backtrace_get_file_line (SCM frame, SCM *file, SCM *line)
+{
+  SCM source = SCM_FRAME_SOURCE (frame);
+  *file = SCM_MEMOIZEDP (source) ? scm_source_property (source, 
scm_sym_filename) : SCM_BOOL_F;
+  *line = (SCM_MEMOIZEDP (source)) ? scm_source_property (source, 
scm_sym_line) : SCM_BOOL_F;
+}
+
 static void
+display_backtrace_file (frame, last_file, port, pstate)
+     SCM frame;
+     SCM *last_file;
+     SCM port;
+     scm_print_state *pstate;
+{
+  SCM file, line;
+
+  display_backtrace_get_file_line (frame, &file, &line);
+
+  if (file == *last_file)
+    return;
+
+  *last_file = file;
+
+  scm_puts ("In ", port);
+  if (file == SCM_BOOL_F)
+    if (line == SCM_BOOL_F)
+      scm_puts ("unknown file", port);
+    else
+      scm_puts ("current input", port);
+  else
+    {
+      pstate->writingp = 0;
+      scm_iprin1 (file, port, pstate);
+      pstate->writingp = 1;
+    }
+  scm_puts (":\n", port);
+}
+
+static void
+display_backtrace_file_and_line (SCM frame, SCM port, scm_print_state *pstate)
+{
+  SCM file, line;
+
+  display_backtrace_get_file_line (frame, &file, &line);
+
+  if (SCM_EQ_P (SCM_SHOW_FILE_NAME, sym_base))
+    {
+      if (file == SCM_BOOL_F)
+       {
+         if (line == SCM_BOOL_F)
+           scm_putc ('?', port);
+         else
+           scm_puts ("<stdin>", port);
+       }
+      else
+       {
+         pstate -> writingp = 0;
+         scm_iprin1 (SCM_STRINGP (file) ? scm_basename (file, SCM_UNDEFINED) : 
file,
+                     port, pstate);
+         pstate -> writingp = 1;
+       }
+
+      scm_putc (':', port);
+    }
+  else if (line != SCM_BOOL_F)
+    {
+      int i, j=0;
+      for (i = SCM_INUM (line)+1; i > 0; i = i/10, j++)
+       ;
+      indent (4-j, port);
+    }
+
+  if (line == SCM_BOOL_F)
+    scm_puts ("   ?", port);
+  else
+    scm_intprint (SCM_INUM (line) + 1, 10, port);
+  scm_puts (": ", port);
+}
+
+static void
 display_frame (SCM frame,int nfield,int indentation,SCM sport,SCM 
port,scm_print_state *pstate)
 {
   int n, i, j;
@@ -448,6 +531,10 @@
       scm_puts ("...\n", port);
     }
 
+  /* display file name and line number */
+  if (SCM_NFALSEP (SCM_SHOW_FILE_NAME))
+    display_backtrace_file_and_line (frame, port, pstate);
+
   /* Check size of frame number. */
   n = SCM_FRAME_NUMBER (frame);
   for (i = 0, j = n; j > 0; ++i) j /= 10;
@@ -509,6 +596,7 @@
   int n_frames, beg, end, n, i, j;
   int nfield, indent_p, indentation;
   SCM frame, sport, print_state;
+  SCM last_file;
   scm_print_state *pstate;
 
   a->port = SCM_COERCE_OUTPORT (a->port);
@@ -595,13 +683,17 @@
   /* Print frames. */
   frame = scm_stack_ref (a->stack, SCM_MAKINUM (beg));
   indentation = 1;
-  display_frame (frame, nfield, indentation, sport, a->port, pstate);
-  for (i = 1; i < n; ++i)
+  last_file = SCM_UNDEFINED;
+  for (i = 0; i < n; ++i)
     {
+      if (!SCM_EQ_P (SCM_SHOW_FILE_NAME, sym_base))
+       display_backtrace_file (frame, &last_file, a->port, pstate);
+
+      display_frame (frame, nfield, indentation, sport, a->port, pstate);
       if (indent_p && SCM_FRAME_EVAL_ARGS_P (frame))
        ++indentation;
-      frame = SCM_BACKWARDS_P ? SCM_FRAME_PREV (frame) : SCM_FRAME_NEXT 
(frame);
-      display_frame (frame, nfield, indentation, sport, a->port, pstate);
+      frame = (SCM_BACKWARDS_P ? 
+              SCM_FRAME_PREV (frame) : SCM_FRAME_NEXT (frame));
     }
 
   scm_remember_upto_here_1 (print_state);



reply via email to

[Prev in Thread] Current Thread [Next in Thread]