(progargs_fluid): New.
[bpt/guile.git] / libguile / debug.h
1 /* classes: h_files */
2
3 #ifndef SCM_DEBUG_H
4 #define SCM_DEBUG_H
5
6 /* Copyright (C) 1995,1996,1998,1999,2000,2001,2002,2004
7 * Free Software Foundation, Inc.
8 *
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
13 *
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
18 *
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 */
23
24 \f
25
26 #include "libguile/__scm.h"
27
28 #include "libguile/options.h"
29 \f
30
31 /*
32 * Here comes some definitions for the debugging machinery.
33 * It might seem strange to represent debug flags as ints,
34 * but consider that any particular piece of code is normally
35 * only interested in one flag at a time. This is then
36 * the most efficient representation.
37 */
38
39 /* {Options}
40 */
41
42 /* scm_debug_opts is defined in eval.c.
43 */
44
45 SCM_API scm_t_option scm_debug_opts[];
46
47 #define SCM_CHEAPTRAPS_P scm_debug_opts[0].val
48 #define SCM_BREAKPOINTS_P scm_debug_opts[1].val
49 #define SCM_TRACE_P scm_debug_opts[2].val
50 #define SCM_REC_PROCNAMES_P scm_debug_opts[3].val
51 #define SCM_BACKWARDS_P scm_debug_opts[4].val
52 #define SCM_BACKTRACE_WIDTH scm_debug_opts[5].val
53 #define SCM_BACKTRACE_INDENT scm_debug_opts[6].val
54 #define SCM_N_FRAMES scm_debug_opts[7].val
55 #define SCM_BACKTRACE_MAXDEPTH scm_debug_opts[8].val
56 #define SCM_BACKTRACE_DEPTH scm_debug_opts[9].val
57 #define SCM_BACKTRACE_P scm_debug_opts[10].val
58 #define SCM_DEVAL_P scm_debug_opts[11].val
59 #define SCM_STACK_LIMIT scm_debug_opts[12].val
60 #define SCM_SHOW_FILE_NAME scm_debug_opts[13].val
61 #define SCM_WARN_DEPRECATED scm_debug_opts[14].val
62 #define SCM_N_DEBUG_OPTIONS 15
63
64 SCM_API int scm_debug_mode_p;
65 SCM_API int scm_check_entry_p;
66 SCM_API int scm_check_apply_p;
67 SCM_API int scm_check_exit_p;
68
69 #define SCM_RESET_DEBUG_MODE \
70 do {\
71 scm_check_entry_p = (SCM_ENTER_FRAME_P || SCM_BREAKPOINTS_P)\
72 && scm_is_true (SCM_ENTER_FRAME_HDLR);\
73 scm_check_apply_p = (SCM_APPLY_FRAME_P || SCM_TRACE_P)\
74 && scm_is_true (SCM_APPLY_FRAME_HDLR);\
75 scm_check_exit_p = (SCM_EXIT_FRAME_P || SCM_TRACE_P)\
76 && scm_is_true (SCM_EXIT_FRAME_HDLR);\
77 scm_debug_mode_p = SCM_DEVAL_P\
78 || scm_check_entry_p || scm_check_apply_p || scm_check_exit_p;\
79 } while (0)
80
81 /* {Evaluator}
82 */
83
84 typedef union scm_t_debug_info
85 {
86 struct { SCM exp, env; } e;
87 struct { SCM proc, args; } a;
88 SCM id;
89 } scm_t_debug_info;
90
91 SCM_API long scm_debug_eframe_size;
92
93 typedef struct scm_t_debug_frame
94 {
95 struct scm_t_debug_frame *prev;
96 long status;
97 scm_t_debug_info *vect;
98 scm_t_debug_info *info;
99 } scm_t_debug_frame;
100
101 #define SCM_EVALFRAME (0L << 11)
102 #define SCM_APPLYFRAME (1L << 11)
103 #define SCM_VOIDFRAME (3L << 11)
104 #define SCM_MACROEXPF (1L << 10)
105 #define SCM_TAILREC (1L << 9)
106 #define SCM_TRACED_FRAME (1L << 8)
107 #define SCM_ARGS_READY (1L << 7)
108 #define SCM_DOVERFLOW (1L << 6)
109 #define SCM_MAX_FRAME_SIZE 63
110
111 #define SCM_FRAMETYPE (3L << 11)
112
113 #define SCM_EVALFRAMEP(x) (((x).status & SCM_FRAMETYPE) == SCM_EVALFRAME)
114 #define SCM_APPLYFRAMEP(x) (((x).status & SCM_FRAMETYPE) == SCM_APPLYFRAME)
115 #define SCM_VOIDFRAMEP(x) (((x).status & SCM_FRAMETYPE) == SCM_VOIDFRAME)
116 #define SCM_OVERFLOWP(x) (((x).status & SCM_DOVERFLOW) != 0)
117 #define SCM_ARGS_READY_P(x) (((x).status & SCM_ARGS_READY) != 0)
118 #define SCM_TRACED_FRAME_P(x) (((x).status & SCM_TRACED_FRAME) != 0)
119 #define SCM_TAILRECP(x) (((x).status & SCM_TAILREC) != 0)
120 #define SCM_MACROEXPP(x) (((x).status & SCM_MACROEXPF) != 0)
121 #define SCM_SET_OVERFLOW(x) ((x).status |= SCM_DOVERFLOW)
122 #define SCM_SET_ARGSREADY(x) ((x).status |= SCM_ARGS_READY)
123 #define SCM_CLEAR_ARGSREADY(x) ((x).status &= ~SCM_ARGS_READY)
124 #define SCM_SET_TRACED_FRAME(x) ((x).status |= SCM_TRACED_FRAME)
125 #define SCM_CLEAR_TRACED_FRAME(x) ((x).status &= ~SCM_TRACED_FRAME)
126 #define SCM_SET_TAILREC(x) ((x).status |= SCM_TAILREC)
127 #define SCM_SET_MACROEXP(x) ((x).status |= SCM_MACROEXPF)
128 #define SCM_CLEAR_MACROEXP(x) ((x).status &= ~SCM_MACROEXPF)
129
130 /* {Debug Objects}
131 */
132
133 SCM_API scm_t_bits scm_tc16_debugobj;
134
135 #define SCM_DEBUGOBJP(x) \
136 SCM_TYP16_PREDICATE (scm_tc16_debugobj, x)
137 #define SCM_DEBUGOBJ_FRAME(x) \
138 ((scm_t_debug_frame *) SCM_CELL_WORD_1 (x))
139 #define SCM_SET_DEBUGOBJ_FRAME(x, f) SCM_SET_CELL_WORD_1 (x, f)
140
141 /* {Memoized Source}
142 */
143
144 SCM_API scm_t_bits scm_tc16_memoized;
145
146 #define SCM_MEMOIZEDP(x) SCM_TYP16_PREDICATE (scm_tc16_memoized, x)
147 #define SCM_MEMOIZED_EXP(x) SCM_CAR (SCM_CELL_OBJECT_1 (x))
148 #define SCM_MEMOIZED_ENV(x) SCM_CDR (SCM_CELL_OBJECT_1 (x))
149
150 \f
151
152 SCM_API SCM scm_debug_object_p (SCM obj);
153 SCM_API SCM scm_local_eval (SCM exp, SCM env);
154 SCM_API SCM scm_reverse_lookup (SCM env, SCM data);
155 SCM_API SCM scm_start_stack (SCM info_id, SCM exp, SCM env);
156 SCM_API SCM scm_procedure_environment (SCM proc);
157 SCM_API SCM scm_procedure_source (SCM proc);
158 SCM_API SCM scm_procedure_name (SCM proc);
159 SCM_API SCM scm_memoized_environment (SCM m);
160 SCM_API SCM scm_make_memoized (SCM exp, SCM env);
161 SCM_API SCM scm_memoized_p (SCM obj);
162 SCM_API SCM scm_with_traps (SCM thunk);
163 SCM_API SCM scm_evaluator_traps (SCM setting);
164 SCM_API SCM scm_debug_options (SCM setting);
165 SCM_API SCM scm_make_debugobj (scm_t_debug_frame *debug);
166
167 SCM_API SCM scm_i_unmemoize_expr (SCM memoized);
168 SCM_API void scm_init_debug (void);
169
170 #ifdef GUILE_DEBUG
171 SCM_API SCM scm_memcons (SCM car, SCM cdr, SCM env);
172 SCM_API SCM scm_mem_to_proc (SCM obj);
173 SCM_API SCM scm_proc_to_mem (SCM obj);
174 SCM_API SCM scm_debug_hang (SCM obj);
175 #endif /*GUILE_DEBUG*/
176
177 #if SCM_ENABLE_DEPRECATED == 1
178
179 #define CHECK_ENTRY scm_check_entry_p
180 #define CHECK_APPLY scm_check_apply_p
181 #define CHECK_EXIT scm_check_exit_p
182
183 /* Deprecated in guile 1.7.0 on 2004-03-29. */
184 #define SCM_DEBUGGINGP scm_debug_mode_p
185 #define scm_debug_mode scm_debug_mode_p
186
187 #endif
188
189 #endif /* SCM_DEBUG_H */
190
191 /*
192 Local Variables:
193 c-file-style: "gnu"
194 End:
195 */