Commit | Line | Data |
---|---|---|
c7ecd529 MD |
1 | /* classes: h_files */ |
2 | ||
13dcb666 DH |
3 | #ifndef SCM_DEBUG_H |
4 | #define SCM_DEBUG_H | |
b29058ff | 5 | |
5132eef0 | 6 | /* Copyright (C) 1995,1996,1998,1999,2000,2001,2002 Free Software Foundation, Inc. |
b29058ff | 7 | * |
c7ecd529 MD |
8 | * This program is free software; you can redistribute it and/or modify |
9 | * it under the terms of the GNU General Public License as published by | |
10 | * the Free Software Foundation; either version 2, or (at your option) | |
11 | * any later version. | |
b29058ff | 12 | * |
c7ecd529 MD |
13 | * This program is distributed in the hope that it will be useful, |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 | * GNU General Public License for more details. | |
b29058ff | 17 | * |
c7ecd529 MD |
18 | * You should have received a copy of the GNU General Public License |
19 | * along with this software; see the file COPYING. If not, write to | |
82892bed JB |
20 | * the Free Software Foundation, Inc., 59 Temple Place, Suite 330, |
21 | * Boston, MA 02111-1307 USA | |
c7ecd529 MD |
22 | * |
23 | * As a special exception, the Free Software Foundation gives permission | |
24 | * for additional uses of the text contained in its release of GUILE. | |
25 | * | |
26 | * The exception is that, if you link the GUILE library with other files | |
27 | * to produce an executable, this does not by itself cause the | |
28 | * resulting executable to be covered by the GNU General Public License. | |
29 | * Your use of that executable is in no way restricted on account of | |
30 | * linking the GUILE library code into it. | |
31 | * | |
32 | * This exception does not however invalidate any other reasons why | |
33 | * the executable file might be covered by the GNU General Public License. | |
34 | * | |
35 | * This exception applies only to the code released by the | |
36 | * Free Software Foundation under the name GUILE. If you copy | |
37 | * code from other Free Software Foundation releases into a copy of | |
38 | * GUILE, as the General Public License permits, the exception does | |
39 | * not apply to the code that you add in this way. To avoid misleading | |
40 | * anyone as to the status of such modified files, you must delete | |
41 | * this exception notice from them. | |
42 | * | |
43 | * If you write modifications of your own for GUILE, it is your choice | |
44 | * whether to permit this exception to apply to your modifications. | |
45 | * If you do not wish that, delete this exception notice. | |
46 | * | |
47 | * The author can be reached at djurfeldt@nada.kth.se | |
82892bed | 48 | * Mikael Djurfeldt, SANS/NADA KTH, 10044 STOCKHOLM, SWEDEN */ |
d3a6bc94 | 49 | |
c7ecd529 MD |
50 | \f |
51 | ||
b4309c3c | 52 | #include "libguile/__scm.h" |
c7ecd529 | 53 | |
e771f866 | 54 | #include "libguile/options.h" |
c7ecd529 MD |
55 | \f |
56 | ||
57 | /* | |
58 | * Here comes some definitions for the debugging machinery. | |
59 | * It might seem strange to represent debug flags as ints, | |
60 | * but consider that any particular piece of code is normally | |
61 | * only interested in one flag at a time. This is then | |
62 | * the most efficient representation. | |
63 | */ | |
64 | ||
65 | /* {Options} | |
66 | */ | |
67 | ||
33b97402 | 68 | /* scm_debug_opts is defined in eval.c. |
5e8d7fd4 MD |
69 | */ |
70 | ||
33b001fd | 71 | SCM_API scm_t_option scm_debug_opts[]; |
c7ecd529 | 72 | |
5e8d7fd4 MD |
73 | #define SCM_CHEAPTRAPS_P scm_debug_opts[0].val |
74 | #define SCM_BREAKPOINTS_P scm_debug_opts[1].val | |
75 | #define SCM_TRACE_P scm_debug_opts[2].val | |
76 | #define SCM_REC_PROCNAMES_P scm_debug_opts[3].val | |
77 | #define SCM_BACKWARDS_P scm_debug_opts[4].val | |
274dc5fd MD |
78 | #define SCM_BACKTRACE_WIDTH scm_debug_opts[5].val |
79 | #define SCM_BACKTRACE_INDENT scm_debug_opts[6].val | |
80 | #define SCM_N_FRAMES scm_debug_opts[7].val | |
81 | #define SCM_BACKTRACE_MAXDEPTH scm_debug_opts[8].val | |
82 | #define SCM_BACKTRACE_DEPTH scm_debug_opts[9].val | |
83 | #define SCM_BACKTRACE_P scm_debug_opts[10].val | |
84 | #define SCM_DEVAL_P scm_debug_opts[11].val | |
85 | #define SCM_STACK_LIMIT scm_debug_opts[12].val | |
29067b9d MV |
86 | #define SCM_SHOW_FILE_NAME scm_debug_opts[13].val |
87 | #define SCM_N_DEBUG_OPTIONS 14 | |
c7ecd529 | 88 | |
33b001fd | 89 | SCM_API SCM (*scm_ceval_ptr) (SCM exp, SCM env); |
1cc91f1b | 90 | |
33b001fd MV |
91 | SCM_API int scm_debug_mode; |
92 | SCM_API int scm_check_entry_p; | |
93 | SCM_API int scm_check_apply_p; | |
94 | SCM_API int scm_check_exit_p; | |
c7ecd529 | 95 | |
5e8d7fd4 | 96 | #define SCM_RESET_DEBUG_MODE \ |
d3a6bc94 | 97 | do {\ |
5132eef0 | 98 | scm_check_entry_p = (SCM_ENTER_FRAME_P || SCM_BREAKPOINTS_P)\ |
b29058ff | 99 | && !SCM_FALSEP (SCM_ENTER_FRAME_HDLR);\ |
5132eef0 | 100 | scm_check_apply_p = (SCM_APPLY_FRAME_P || SCM_TRACE_P)\ |
b29058ff | 101 | && !SCM_FALSEP (SCM_APPLY_FRAME_HDLR);\ |
5132eef0 | 102 | scm_check_exit_p = (SCM_EXIT_FRAME_P || SCM_TRACE_P)\ |
b29058ff | 103 | && !SCM_FALSEP (SCM_EXIT_FRAME_HDLR);\ |
5132eef0 DH |
104 | scm_debug_mode = SCM_DEVAL_P\ |
105 | || scm_check_entry_p || scm_check_apply_p || scm_check_exit_p;\ | |
5e8d7fd4 | 106 | scm_ceval_ptr = scm_debug_mode ? scm_deval : scm_ceval;\ |
d3a6bc94 | 107 | } while (0) |
c7ecd529 | 108 | |
c7ecd529 MD |
109 | /* {Evaluator} |
110 | */ | |
111 | ||
92c2555f | 112 | typedef union scm_t_debug_info |
c7ecd529 MD |
113 | { |
114 | struct { SCM exp, env; } e; | |
115 | struct { SCM proc, args; } a; | |
473c250d | 116 | SCM id; |
92c2555f | 117 | } scm_t_debug_info; |
c7ecd529 | 118 | |
33b001fd | 119 | SCM_API long scm_debug_eframe_size; |
c7ecd529 | 120 | |
92c2555f | 121 | typedef struct scm_t_debug_frame |
c7ecd529 | 122 | { |
92c2555f | 123 | struct scm_t_debug_frame *prev; |
c7ecd529 | 124 | long status; |
92c2555f MV |
125 | scm_t_debug_info *vect; |
126 | scm_t_debug_info *info; | |
127 | } scm_t_debug_frame; | |
1be6b49c | 128 | |
1646d37b | 129 | #ifndef USE_THREADS |
33b001fd | 130 | SCM_API scm_t_debug_frame *scm_last_debug_frame; |
1646d37b | 131 | #endif |
c7ecd529 | 132 | |
77debe3c MD |
133 | #define SCM_EVALFRAME (0L << 11) |
134 | #define SCM_APPLYFRAME (1L << 11) | |
135 | #define SCM_VOIDFRAME (3L << 11) | |
136 | #define SCM_MACROEXPF (1L << 10) | |
fcbb26b2 MD |
137 | #define SCM_TAILREC (1L << 9) |
138 | #define SCM_TRACED_FRAME (1L << 8) | |
5e8d7fd4 | 139 | #define SCM_ARGS_READY (1L << 7) |
fcbb26b2 | 140 | #define SCM_DOVERFLOW (1L << 6) |
020c890c | 141 | #define SCM_MAX_FRAME_SIZE 63 |
5e8d7fd4 | 142 | |
77debe3c | 143 | #define SCM_FRAMETYPE (3L << 11) |
fcbb26b2 | 144 | |
77debe3c | 145 | #define SCM_EVALFRAMEP(x) (((x).status & SCM_FRAMETYPE) == SCM_EVALFRAME) |
fcbb26b2 | 146 | #define SCM_APPLYFRAMEP(x) (((x).status & SCM_FRAMETYPE) == SCM_APPLYFRAME) |
473c250d | 147 | #define SCM_VOIDFRAMEP(x) (((x).status & SCM_FRAMETYPE) == SCM_VOIDFRAME) |
5e8d7fd4 MD |
148 | #define SCM_OVERFLOWP(x) (((x).status & SCM_DOVERFLOW) != 0) |
149 | #define SCM_ARGS_READY_P(x) (((x).status & SCM_ARGS_READY) != 0) | |
150 | #define SCM_TRACED_FRAME_P(x) (((x).status & SCM_TRACED_FRAME) != 0) | |
151 | #define SCM_TAILRECP(x) (((x).status & SCM_TAILREC) != 0) | |
77debe3c | 152 | #define SCM_MACROEXPP(x) (((x).status & SCM_MACROEXPF) != 0) |
5e8d7fd4 MD |
153 | #define SCM_SET_OVERFLOW(x) ((x).status |= SCM_DOVERFLOW) |
154 | #define SCM_SET_ARGSREADY(x) ((x).status |= SCM_ARGS_READY) | |
155 | #define SCM_CLEAR_ARGSREADY(x) ((x).status &= ~SCM_ARGS_READY) | |
156 | #define SCM_SET_TRACED_FRAME(x) ((x).status |= SCM_TRACED_FRAME) | |
157 | #define SCM_CLEAR_TRACED_FRAME(x) ((x).status &= ~SCM_TRACED_FRAME) | |
158 | #define SCM_SET_TAILREC(x) ((x).status |= SCM_TAILREC) | |
77debe3c MD |
159 | #define SCM_SET_MACROEXP(x) ((x).status |= SCM_MACROEXPF) |
160 | #define SCM_CLEAR_MACROEXP(x) ((x).status &= ~SCM_MACROEXPF) | |
5e8d7fd4 MD |
161 | |
162 | #define SCM_DEBUGGINGP scm_debug_mode | |
c7ecd529 | 163 | |
fcbb26b2 MD |
164 | /* {Debug Objects} |
165 | */ | |
166 | ||
33b001fd | 167 | SCM_API scm_t_bits scm_tc16_debugobj; |
fcbb26b2 | 168 | |
13dcb666 DH |
169 | #define SCM_DEBUGOBJP(x) \ |
170 | SCM_TYP16_PREDICATE (scm_tc16_debugobj, x) | |
171 | #define SCM_DEBUGOBJ_FRAME(x) \ | |
172 | ((scm_t_debug_frame *) SCM_CELL_WORD_1 (x)) | |
e841c3e0 | 173 | #define SCM_SET_DEBUGOBJ_FRAME(x, f) SCM_SET_CELL_WORD_1 (x, f) |
fcbb26b2 | 174 | |
c7ecd529 MD |
175 | /* {Memoized Source} |
176 | */ | |
177 | ||
33b001fd | 178 | SCM_API scm_t_bits scm_tc16_memoized; |
c7ecd529 | 179 | |
e841c3e0 KN |
180 | #define SCM_MEMOIZEDP(x) SCM_TYP16_PREDICATE (scm_tc16_memoized, x) |
181 | #define SCM_MEMOIZED_EXP(x) SCM_CAR (SCM_CELL_OBJECT_1 (x)) | |
182 | #define SCM_MEMOIZED_ENV(x) SCM_CDR (SCM_CELL_OBJECT_1 (x)) | |
c7ecd529 MD |
183 | |
184 | \f | |
185 | ||
33b001fd MV |
186 | SCM_API SCM scm_debug_object_p (SCM obj); |
187 | SCM_API SCM scm_local_eval (SCM exp, SCM env); | |
188 | SCM_API SCM scm_reverse_lookup (SCM env, SCM data); | |
189 | SCM_API SCM scm_start_stack (SCM id, SCM exp, SCM env); | |
190 | SCM_API SCM scm_procedure_environment (SCM proc); | |
191 | SCM_API SCM scm_procedure_source (SCM proc); | |
192 | SCM_API SCM scm_procedure_name (SCM proc); | |
193 | SCM_API SCM scm_memoized_environment (SCM m); | |
194 | SCM_API SCM scm_make_memoized (SCM exp, SCM env); | |
195 | SCM_API SCM scm_memoized_p (SCM obj); | |
196 | SCM_API SCM scm_with_traps (SCM thunk); | |
197 | SCM_API SCM scm_evaluator_traps (SCM setting); | |
198 | SCM_API SCM scm_debug_options (SCM setting); | |
199 | SCM_API SCM scm_unmemoize (SCM memoized); | |
200 | SCM_API SCM scm_make_debugobj (scm_t_debug_frame *debug); | |
201 | SCM_API void scm_init_debug (void); | |
c7ecd529 | 202 | |
f3667f52 | 203 | #ifdef GUILE_DEBUG |
33b001fd MV |
204 | SCM_API SCM scm_make_iloc (SCM frame, SCM binding, SCM cdrp); |
205 | SCM_API SCM scm_iloc_p (SCM obj); | |
206 | SCM_API SCM scm_memcons (SCM car, SCM cdr, SCM env); | |
207 | SCM_API SCM scm_mem_to_proc (SCM obj); | |
208 | SCM_API SCM scm_proc_to_mem (SCM obj); | |
209 | SCM_API SCM scm_debug_hang (SCM obj); | |
f3667f52 JB |
210 | #endif /*GUILE_DEBUG*/ |
211 | ||
5132eef0 DH |
212 | #if SCM_ENABLE_DEPRECATED == 1 |
213 | #define CHECK_ENTRY scm_check_entry_p | |
214 | #define CHECK_APPLY scm_check_apply_p | |
215 | #define CHECK_EXIT scm_check_exit_p | |
216 | #endif | |
217 | ||
b29058ff | 218 | #endif /* SCM_DEBUG_H */ |
89e00824 ML |
219 | |
220 | /* | |
221 | Local Variables: | |
222 | c-file-style: "gnu" | |
223 | End: | |
224 | */ |