* alist.c, arbiters.c, continuations.c, debug.c, debug.h, eval.c,
[bpt/guile.git] / libguile / debug.h
1 /* classes: h_files */
2
3 #ifndef DEBUGH
4 #define DEBUGH
5 /* Copyright (C) 1995,1996 Mikael Djurfeldt
6 *
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)
10 * any later version.
11 *
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.
16 *
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, 675 Mass Ave, Cambridge, MA 02139, USA.
20 *
21 * As a special exception, the Free Software Foundation gives permission
22 * for additional uses of the text contained in its release of GUILE.
23 *
24 * The exception is that, if you link the GUILE library with other files
25 * to produce an executable, this does not by itself cause the
26 * resulting executable to be covered by the GNU General Public License.
27 * Your use of that executable is in no way restricted on account of
28 * linking the GUILE library code into it.
29 *
30 * This exception does not however invalidate any other reasons why
31 * the executable file might be covered by the GNU General Public License.
32 *
33 * This exception applies only to the code released by the
34 * Free Software Foundation under the name GUILE. If you copy
35 * code from other Free Software Foundation releases into a copy of
36 * GUILE, as the General Public License permits, the exception does
37 * not apply to the code that you add in this way. To avoid misleading
38 * anyone as to the status of such modified files, you must delete
39 * this exception notice from them.
40 *
41 * If you write modifications of your own for GUILE, it is your choice
42 * whether to permit this exception to apply to your modifications.
43 * If you do not wish that, delete this exception notice.
44 *
45 * The author can be reached at djurfeldt@nada.kth.se
46 * Mikael Djurfeldt, SANS/NADA KTH, 10044 STOCKHOLM, SWEDEN
47 */
48 \f
49
50 #include "libguile/__scm.h"
51
52 #include "libguile/options.h"
53 \f
54
55 /*
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.
61 */
62
63 /* {Options}
64 */
65
66 /* scm_debug_opts and scm_evaluator_trap_table are defined in eval.c.
67 */
68
69 extern scm_option scm_debug_opts[];
70
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
84
85 extern scm_option scm_evaluator_trap_table[];
86
87 #define SCM_ENTER_FRAME_P scm_evaluator_trap_table[0].val
88 #define SCM_APPLY_FRAME_P scm_evaluator_trap_table[1].val
89 #define SCM_EXIT_FRAME_P scm_evaluator_trap_table[2].val
90 #define SCM_N_EVALUATOR_TRAPS 3
91
92 extern SCM (*scm_ceval_ptr) SCM_P ((SCM exp, SCM env));
93
94 extern int scm_debug_mode;
95 extern int scm_check_entry_p, scm_check_apply_p, scm_check_exit_p;
96
97 #define CHECK_ENTRY scm_check_entry_p
98 #define CHECK_APPLY scm_check_apply_p
99 #define CHECK_EXIT scm_check_exit_p
100
101 #define SCM_RESET_DEBUG_MODE \
102 {\
103 if (SCM_ENTER_FRAME_P || SCM_BREAKPOINTS_P) CHECK_ENTRY = 1;\
104 if (SCM_APPLY_FRAME_P || SCM_TRACE_P) CHECK_APPLY = 1;\
105 if (SCM_EXIT_FRAME_P || SCM_TRACE_P) CHECK_EXIT = 1;\
106 scm_debug_mode = SCM_DEVAL_P || SCM_BACKTRACE_P || CHECK_ENTRY || CHECK_APPLY || CHECK_EXIT;\
107 scm_ceval_ptr = scm_debug_mode ? scm_deval : scm_ceval;\
108 }
109
110
111 /* {Evaluator}
112 */
113
114 typedef union scm_debug_info
115 {
116 struct { SCM exp, env; } e;
117 struct { SCM proc, args; } a;
118 SCM id;
119 } scm_debug_info;
120
121 extern int scm_debug_eframe_size;
122
123 typedef struct scm_debug_frame
124 {
125 struct scm_debug_frame *prev;
126 long status;
127 scm_debug_info vect[1];
128 } scm_debug_frame;
129
130 #ifndef USE_THREADS
131 extern scm_debug_frame *scm_last_debug_frame;
132 #endif
133
134 #define SCM_EVALFRAME (0L << 10)
135 #define SCM_APPLYFRAME (1L << 10)
136 #define SCM_VOIDFRAME (2L << 10)
137 #define SCM_TAILREC (1L << 9)
138 #define SCM_TRACED_FRAME (1L << 8)
139 #define SCM_ARGS_READY (1L << 7)
140 #define SCM_DOVERFLOW (1L << 6)
141 #define SCM_MAX_FRAME_SIZE 63 /* also used as a mask for the size field */
142
143 #define SCM_FRAMETYPE (3L << 10)
144
145 #define SCM_EVALFRAMEP(x) (((x).status & SCM_FRAMETYPE) == SCM_EVALFRAME)
146 #define SCM_APPLYFRAMEP(x) (((x).status & SCM_FRAMETYPE) == SCM_APPLYFRAME)
147 #define SCM_VOIDFRAMEP(x) (((x).status & SCM_FRAMETYPE) == SCM_VOIDFRAME)
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)
152 #define SCM_SET_OVERFLOW(x) ((x).status |= SCM_DOVERFLOW)
153 #define SCM_SET_ARGSREADY(x) ((x).status |= SCM_ARGS_READY)
154 #define SCM_CLEAR_ARGSREADY(x) ((x).status &= ~SCM_ARGS_READY)
155 #define SCM_SET_TRACED_FRAME(x) ((x).status |= SCM_TRACED_FRAME)
156 #define SCM_CLEAR_TRACED_FRAME(x) ((x).status &= ~SCM_TRACED_FRAME)
157 #define SCM_SET_TAILREC(x) ((x).status |= SCM_TAILREC)
158
159 #define SCM_DEBUGGINGP scm_debug_mode
160 #define SCM_DSIDEVAL(x, env) if NIMP(x) scm_deval((x), (env))
161
162 /* {Debug Objects}
163 */
164
165 extern long scm_tc16_debugobj;
166
167 #define SCM_DEBUGOBJP(x) (scm_tc16_debugobj == SCM_TYP16 (x))
168 #define SCM_DEBUGOBJ_FRAME(x) SCM_CDR (x)
169 #define SCM_SET_DEBUGOBJ_FRAME(x, f) SCM_SETCDR (x, f)
170
171 /* {Memoized Source}
172 */
173
174 extern long scm_tc16_memoized;
175
176 #define SCM_MEMOIZEDP(x) (scm_tc16_memoized == SCM_TYP16 (x))
177 #define SCM_MEMOIZED_EXP(x) SCM_CAR (SCM_CDR (x))
178 #define SCM_MEMOIZED_ENV(x) SCM_CDR (SCM_CDR (x))
179
180 \f
181
182 extern SCM * scm_lookup_cstr SCM_P ((char *str, int len, SCM env));
183 extern SCM * scm_lookup_soft SCM_P ((SCM var, SCM genv));
184 extern SCM scm_evstr SCM_P ((char *str));
185 extern SCM scm_eval_string SCM_P ((SCM str));
186 extern int scm_ready_p SCM_P ((void));
187 extern void debug_print SCM_P ((SCM obj));
188 extern SCM scm_debug_object_p SCM_P ((SCM obj));
189 extern SCM scm_local_eval SCM_P ((SCM exp, SCM env));
190 extern SCM scm_procedure_environment SCM_P ((SCM proc));
191 extern SCM scm_procedure_source SCM_P ((SCM proc));
192 extern SCM scm_procedure_name SCM_P ((SCM proc));
193 extern SCM scm_memoized_environment SCM_P ((SCM m));
194 extern SCM scm_make_memoized SCM_P ((SCM exp, SCM env));
195 extern SCM scm_memoized_p SCM_P ((SCM obj));
196 extern SCM scm_single_step SCM_P ((SCM cont, SCM val));
197 extern SCM scm_evaluator_traps SCM_P ((SCM setting));
198 extern SCM scm_debug_options SCM_P ((SCM setting));
199 extern SCM scm_unmemoize SCM_P ((SCM memoized));
200 extern SCM scm_make_debugobj SCM_P ((scm_debug_frame* debug));
201 extern void scm_init_debug SCM_P ((void));
202
203 #endif /* DEBUGH */