[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[patch] File names and line numbers in backtrace
From: |
Daniel Skarda |
Subject: |
[patch] File names and line numbers in backtrace |
Date: |
21 May 2001 18:41:49 +0200 |
User-agent: |
Gnus/5.0808 (Gnus v5.8.8) Emacs/20.7 |
Hello,
sometime ago I found that output of backtrace command is not too informative.
It does show the code - but it does not show _where_ the code is. So I tried to
change backtrace to write information about file name and line number.
`diff' against guile-core from CVS is attached to the end of this mail. It
extends debug-options command with following options:
show-line-number
show-base-file-name - full path is sometimes long. This options turns on
showing only base file name.
show-full-file-name - show file name with full path only once, when
evaluation "enters" the file.
I am not sure if my patch does everything in the correct way, but I hope that
at least it inspires some guile hacker to write/apply patch with similar (or
better) functionality.
Best regards,
Dan Skarda
------------------------------
guile> (debug-options)
(show-base-file-name show-line-number ...)
guile> (format "~Y" '(foo bar))
Backtrace:
0* <stdin>:15 [format:format "~Y" (foo bar)]
1 format.scm:149 (let ((args (if # # ...))) (set! format:args args) ...)
...
2 format.scm:169 [call-with-output-string #<procedure #f (port)>]
3* ?:? [#<procedure #f (port)> #<output: string 80e5e88>]
4* format.scm:170 [format:out #<output: string 80e5e88> "~Y" ((foo bar))]
5 format.scm:178 (let ((arg-pos #) (arg-len #)) (cond (# # # #) (# # # #)
(else # #t)))
6* format.scm:178 [format:format-work "~Y" ((foo bar))]
7 format.scm:197 (letrec (# # # # ...) (set! format:pos 0) (set!
format:arg-pos 0) ...)
8* format.scm:764 [anychar-dispatch]
9 format.scm:265 (if (>= format:pos format-string-len) arg-pos ...)
...
10 format.scm:294 (case (char-upcase #) (# # # #) (# # # #) ...)
11* format.scm:448 (require (quote pretty-print))
------------------------------
guile> (debug-options)
(show-full-file-name show-line-number ...)
guile> (format "~Y" '(foo bar))
Backtrace:
<stdin>
0* 19 [format:format "~Y" (foo bar)]
/opt/guile//share/guile/1.5.0/ice-9/format.scm:
1 149 (let ((args (if # # ...))) (set! format:args args) ...)
...
2 169 [call-with-output-string #<procedure #f (port)>]
<unknown file>
3* ? [#<procedure #f (port)> #<output: string 80ca0b8>]
/opt/guile//share/guile/1.5.0/ice-9/format.scm:
4* 170 [format:out #<output: string 80ca0b8> "~Y" ((foo bar))]
5 178 (let ((arg-pos #) (arg-len #)) (cond (# # # #) (# # # #) (else # #t)))
6* 178 [format:format-work "~Y" ((foo bar))]
7 197 (letrec (# # # # ...) (set! format:pos 0) (set! format:arg-pos 0) ...)
8* 764 [anychar-dispatch]
9 265 (if (>= format:pos format-string-len) arg-pos ...)
...
10 294 (case (char-upcase #) (# # # #) (# # # #) ...)
11* 448 (require (quote pretty-print))
------------------------------
Index: libguile/backtrace.c
===================================================================
RCS file: /cvs/guile/guile-core/libguile/backtrace.c,v
retrieving revision 1.63
diff -u -r1.63 backtrace.c
--- libguile/backtrace.c 2001/05/15 14:57:22 1.63
+++ libguile/backtrace.c 2001/05/21 16:39:54
@@ -66,6 +66,7 @@
#include "libguile/validate.h"
#include "libguile/backtrace.h"
+#include "libguile/filesys.h"
/* {Error reporting and backtraces}
* (A first approximation.)
@@ -437,6 +438,80 @@
#undef FUNC_NAME
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;
+ if (file == SCM_BOOL_F)
+ if (line == SCM_BOOL_F)
+ scm_puts ("<unknown file>\n", port);
+ else
+ scm_puts ("<stdin>\n", port);
+ else
+ {
+ pstate->writingp = 0;
+ scm_iprin1 (file, port, pstate);
+ scm_puts (":\n", port);
+ pstate->writingp = 1;
+ }
+}
+
+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);
+ scm_putc (' ', port);
+
+ if (SCM_BACKTRACE_BASE_NAME_P)
+ {
+ 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;
+ }
+
+ if (SCM_BACKTRACE_LINE_P)
+ scm_putc (':', port);
+ }
+
+ if (SCM_BACKTRACE_LINE_P)
+ {
+ if (line == SCM_BOOL_F)
+ scm_putc ('?', port);
+ else
+ scm_intprint (SCM_INUM (line) + 1, 10, port);
+ }
+}
+
+static void
display_frame (SCM frame,int nfield,int indentation,SCM sport,SCM
port,scm_print_state *pstate)
{
int n, i, j;
@@ -461,6 +536,10 @@
/* Real frame marker */
scm_putc (SCM_FRAME_REAL_P (frame) ? '*' : ' ', port);
+ /* display file name and line number */
+ if (SCM_BACKTRACE_LINE_P || SCM_BACKTRACE_BASE_NAME_P)
+ display_backtrace_file_and_line (frame, port, pstate);
+
/* Indentation. */
indent (indentation, port);
@@ -509,6 +588,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 +675,16 @@
/* 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_BACKTRACE_FULL_NAME_P)
+ 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);
}
scm_remember_upto_here_1 (print_state);
Index: libguile/debug.h
===================================================================
RCS file: /cvs/guile/guile-core/libguile/debug.h,v
retrieving revision 1.34
diff -u -r1.34 debug.h
--- libguile/debug.h 2000/12/08 17:32:56 1.34
+++ libguile/debug.h 2001/05/21 16:39:54
@@ -84,7 +84,10 @@
#define SCM_BACKTRACE_P scm_debug_opts[10].val
#define SCM_DEVAL_P scm_debug_opts[11].val
#define SCM_STACK_LIMIT scm_debug_opts[12].val
-#define SCM_N_DEBUG_OPTIONS 13
+#define SCM_BACKTRACE_LINE_P scm_debug_opts[13].val
+#define SCM_BACKTRACE_FULL_NAME_P scm_debug_opts[14].val
+#define SCM_BACKTRACE_BASE_NAME_P scm_debug_opts[15].val
+#define SCM_N_DEBUG_OPTIONS 16
extern SCM (*scm_ceval_ptr) (SCM exp, SCM env);
Index: libguile/eval.c
===================================================================
RCS file: /cvs/guile/guile-core/libguile/eval.c,v
retrieving revision 1.222
diff -u -r1.222 eval.c
--- libguile/eval.c 2001/05/20 23:39:55 1.222
+++ libguile/eval.c 2001/05/21 16:39:55
@@ -1686,7 +1686,10 @@
{ SCM_OPTION_INTEGER, "depth", 20, "Maximal length of printed backtrace." },
{ SCM_OPTION_BOOLEAN, "backtrace", 0, "Show backtrace on error." },
{ SCM_OPTION_BOOLEAN, "debug", 0, "Use the debugging evaluator." },
- { SCM_OPTION_INTEGER, "stack", 20000, "Stack size limit (measured in words;
0 = no check)." }
+ { SCM_OPTION_INTEGER, "stack", 20000, "Stack size limit (measured in words;
0 = no check)." },
+ { SCM_OPTION_BOOLEAN, "show-line-number", 0, "Show line numbers in
backtrace."},
+ { SCM_OPTION_BOOLEAN, "show-full-file-name", 0, "Show full file names in
backtrace."},
+ { SCM_OPTION_BOOLEAN, "show-base-file-name", 0, "Show base file names in
backtrace."}
};
scm_option scm_evaluator_trap_table[] = {
- [patch] File names and line numbers in backtrace,
Daniel Skarda <=