5 /* Copyright (C) 1995,1996 Free Software Foundation
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2, or (at your option)
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this software; see the file COPYING. If not, write to
19 * the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
20 * Boston, MA 02111-1307 USA
22 * As a special exception, the Free Software Foundation gives permission
23 * for additional uses of the text contained in its release of GUILE.
25 * The exception is that, if you link the GUILE library with other files
26 * to produce an executable, this does not by itself cause the
27 * resulting executable to be covered by the GNU General Public License.
28 * Your use of that executable is in no way restricted on account of
29 * linking the GUILE library code into it.
31 * This exception does not however invalidate any other reasons why
32 * the executable file might be covered by the GNU General Public License.
34 * This exception applies only to the code released by the
35 * Free Software Foundation under the name GUILE. If you copy
36 * code from other Free Software Foundation releases into a copy of
37 * GUILE, as the General Public License permits, the exception does
38 * not apply to the code that you add in this way. To avoid misleading
39 * anyone as to the status of such modified files, you must delete
40 * this exception notice from them.
42 * If you write modifications of your own for GUILE, it is your choice
43 * whether to permit this exception to apply to your modifications.
44 * If you do not wish that, delete this exception notice.
46 * The author can be reached at djurfeldt@nada.kth.se
47 * Mikael Djurfeldt, SANS/NADA KTH, 10044 STOCKHOLM, SWEDEN */
50 #include "libguile/__scm.h"
52 #include "libguile/options.h"
56 * Here comes some definitions for the debugging machinery.
57 * It might seem strange to represent debug flags as ints,
58 * but consider that any particular piece of code is normally
59 * only interested in one flag at a time. This is then
60 * the most efficient representation.
66 /* scm_debug_opts is defined in eval.c.
69 extern scm_option scm_debug_opts
[];
71 #define SCM_CHEAPTRAPS_P scm_debug_opts[0].val
72 #define SCM_BREAKPOINTS_P scm_debug_opts[1].val
73 #define SCM_TRACE_P scm_debug_opts[2].val
74 #define SCM_REC_PROCNAMES_P scm_debug_opts[3].val
75 #define SCM_BACKWARDS_P scm_debug_opts[4].val
76 #define SCM_BACKTRACE_INDENT scm_debug_opts[5].val
77 #define SCM_N_FRAMES scm_debug_opts[6].val
78 #define SCM_BACKTRACE_MAXDEPTH scm_debug_opts[7].val
79 #define SCM_BACKTRACE_DEPTH scm_debug_opts[8].val
80 #define SCM_BACKTRACE_P scm_debug_opts[9].val
81 #define SCM_DEVAL_P scm_debug_opts[10].val
82 #define SCM_STACK_LIMIT scm_debug_opts[11].val
83 #define SCM_N_DEBUG_OPTIONS 12
85 extern SCM (*scm_ceval_ptr
) SCM_P ((SCM exp
, SCM env
));
87 extern int scm_debug_mode
;
88 extern int scm_check_entry_p
, scm_check_apply_p
, scm_check_exit_p
;
90 #define CHECK_ENTRY scm_check_entry_p
91 #define CHECK_APPLY scm_check_apply_p
92 #define CHECK_EXIT scm_check_exit_p
94 #define SCM_RESET_DEBUG_MODE \
96 CHECK_ENTRY = SCM_ENTER_FRAME_P || SCM_BREAKPOINTS_P;\
97 CHECK_APPLY = SCM_APPLY_FRAME_P || SCM_TRACE_P;\
98 CHECK_EXIT = SCM_EXIT_FRAME_P || SCM_TRACE_P;\
99 scm_debug_mode = SCM_DEVAL_P || CHECK_ENTRY || CHECK_APPLY || CHECK_EXIT;\
100 scm_ceval_ptr = scm_debug_mode ? scm_deval : scm_ceval;\
107 typedef union scm_debug_info
109 struct { SCM exp
, env
; } e
;
110 struct { SCM proc
, args
; } a
;
114 extern int scm_debug_eframe_size
;
116 typedef struct scm_debug_frame
118 struct scm_debug_frame
*prev
;
120 scm_debug_info
*vect
;
121 scm_debug_info
*info
;
125 extern scm_debug_frame
*scm_last_debug_frame
;
128 #define SCM_EVALFRAME (0L << 10)
129 #define SCM_APPLYFRAME (1L << 10)
130 #define SCM_VOIDFRAME (2L << 10)
131 #define SCM_TAILREC (1L << 9)
132 #define SCM_TRACED_FRAME (1L << 8)
133 #define SCM_ARGS_READY (1L << 7)
134 #define SCM_DOVERFLOW (1L << 6)
135 #define SCM_MAX_FRAME_SIZE 63 /* also used as a mask for the size field */
137 #define SCM_FRAMETYPE (3L << 10)
139 #define SCM_EVALFRAMEP(x) (((x).status & SCM_FRAMETYPE) == SCM_EVALFRAME)
140 #define SCM_APPLYFRAMEP(x) (((x).status & SCM_FRAMETYPE) == SCM_APPLYFRAME)
141 #define SCM_VOIDFRAMEP(x) (((x).status & SCM_FRAMETYPE) == SCM_VOIDFRAME)
142 #define SCM_OVERFLOWP(x) (((x).status & SCM_DOVERFLOW) != 0)
143 #define SCM_ARGS_READY_P(x) (((x).status & SCM_ARGS_READY) != 0)
144 #define SCM_TRACED_FRAME_P(x) (((x).status & SCM_TRACED_FRAME) != 0)
145 #define SCM_TAILRECP(x) (((x).status & SCM_TAILREC) != 0)
146 #define SCM_SET_OVERFLOW(x) ((x).status |= SCM_DOVERFLOW)
147 #define SCM_SET_ARGSREADY(x) ((x).status |= SCM_ARGS_READY)
148 #define SCM_CLEAR_ARGSREADY(x) ((x).status &= ~SCM_ARGS_READY)
149 #define SCM_SET_TRACED_FRAME(x) ((x).status |= SCM_TRACED_FRAME)
150 #define SCM_CLEAR_TRACED_FRAME(x) ((x).status &= ~SCM_TRACED_FRAME)
151 #define SCM_SET_TAILREC(x) ((x).status |= SCM_TAILREC)
153 #define SCM_DEBUGGINGP scm_debug_mode
154 #define SCM_DSIDEVAL(x, env) if NIMP(x) scm_deval((x), (env))
159 extern long scm_tc16_debugobj
;
161 #define SCM_DEBUGOBJP(x) (scm_tc16_debugobj == SCM_TYP16 (x))
162 #define SCM_DEBUGOBJ_FRAME(x) SCM_CDR (x)
163 #define SCM_SET_DEBUGOBJ_FRAME(x, f) SCM_SETCDR (x, f)
168 extern long scm_tc16_memoized
;
170 #define SCM_MEMOIZEDP(x) (scm_tc16_memoized == SCM_TYP16 (x))
171 #define SCM_MEMOIZED_EXP(x) SCM_CAR (SCM_CDR (x))
172 #define SCM_MEMOIZED_ENV(x) SCM_CDR (SCM_CDR (x))
176 extern SCM
* scm_lookup_cstr
SCM_P ((char *str
, int len
, SCM env
));
177 extern SCM
* scm_lookup_soft
SCM_P ((SCM var
, SCM genv
));
178 extern SCM scm_evstr
SCM_P ((char *str
));
179 extern SCM scm_eval_string
SCM_P ((SCM str
));
180 extern int scm_ready_p
SCM_P ((void));
181 extern void debug_print
SCM_P ((SCM obj
));
182 extern SCM scm_debug_object_p
SCM_P ((SCM obj
));
183 extern SCM scm_local_eval
SCM_P ((SCM exp
, SCM env
));
184 extern SCM scm_procedure_environment
SCM_P ((SCM proc
));
185 extern SCM scm_procedure_source
SCM_P ((SCM proc
));
186 extern SCM scm_procedure_name
SCM_P ((SCM proc
));
187 extern SCM scm_memoized_environment
SCM_P ((SCM m
));
188 extern SCM scm_make_memoized
SCM_P ((SCM exp
, SCM env
));
189 extern SCM scm_memoized_p
SCM_P ((SCM obj
));
190 extern SCM scm_single_step
SCM_P ((SCM cont
, SCM val
));
191 extern SCM scm_evaluator_traps
SCM_P ((SCM setting
));
192 extern SCM scm_debug_options
SCM_P ((SCM setting
));
193 extern SCM scm_unmemoize
SCM_P ((SCM memoized
));
194 extern SCM scm_make_debugobj
SCM_P ((scm_debug_frame
* debug
));
195 extern void scm_init_debug
SCM_P ((void));