summaryrefslogtreecommitdiff
path: root/libguile/backtrace.c
diff options
context:
space:
mode:
authorAndy Wingo <wingo@pobox.com>2009-12-03 13:09:58 +0100
committerAndy Wingo <wingo@pobox.com>2009-12-03 14:42:51 +0100
commitaa3f69519f1af3fcf31cf36be33776db3fedf65a (patch)
tree5f2a4ab2d8332b5754693d4dc7997ed96cd7985d /libguile/backtrace.c
parent14aa25e410d49586c8ff9b4a80d2b6046b769905 (diff)
downloadguile-aa3f69519f1af3fcf31cf36be33776db3fedf65a.tar.gz
replace frame implementation with VM frames
* libguile/stacks.h: Rework so that a stack doesn't copy information out of VM frames, it just holds onto a VM frame, along with the stack id and length. VM frames are now the only representation of frames in Guile. (scm_t_info_frame, SCM_FRAME_N_SLOTS, SCM_FRAME_REF, SCM_FRAME_NUMBER) (SCM_FRAME_FLAGS, SCM_FRAME_SOURCE, SCM_FRAME_PROC, SCM_FRAME_ARGS) (SCM_FRAME_PREV, SCM_FRAME_NEXT) (SCM_FRAMEF_VOID, SCM_FRAMEF_REAL, SCM_FRAMEF_PROC) (SCM_FRAMEF_EVAL_ARGS, SCM_FRAMEF_OVERFLOW) (SCM_FRAME_VOID_P, SCM_FRAME_REAL_P, SCM_FRAME_PROC_P) (SCM_FRAME_EVAL_ARGS_P, SCM_FRAME_OVERFLOW_P): Remove these macros corresponding to the old frame implementation. (scm_frame_p scm_frame_source, scm_frame_procedure) (scm_frame_arguments): These definitions are now in frames.h. (scm_last_stack_frame): Remove declaration of previously-removed constructor. Probably should re-instate it though. (scm_frame_number, scm_frame_previous, scm_frame_next) (scm_frame_real_p, scm_frame_procedure_p, scm_frame_evaluating_args_p) (scm_frame_overflow_p) : Remove these procedures corresponding to the old stack implementation. * libguile/stacks.c: Update for new frames implementation. * libguile/frames.h: * libguile/frames.c: Rename functions operating on VM frames to have a scm_frame prefix, not scm_vm_frame -- because they really are the only frames we have. Rename corresponding Scheme functions too, from vm-frame-foo to frame-foo. * libguile/deprecated.h: Remove scm_stack and scm_info_frame data types. * libguile/vm.c (vm_dispatch_hook): Adapt to scm_c_make_frame name change. * module/system/vm/frame.scm: No need to export functions provided frames.c now, as we load those procedures into the default environment now. Rename functions, and remove a couple of outdated, unused functions. The bottom half of this file is still bitrotten, though. * libguile/backtrace.c: Rework to operate on the new frame representation. Also fix a bug displaying file names for compiled procedures. * libguile/init.c: Load the VM much earlier, just because we can. Also it allows us to have frames.[ch] loaded in time for stacks to be initialized, so that scm_frame_arguments can do the right thing.
Diffstat (limited to 'libguile/backtrace.c')
-rw-r--r--libguile/backtrace.c141
1 files changed, 40 insertions, 101 deletions
diff --git a/libguile/backtrace.c b/libguile/backtrace.c
index 58fe0cfc9..9d56ea2d0 100644
--- a/libguile/backtrace.c
+++ b/libguile/backtrace.c
@@ -43,6 +43,7 @@
#include "libguile/ports.h"
#include "libguile/strings.h"
#include "libguile/dynwind.h"
+#include "libguile/frames.h"
#include "libguile/validate.h"
#include "libguile/lang.h"
@@ -157,11 +158,7 @@ display_expression (SCM frame, SCM pname, SCM source, SCM port)
pstate->length = DISPLAY_EXPRESSION_MAX_LENGTH;
if (scm_is_symbol (pname) || scm_is_string (pname))
{
- if (SCM_FRAMEP (frame)
- && SCM_FRAME_EVAL_ARGS_P (frame))
- scm_puts ("While evaluating arguments to ", port);
- else
- scm_puts ("In procedure ", port);
+ scm_puts ("In procedure ", port);
scm_iprin1 (pname, port, pstate);
}
scm_puts (":\n", port);
@@ -354,14 +351,14 @@ display_frame_expr (char *hdr, SCM exp, char *tlr, int indentation, SCM sport, S
static void
display_application (SCM frame, int indentation, SCM sport, SCM port, scm_print_state *pstate)
{
- SCM proc = SCM_FRAME_PROC (frame);
+ SCM proc = scm_frame_procedure (frame);
SCM name = (scm_is_true (scm_procedure_p (proc))
? scm_procedure_name (proc)
: SCM_BOOL_F);
display_frame_expr ("[",
scm_cons (scm_is_true (name) ? name : proc,
- SCM_FRAME_ARGS (frame)),
- SCM_FRAME_EVAL_ARGS_P (frame) ? " ..." : "]",
+ scm_frame_arguments (frame)),
+ "]",
indentation,
sport,
port,
@@ -383,30 +380,27 @@ SCM_DEFINE (scm_display_application, "display-application", 1, 2, 0,
if (SCM_UNBNDP (indent))
indent = SCM_INUM0;
- if (SCM_FRAME_PROC_P (frame))
- /* Display an application. */
- {
- SCM sport, print_state;
- scm_print_state *pstate;
+ /* Display an application. */
+ {
+ SCM sport, print_state;
+ scm_print_state *pstate;
- /* Create a string port used for adaptation of printing parameters. */
- sport = scm_mkstrport (SCM_INUM0,
- scm_make_string (scm_from_int (240),
- SCM_UNDEFINED),
- SCM_OPN | SCM_WRTNG,
- FUNC_NAME);
-
- /* Create a print state for printing of frames. */
- print_state = scm_make_print_state ();
- pstate = SCM_PRINT_STATE (print_state);
- pstate->writingp = 1;
- pstate->fancyp = 1;
+ /* Create a string port used for adaptation of printing parameters. */
+ sport = scm_mkstrport (SCM_INUM0,
+ scm_make_string (scm_from_int (240),
+ SCM_UNDEFINED),
+ SCM_OPN | SCM_WRTNG,
+ FUNC_NAME);
+
+ /* Create a print state for printing of frames. */
+ print_state = scm_make_print_state ();
+ pstate = SCM_PRINT_STATE (print_state);
+ pstate->writingp = 1;
+ pstate->fancyp = 1;
- display_application (frame, scm_to_int (indent), sport, port, pstate);
- return SCM_BOOL_T;
- }
- else
- return SCM_BOOL_F;
+ display_application (frame, scm_to_int (indent), sport, port, pstate);
+ return SCM_BOOL_T;
+ }
}
#undef FUNC_NAME
@@ -415,7 +409,7 @@ SCM_SYMBOL (sym_base, "base");
static void
display_backtrace_get_file_line (SCM frame, SCM *file, SCM *line)
{
- SCM source = SCM_FRAME_SOURCE (frame);
+ SCM source = scm_frame_source (frame);
*file = *line = SCM_BOOL_F;
if (scm_is_pair (source)
&& scm_is_pair (scm_cdr (source))
@@ -439,7 +433,7 @@ display_backtrace_file (frame, last_file, port, pstate)
display_backtrace_get_file_line (frame, &file, &line);
- if (scm_is_eq (file, *last_file))
+ if (scm_is_true (scm_equal_p (file, *last_file)))
return;
*last_file = file;
@@ -506,23 +500,16 @@ display_backtrace_file_and_line (SCM frame, SCM port, scm_print_state *pstate)
}
static void
-display_frame (SCM frame, int nfield, int indentation, SCM sport, SCM port, scm_print_state *pstate)
+display_frame (SCM frame, int n, int nfield, int indentation,
+ SCM sport, SCM port, scm_print_state *pstate)
{
- int n, i, j;
-
- /* Announce missing frames? */
- if (!SCM_BACKWARDS_P && SCM_FRAME_OVERFLOW_P (frame))
- {
- indent (nfield + 1 + indentation, port);
- scm_puts ("...\n", port);
- }
+ int i, j;
/* display file name and line number */
if (scm_is_true (SCM_PACK (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;
/* Number indentation. */
@@ -531,38 +518,12 @@ display_frame (SCM frame, int nfield, int indentation, SCM sport, SCM port, scm_
/* Frame number. */
scm_iprin1 (scm_from_int (n), port, pstate);
- /* Real frame marker */
- scm_putc (SCM_FRAME_REAL_P (frame) ? '*' : ' ', port);
-
/* Indentation. */
indent (indentation, port);
- if (SCM_FRAME_PROC_P (frame))
- /* Display an application. */
- display_application (frame, nfield + 1 + indentation, sport, port, pstate);
- else
- /* Display a special form. */
- {
- SCM source = SCM_FRAME_SOURCE (frame);
- SCM copy = (scm_is_pair (source)
- ? scm_source_property (source, scm_sym_copy)
- : SCM_BOOL_F);
- display_frame_expr ("(",
- copy,
- ")",
- nfield + 1 + indentation,
- sport,
- port,
- pstate);
- }
+ /* Display an application. */
+ display_application (frame, nfield + 1 + indentation, sport, port, pstate);
scm_putc ('\n', port);
-
- /* Announce missing frames? */
- if (SCM_BACKWARDS_P && SCM_FRAME_OVERFLOW_P (frame))
- {
- indent (nfield + 1 + indentation, port);
- scm_puts ("...\n", port);
- }
}
struct display_backtrace_args {
@@ -633,48 +594,26 @@ display_backtrace_body (struct display_backtrace_args *a)
pstate->highlight_objects = a->highlight_objects;
/* First find out if it's reasonable to do indentation. */
- if (SCM_BACKWARDS_P)
- indent_p = 0;
- else
- {
- unsigned int j;
-
- indent_p = 1;
- frame = scm_stack_ref (a->stack, scm_from_int (beg));
- for (i = 0, j = 0; i < n; ++i)
- {
- if (SCM_FRAME_REAL_P (frame))
- ++j;
- if (j > SCM_BACKTRACE_INDENT)
- {
- indent_p = 0;
- break;
- }
- frame = (SCM_BACKWARDS_P
- ? SCM_FRAME_PREV (frame)
- : SCM_FRAME_NEXT (frame));
- }
- }
+ indent_p = 0;
/* Determine size of frame number field. */
- j = SCM_FRAME_NUMBER (scm_stack_ref (a->stack, scm_from_int (end)));
+ j = end;
for (i = 0; j > 0; ++i) j /= 10;
nfield = i ? i : 1;
/* Print frames. */
- frame = scm_stack_ref (a->stack, scm_from_int (beg));
indentation = 1;
last_file = SCM_UNDEFINED;
- for (i = 0; i < n; ++i)
+ if (SCM_BACKWARDS_P)
+ end++;
+ else
+ end--;
+ for (i = beg; i != end; SCM_BACKWARDS_P ? ++i : --i)
{
+ frame = scm_stack_ref (a->stack, scm_from_int (i));
if (!scm_is_eq (SCM_PACK (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, i, nfield, indentation, sport, a->port, pstate);
}
scm_remember_upto_here_1 (print_state);